datastore

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB

func NewDB(n Name, logger zerolog.Logger) (*sql.DB, func(), error)

NewDB returns an open database handle of 0 or more underlying PostgreSQL connections

func NewNullInt64

func NewNullInt64(i int64) sql.NullInt64

NewNullInt64 returns a null if i == 0, otherwise it returns the int64 which was input

func NewNullString

func NewNullString(s string) sql.NullString

NewNullString returns a null if s is empty, otherwise it returns the string which was input

Types

type Datastore

type Datastore struct {
	// contains filtered or unexported fields
}

Datastore is a concrete implementation for a database

func NewDatastore

func NewDatastore(db *sql.DB) *Datastore

NewDatastore is an initializer for the Datastore struct

func (*Datastore) BeginTx

func (ds *Datastore) BeginTx(ctx context.Context) (*sql.Tx, error)

BeginTx is a wrapper for sql.DB.BeginTx in order to expose from the Datastore interface

func (*Datastore) CommitTx

func (ds *Datastore) CommitTx(tx *sql.Tx) error

CommitTx is a wrapper for sql.Tx.Commit in order to expose from the Datastore interface. Proper error handling is also considered.

func (*Datastore) DB

func (ds *Datastore) DB() *sql.DB

DB is a getter for the sql.DB in the Datastore struct

func (*Datastore) RollbackTx

func (ds *Datastore) RollbackTx(tx *sql.Tx, err error) error

RollbackTx is a wrapper for sql.Tx.Rollback in order to expose from the Datastore interface. Proper error handling is also considered.

type Datastorer

type Datastorer interface {
	DB() *sql.DB
	BeginTx(context.Context) (*sql.Tx, error)
	RollbackTx(*sql.Tx, error) error
	CommitTx(*sql.Tx) error
}

Datastorer is an interface for working with the Database

type Name

type Name int

Name defines the name for the Datastore

const (
	// LocalDatastore represents the local PostgreSQL db
	LocalDatastore Name = iota
	// GCPCPDatastore represents a local connection to a GCP Cloud
	// SQL db through the Google Cloud Proxy
	GCPCPDatastore
	// GCPDatastore represents a true GCP connection to a GCP
	// Cloud SQL db
	GCPDatastore
	// MockedDatastore represents a Mocked Database
	MockedDatastore
)

func (Name) String

func (n Name) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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