postgres

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: MIT Imports: 8 Imported by: 16

README

postgres

GoDoc Tesst Go Report Card codecov Gitter chat

Postgres adapter for REL.

Example

package main

import (
	"context"

	_ "github.com/lib/pq"
	"github.com/go-rel/postgres"
	"github.com/go-rel/rel"
)

func main() {
	// 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)
	repo.Ping(context.TODO())
}

Supported Driver

  • github.com/lib/pq

Supported Database

  • PostgreSQL 9, 10, 11, 12 and 13

Testing

Start PostgreSQL server in Docker
docker run -it --rm -p 5433:5432 -e "POSTGRES_USER=rel" -e "POSTGRES_PASSWORD=test" -e "POSTGRES_DB=rel_test" postgres:14-alpine
Run tests
POSTGRESQL_DATABASE="postgres://rel:test@localhost:5433/rel_test?timezone=Asia/Jakarta" go test ./...

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

This section is empty.

Functions

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.

Types

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) (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) ([]interface{}, error)

InsertAll inserts multiple records to database and returns its ids.

type Quote added in v0.2.0

type Quote struct{}

Quote PostgreSQL identifiers and literals.

func (Quote) ID added in v0.2.0

func (q Quote) ID(name string) string

func (Quote) Value added in v0.2.0

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

type ValueConvert added in v0.2.0

type ValueConvert struct{}

ValueConvert converts values to PostgreSQL literals.

func (ValueConvert) ConvertValue added in v0.2.0

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

Jump to

Keyboard shortcuts

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