Skip to content

go-rel/postgres

Repository files navigation

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 ./...