Skip to content

postgres

import "github.com/go-rel/postgres"

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)

Constants

const Name string = "postgres"
Name of database type this adapter implements.

const TimeLayout = "2006-01-02 15:04:05.999999999Z07:00:00"
TimeLayout used by PostgreSQL adapter.

func FormatTime

func FormatTime(t time.Time) string
FormatTime formats time to PostgreSQL format.

func MustOpen

func MustOpen(dsn string) rel.Adapter
MustOpen postgres connection using dsn.

func New

func New(database *db.DB) rel.Adapter
New postgres adapter using existing connection.

func Open

func Open(dsn string) (rel.Adapter, error)
Open postgres connection using dsn.

type Postgres

type Postgres struct {
    sql.SQL
}
Postgres adapter.

func (Postgres) Begin

func (p Postgres) Begin(ctx context.Context) (rel.Adapter, error)
Begin begins a new transaction.

func (Postgres) Insert

func (p Postgres) Insert(ctx context.Context, query rel.Query, primaryField string, mutates map[string]rel.Mutate, onConflict rel.OnConflict) (interface{}, error)
Insert inserts a record to database and returns its id.

func (Postgres) InsertAll

func (p Postgres) InsertAll(ctx context.Context, query rel.Query, primaryField string, fields []string, bulkMutates []map[string]rel.Mutate, onConflict rel.OnConflict) ([]interface{}, error)
InsertAll inserts multiple records to database and returns its ids.

func (Postgres) Name

func (Postgres) Name() string
Name of database adapter.

type Quote

type Quote struct{}
Quote PostgreSQL identifiers and literals.

func (Quote) ID

func (q Quote) ID(name string) string

func (Quote) Value

func (q Quote) Value(v interface{}) string

type ValueConvert

type ValueConvert struct{}
ValueConvert converts values to PostgreSQL literals.

func (ValueConvert) ConvertValue

func (c ValueConvert) ConvertValue(v interface{}) (driver.Value, error)

Last update: 2024-08-16