postgres

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package postgres wraps postgres (pq) driver as an adapter for REL.

Usage:

// open postgres connection.
adapter, err := postgres.Open("postgres://postgres@localhost/rel_test?sslmode=disable")
if err != nil {
	panic(err)
}
defer adapter.Close()

// initialize REL's repo.
repo := rel.New(adapter)

Index

Constants

This section is empty.

Variables

View Source
var (

	// Config for postgres adapter.
	Config = sql.Config{
		Placeholder:         "$",
		EscapeChar:          "\"",
		Ordinal:             true,
		InsertDefaultValues: true,
		ErrorFunc:           errorFunc,
		MapColumnFunc:       mapColumnFunc,
	}
)

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	*sql.Adapter
}

Adapter definition for postgres database.

func New added in v0.5.0

func New(database *db.DB) *Adapter

New postgres adapter using existing connection.

func Open

func Open(dsn string) (*Adapter, error)

Open postgres connection using dsn.

func (*Adapter) Begin

func (adapter *Adapter) Begin(ctx context.Context) (rel.Adapter, error)

Begin begins a new transaction.

func (*Adapter) Insert

func (adapter *Adapter) Insert(ctx context.Context, query rel.Query, primaryField string, mutates map[string]rel.Mutate) (interface{}, error)

Insert inserts a record to database and returns its id.

func (*Adapter) InsertAll

func (adapter *Adapter) InsertAll(ctx context.Context, query rel.Query, primaryField string, fields []string, bulkMutates []map[string]rel.Mutate) ([]interface{}, error)

InsertAll inserts multiple records to database and returns its ids.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL