Categorygithub.com/go-rel/postgres
modulepackage
0.12.0
Repository: https://github.com/go-rel/postgres.git
Documentation: pkg.go.dev

# 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())
}

Example Replication (Master/Standby)

package main

import (
	"context"

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

func main() {
	// open postgres connections.
	adapter := primaryreplica.New(
		postgres.MustOpen("postgres://postgres@master/rel_test?sslmode=disable"),
		postgres.MustOpen("postgres://postgres@standby/rel_test?sslmode=disable"),
	)
	defer adapter.Close()

	// initialize REL's repo.
	repo := rel.New(adapter)
	repo.Ping(context.TODO())
}

Supported Driver

  • github.com/lib/pq
  • github.com/jackc/pgx/v5/stdlib

Supported Database

  • PostgreSQL 11, 12, 13, 14, 15 and 16

Testing

Start PostgreSQL server in Docker

docker run -it --rm -p 25432:5432 -e "POSTGRES_USER=rel" -e "POSTGRES_PASSWORD=rel" -e "POSTGRES_DB=rel_test" postgres:14-alpine

Run tests

go test -p 1 ./...

# Functions

FormatTime formats time to PostgreSQL format.
MustOpen postgres connection using dsn.
New postgres adapter using existing connection.
Open postgres connection using dsn.

# Constants

Name of database type this adapter implements.
TimeLayout used by PostgreSQL adapter.

# Structs

Postgres adapter.
Quote PostgreSQL identifiers and literals.
ValueConvert converts values to PostgreSQL literals.