common

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenDB

func OpenDB(databaseURL *url.URL, migrationsDir string, skipMigration bool, debug bool) (*sql.DB, error)

func ParseUrl

func ParseUrl(dbURL string) (*url.URL, error)

Types

type DBMethods

type DBMethods struct {
	DB *sql.DB

	Debug  bool
	Driver string
}

func (*DBMethods) Begin

func (d *DBMethods) Begin(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

func (*DBMethods) Close

func (d *DBMethods) Close() error

func (*DBMethods) CurrentUnixTimestamp added in v1.0.4

func (d *DBMethods) CurrentUnixTimestamp() int64

func (*DBMethods) DeleteRowByID added in v1.0.3

func (d *DBMethods) DeleteRowByID(ctx context.Context, id int64, row any) error

func (*DBMethods) Each added in v1.0.1

func (d *DBMethods) Each(ctx context.Context, query string, callback func(ctx context.Context, rows *Rows) error, args ...any) error

func (*DBMethods) EachPrepared added in v1.0.5

func (d *DBMethods) EachPrepared(ctx context.Context, prep *Prepared, callback func(ctx context.Context, rows *Rows) error) error

func (*DBMethods) Exec

func (d *DBMethods) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*DBMethods) ExecPrepared added in v1.0.5

func (d *DBMethods) ExecPrepared(ctx context.Context, prep *Prepared) (sql.Result, error)

func (*DBMethods) InsertRow added in v1.0.5

func (d *DBMethods) InsertRow(ctx context.Context, row any) error

func (*DBMethods) Ping

func (d *DBMethods) Ping(ctx context.Context) error

func (*DBMethods) Prepare

func (d *DBMethods) Prepare(ctx context.Context, query string) (*sql.Stmt, error)

func (*DBMethods) PrepareSQL added in v1.0.8

func (d *DBMethods) PrepareSQL(query string, args ...any) *Prepared

func (*DBMethods) Query

func (d *DBMethods) Query(ctx context.Context, query string, args ...any) (*Rows, error)

func (*DBMethods) QueryPrepared added in v1.0.5

func (d *DBMethods) QueryPrepared(ctx context.Context, prep *Prepared) (*Rows, error)

func (*DBMethods) QueryRow

func (d *DBMethods) QueryRow(ctx context.Context, query string, args ...any) *Row

func (*DBMethods) QueryRowByID added in v1.0.3

func (d *DBMethods) QueryRowByID(ctx context.Context, id int64, row any) error

func (*DBMethods) QueryRowPrepared added in v1.0.5

func (d *DBMethods) QueryRowPrepared(ctx context.Context, prep *Prepared) *Row

func (*DBMethods) RowExists added in v1.0.3

func (d *DBMethods) RowExists(ctx context.Context, id int64, row any) bool

func (*DBMethods) SetConnMaxLifetime

func (d *DBMethods) SetConnMaxLifetime(t time.Duration)

func (*DBMethods) SetMaxIdleConns

func (d *DBMethods) SetMaxIdleConns(n int)

func (*DBMethods) SetMaxOpenConns

func (d *DBMethods) SetMaxOpenConns(n int)

func (*DBMethods) Transaction

func (d *DBMethods) Transaction(ctx context.Context, callback func(ctx context.Context, tx *Tx) error) error

func (*DBMethods) UpdateRow added in v1.0.9

func (d *DBMethods) UpdateRow(ctx context.Context, row any) error

func (*DBMethods) UpdateRowOnly added in v1.0.9

func (d *DBMethods) UpdateRowOnly(ctx context.Context, row any, fields ...string) error

type Engine

