psql

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2018 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const DentryTableName = "dentry"

Dentry table name

View Source
const ServiceTableName = "service"

Service table name

Variables

View Source
var DeleteDentryByIdQry = fmt.Sprintf(`
	DELETE
	FROM public.%s
	WHERE id=$1`, DentryTableName)
View Source
var DeleteDentryByPrefixQry = fmt.Sprintf(`
	DELETE
	FROM public.%s
	WHERE
		dtab=$1
		AND prefix=$2`, DentryTableName)
View Source
var DentryListByDtab = fmt.Sprintf(`
	SELECT *
	FROM public.%s
	WHERE dtab = $1
	ORDER BY priority ASC`, DentryTableName)
View Source
var GetServiceByLogicalNameQry = fmt.Sprintf(`
	SELECT *
	FROM "%s"
	WHERE logical_name = $1`, ServiceTableName)
View Source
var SelectDentryById = fmt.Sprintf(`
	SELECT *
	FROM public.%s
	WHERE id=$1`, DentryTableName)
View Source
var UpsertDentryQry = fmt.Sprintf(`
	INSERT INTO public.%s (
		"dtab",
		"prefix",
		"destination",
		"priority")
	VALUES ($1,$2,$3,$4)
	ON CONFLICT ON CONSTRAINT uq_dentry_dtab_prefix DO
	UPDATE SET
		update_date=timezone('UTC'::text, now()),
		dtab=excluded.dtab,
		prefix=excluded.prefix,
		destination=excluded.destination,
		priority=excluded.priority
	RETURNING *;`, DentryTableName)

Service upsert query

View Source
var UpsertServiceQry = fmt.Sprintf(`
	INSERT INTO "%s" (
		"logical_name",
		"namespace",
		"description")
	VALUES ($1,$2,$3)
	ON CONFLICT ON CONSTRAINT uq_service_logical_name DO
	UPDATE SET
		update_date=timezone('UTC'::text, now()),
		namespace=excluded.namespace,
		description=excluded.description
	RETURNING *;`, ServiceTableName)

Service upsert query

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NewMigrator

func NewMigrator(dsn DSN, opts ...MigrateOption) (*migrate.Migrate, error)

Migrate runs database migrat

func NewMigratorFromDB

func NewMigratorFromDB(db *sql.DB, opts ...MigrateOption) (*migrate.Migrate, error)

func Open

func Open(dsn DSN) (*sqlx.DB, error)

Open opens a new postgrtes connection using the provided DSN

func QueryRowx

func QueryRowx(db sqlx.Queryer, handler RowHandler, qry string, args ...interface{}) error

QueryRowx wraps sqlx.QueryRowx, executing the query and passing the resulting row to a RowHandler

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type DSN

type DSN struct {
	Host     string
	Name     string
	Username string
	Password string
	SSLMode  string
}

A DSN is a postgresql Data source name used for database connection

func (DSN) String

func (dsn DSN) String() string

String bulds the DSN as a URL returning the constructed URL

type DentryStore

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

DentryStore manages dentry CRUD ops

func NewDentryStore

func NewDentryStore(db *sqlx.DB) *DentryStore

NewDentryStore returns a new DentryStore

func (*DentryStore) DelegationTables

func (store *DentryStore) DelegationTables() ([]string, error)

DelegationTables returns a list of distinct delgation tables

func (*DentryStore) DeleteDentryById

func (store *DentryStore) DeleteDentryById(id uuid.UUID) (int64, error)

DeleteDentryById deletes a dentry by it's UUID

func (*DentryStore) DeleteDentryByPrefix

func (store *DentryStore) DeleteDentryByPrefix(dtab, prefix string) (int64, error)

DeleteDentryByPrefix deletes a dentry by it's prefix in a specified dtab

func (*DentryStore) DentriesByDtab

func (store *DentryStore) DentriesByDtab(ctx context.Context, dtab string) (<-chan *store.Dentry, error)

DentriesByDtab returns a slice of Dentry for the Delegation table

func (*DentryStore) DtabUpdates

func (store *DentryStore) DtabUpdates() <-chan namerd.Dtab

TODO: could be a subscription style model

func (*DentryStore) PutDentry

func (store *DentryStore) PutDentry(dentry *store.Dentry) (*store.Dentry, error)

PutDentry creates or updates a dentry

type MigrateLogger

type MigrateLogger struct {
	Logger zerolog.Logger
}

migrateLogger is used to log database migrations

func (*MigrateLogger) Printf

func (l *MigrateLogger) Printf(format string, v ...interface{})

Printf passes the log message and arguments to our logger

func (*MigrateLogger) Verbose

func (l *MigrateLogger) Verbose() bool

Verbose returns true so we can log what the migrator is doing

type MigrateOption

type MigrateOption func(m *migrate.Migrate)

func MigrateWithLog

func MigrateWithLog(log migrate.Logger) MigrateOption

type QueryExecer

type QueryExecer interface {
	sqlx.Queryer
	sqlx.Execer
}

type RowHandler

type RowHandler interface {
	Scan(*sqlx.Row) error
}

A RowHandler handles struct scanning a sqlx.Row into a destination inerface

type RowHandlerFunc

type RowHandlerFunc func(*sqlx.Row) error

The RowHandlerFunc type is an adapter to allow the use of ordinary functions as row handlers

func (RowHandlerFunc) Scan

func (fn RowHandlerFunc) Scan(row *sqlx.Row) error

Scan implements the RowHandler interface

type ServiceStore

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

ServiceStore handles CRUD opperations for services in psql

func NewServiceStore

func NewServiceStore(db *sqlx.DB) *ServiceStore

NewServiceStore returns a new ServiceStore

func (*ServiceStore) GetByLogicalName

func (store *ServiceStore) GetByLogicalName(ln string) (*store.Service, error)

GetByLogicalName returns a service by its unique logical name

func (*ServiceStore) PutService

func (store *ServiceStore) PutService(service *store.Service) (*store.Service, error)

PutService implements the store.ServicePutter and executes an Upsert query to create or update a service

type Store

type Store struct {
	*ServiceStore
	*DentryStore
}

Store embeds the various other stores for a single store interface

func New

func New(db *sqlx.DB) *Store

New connects to a new Store

Jump to

Keyboard shortcuts

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