postgres

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertSortParameters

func ConvertSortParameters(params db.SortParameters, sortableColumns map[string]bool) []string

ConvertSortParameters to sql query string

func Open

func Open(ctx context.Context, options ...Option) (*sqlx.DB, error)

Open initializes a database session based on the provided options.

func ToSnakeCase

func ToSnakeCase(in string) string

ToSnakeCase convert the given string to snake case following the Golang format: acronyms are converted to lower-case and preceded by an underscore.

Types

type Default

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

Default contains the basic implementation of the SQL interface

func NewCRUDTable

func NewCRUDTable(session *sqlx.DB, db, table string, columns, sortable []string) *Default

NewCRUDTable sets up a new Default struct

func (*Default) Create

func (d *Default) Create(ctx context.Context, data interface{}) error

Create a record

func (*Default) GetDBName

func (d *Default) GetDBName() string

GetDBName returns database's name

func (*Default) GetSession

func (d *Default) GetSession() interface{}

GetSession returns the current session

func (*Default) GetTableName

func (d *Default) GetTableName() string

GetTableName returns table's name

func (*Default) RemoveOne

func (d *Default) RemoveOne(ctx context.Context, filter interface{}) error

RemoveOne is used to remove one element from the collection that match the filter

func (*Default) Search

func (d *Default) Search(ctx context.Context, filter interface{}, pagination *db.Pagination, sortParams *db.SortParameters, results interface{}) (int, error)

Search for element in collection

func (*Default) Update

func (d *Default) Update(ctx context.Context, updates map[string]interface{}, filter interface{}) error

Update the collection element with updates set matching the given filter

func (*Default) WhereAndFetchOne

func (d *Default) WhereAndFetchOne(ctx context.Context, filter interface{}, result interface{}) error

WhereAndFetchOne returns only one element from the given filter

func (*Default) WhereCount

func (d *Default) WhereCount(ctx context.Context, filter interface{}) (int, error)

WhereCount is used to cound resultset elements from the given filter

type Option

type Option func(o *Options)

Option allows for managing configuration using functional options.

func WithConnMaxLifetime

func WithConnMaxLifetime(t time.Duration) Option

func WithDSN

func WithDSN(dsn string) Option

func WithDialect

func WithDialect(dialect string) Option

func WithLogLevel

func WithLogLevel(logLevel string) Option

func WithLogger

func WithLogger(logger *zap.Logger) Option

func WithMaxIdleConns

func WithMaxIdleConns(n int) Option

func WithMaxOpenConns

func WithMaxOpenConns(n int) Option

func WithOptions

func WithOptions(options Options) Option

WithOptions sets database options through a single Options object

func WithStatsRecordInterval

func WithStatsRecordInterval(i time.Duration) Option

type Options

type Options struct {
	DSN                 string
	Dialect             string
	Logger              *zap.Logger
	LogLevel            string
	ConnMaxLifetime     time.Duration // time.Hour
	MaxIdleConns        int           // 10
	MaxOpenConns        int           // 25
	StatsRecordInterval time.Duration // time.Second * 5
}

Options holds configuration of our database dialect.

Jump to

Keyboard shortcuts

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