type Engine interface {
	Begin(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
	Close() error
	CurrentUnixTimestamp() int64
	DeleteRowByID(ctx context.Context, id int64, row any) error
	Each(ctx context.Context, query string, logic func(ctx context.Context, rows *Rows) error, args ...any) error
	EachPrepared(ctx context.Context, prep *Prepared, logic func(ctx context.Context, rows *Rows) error) error
	Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
	ExecPrepared(ctx context.Context, prep *Prepared) (sql.Result, error)
	InsertRow(ctx context.Context, row any) error
	Ping(context.Context) error
	Prepare(ctx context.Context, query string) (*sql.Stmt, error)
	PrepareSQL(query string, args ...any) *Prepared
	Query(ctx context.Context, query string, args ...any) (*Rows, error)
	QueryPrepared(ctx context.Context, prep *Prepared) (*Rows, error)
	QueryRow(ctx context.Context, query string, args ...any) *Row
	QueryRowByID(ctx context.Context, id int64, row any) error
	QueryRowPrepared(ctx context.Context, prep *Prepared) *Row
	RowExists(ctx context.Context, id int64, row any) bool
	SetConnMaxLifetime(d time.Duration)
	SetMaxIdleConns(n int)
	SetMaxOpenConns(n int)
	Transaction(ctx context.Context, queries func(ctx context.Context, tx *Tx) error) error
	UpdateRow(ctx context.Context, row any) error
	UpdateRowOnly(ctx context.Context, row any, fields ...string) error
}

type Prepared added in v1.0.5

type Prepared struct {
	Query string
	Args  []any
}

type Row added in v1.0.1

type Row struct {
	*sql.Row
}

func (*Row) Scans added in v1.0.1

func (r *Row) Scans(row any) error

type Rows added in v1.0.1

type Rows struct {
	*sql.Rows
}

func (*Rows) Scans added in v1.0.1

func (r *Rows) Scans(row any) error

type Tx

type Tx struct {
	Debug  bool
	Driver string
	// contains filtered or unexported fields
}

func (*Tx) Commit

func (t *Tx) Commit() error

func (*Tx) CurrentUnixTimestamp added in v1.0.4

func (t *Tx) CurrentUnixTimestamp() int64

func (*Tx) DeleteRowByID added in v1.0.3

func (t *Tx) DeleteRowByID(ctx context.Context, id int64, row any) error

func (*Tx) Each added in v1.0.5

func (t *Tx) Each(ctx context.Context, query string, callback func(ctx context.Context, rows *Rows) error, args ...any) error

func (*Tx) EachPrepared added in v1.0.5

func (t *Tx) EachPrepared(ctx context.Context, prep *Prepared, callback func(ctx context.Context, rows *Rows) error) error

func (*Tx) Exec

func (t *Tx) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

func (*Tx) ExecPrepared added in v1.0.5

func (t *Tx) ExecPrepared(ctx context.Context, prep *Prepared) (sql.Result, error)

func (*Tx) InsertRow added in v1.0.5

func (t *Tx) InsertRow(ctx context.Context, row any) error

func (*Tx) PrepareSQL added in v1.0.8

func (t *Tx) PrepareSQL(query string, args ...any) *Prepared

func (*Tx) Query

func (t *Tx) Query(ctx context.Context, query string, args ...any) (*Rows, error)

func (*Tx) QueryPrepared added in v1.0.5

func (t *Tx) QueryPrepared(ctx context.Context, prep *Prepared) (*Rows, error)

func (*Tx) QueryRow

func (t *Tx) QueryRow(ctx context.Context, query string, args ...any) *Row

func (*Tx) QueryRowByID added in v1.0.3

func (t *Tx) QueryRowByID(ctx context.Context, id int64, row any) error

func (*Tx) QueryRowPrepared added in v1.0.5

func (t *Tx) QueryRowPrepared(ctx context.Context, prep *Prepared) *Row

func (*Tx) Rollback

func (t *Tx) Rollback() error

func (*Tx) RowExists added in v1.0.3

func (t *Tx) RowExists(ctx context.Context, id int64, row any) bool

func (*Tx) UpdateRow added in v1.0.9

func (t *Tx) UpdateRow(ctx context.Context, row any) error

func (*Tx) UpdateRowOnly added in v1.0.9

func (t *Tx) UpdateRowOnly(ctx context.Context, row any, fields ...string) error

Jump to

Keyboard shortcuts

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