db

package
v0.0.0-...-6b69eb2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ENV        = "ENV"
	DEBUG      = "DEBUG"
	SENTRY_ENV = "SENTRY_ENV"
	SENTRY_DSN = "SENTRY_DSN"
)
View Source
const (
	DB_POSTGRES = "DB_POSTGRES"
	PGHOST      = "PG_HOST"
	PGPORT      = "PG_PORT"
	PGUSER      = "PG_USER"
	PGPASSWORD  = "PG_PASS"
	PGDATABASE  = "PG_DBNAME"
	PGCACHE     = "PG_DBCACHE"
	PGSSLMODE   = "PG_SSLMODE"
	PGLIFETIME  = "PG_LIFETIME"
	PGMAXIDLE   = "PG_MAXIDLE"
	PGMAXCONN   = "PG_MAXCONN"
)
View Source
const (
	LevelDefault sql.IsolationLevel = iota
	LevelReadUncommitted
	LevelReadCommitted
	LevelWriteCommitted
	LevelRepeatableRead
	LevelSnapshot
	LevelSerializable
	LevelLinearizable
)

Variables

View Source
var (
	UPSTASH_REDIS = "UPSTASH_REDIS"
	DB_REDIS      = "DB_REDIS"
)
View Source
var ErrNoRows error = sql.ErrNoRows

Functions

func EscapeString

func EscapeString(s string) string

EscapeString escape the given string.

func EstimatedPrint

func EstimatedPrint(start time.Time, name string, ctx ...*fiber.Ctx)

func IsNoRows

func IsNoRows(err error, stx *PGTx) bool

func IsRollback

func IsRollback(err error, stx *PGTx) bool

func IsRollbackThrow

func IsRollbackThrow(err error, stx *PGTx) bool

Types

type PGClient

type PGClient struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

func (*PGClient) Begin

func (pg *PGClient) Begin(level ...sql.IsolationLevel) (*PGTx, error)

func (*PGClient) Close

func (pg *PGClient) Close() error

func (*PGClient) Connect

func (pg *PGClient) Connect(c *context.Context, appTitle string)

func (*PGClient) CreateChannel

func (pg *PGClient) CreateChannel(appTitle string) (*PGNotify, error)

func (*PGClient) FetchRow

func (pg *PGClient) FetchRow(rows *sql.Rows) (PGRow, error)

func (*PGClient) Query

func (pg *PGClient) Query(query string, args ...any) (*sql.Rows, error)

func (*PGClient) QueryOne

func (pg *PGClient) QueryOne(query string, args ...any) (PGRow, error)

type PGNotify

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

func (*PGNotify) Close

func (pg *PGNotify) Close() error

func (*PGNotify) Listen

func (pg *PGNotify) Listen(channelName string, eventCallback func(e *pq.Notification)) error

func (*PGNotify) Ping

func (pg *PGNotify) Ping() error

type PGRecord

type PGRecord []PGRow

func (PGRecord) Find

func (row PGRecord) Find(columnName string, compareValue string) bool

type PGRow

type PGRow map[string]string

func (PGRow) ToBoolean

func (pg PGRow) ToBoolean(name string) bool

func (PGRow) ToByte

func (pg PGRow) ToByte(name string) []byte

func (PGRow) ToFloat64

func (pg PGRow) ToFloat64(name string) float64

func (PGRow) ToInt64

func (pg PGRow) ToInt64(name string) int64

func (PGRow) ToTime

func (pg PGRow) ToTime(name string) time.Time

type PGTx

type PGTx struct {
	Closed bool
	// contains filtered or unexported fields
}

func (*PGTx) Commit

func (stx *PGTx) Commit() error

func (*PGTx) Execute

func (stx *PGTx) Execute(query string, args ...any) error

func (*PGTx) ExecutePrint

func (stx *PGTx) ExecutePrint(query string, args ...any) error

func (*PGTx) FetchAll

func (stx *PGTx) FetchAll(rows *sql.Rows) (PGRecord, error)

func (*PGTx) FetchOneColumn

func (stx *PGTx) FetchOneColumn(rows *sql.Rows, columnName string) (SubSet, error)

func (*PGTx) FetchRow

func (stx *PGTx) FetchRow(rows *sql.Rows) (PGRow, error)

func (*PGTx) Query

func (stx *PGTx) Query(query string, args ...any) (*sql.Rows, error)

func (*PGTx) QueryOne

func (stx *PGTx) QueryOne(query string, args ...any) (PGRow, error)

func (*PGTx) QueryOnePrint

func (stx *PGTx) QueryOnePrint(query string, args ...any) (PGRow, error)

func (*PGTx) QueryPrint

func (stx *PGTx) QueryPrint(query string, args ...any) (*sql.Rows, error)

func (*PGTx) Rollback

func (stx *PGTx) Rollback() error

type Storage

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

Storage interface that is implemented by storage providers

func CacheNew

func CacheNew(ctx context.Context) *Storage

New creates a new storage

func (*Storage) Close

func (s *Storage) Close() error

Close the database

func (*Storage) Delete

func (s *Storage) Delete(key string) error

Delete entry by key

func (*Storage) Get

func (s *Storage) Get(key string) (string, error)

Get value by key

func (*Storage) GetBool

func (s *Storage) GetBool(key string) (bool, error)

func (*Storage) GetObject

func (s *Storage) GetObject(key string) ([]byte, error)

func (*Storage) Set

func (s *Storage) Set(key string, val any, exp time.Duration) error

Set key with value

type SubSet

type SubSet []string

func (*SubSet) Find

func (s *SubSet) Find(val string) int

func (*SubSet) ToParam

func (s *SubSet) ToParam() string

Jump to

Keyboard shortcuts

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