database

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InjectTx

func InjectTx(ctx context.Context, s SqlGdbc) context.Context

Types

type DatabaseConnector added in v1.0.0

type DatabaseConnector interface {
	// Connect to database using:
	// 1. drivername
	// 2. dsn(connection string)
	// 3. poolOptions: nil if no need to configure pool
	Connect(drivername string, dsn string, poolOptions *PoolOptions) (*Gdbc, error)
}

func NewSqlxDatabaseConnector added in v1.0.0

func NewSqlxDatabaseConnector() DatabaseConnector

type EnableTransactor

type EnableTransactor interface {
	WithinTransaction(ctx context.Context, txFunc func(ctx context.Context) error) error
	WithinTransactionOptions(ctx context.Context, txFunc func(ctx context.Context) error, txOption *sql.TxOptions) error
}

type Gdbc

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

Used this in repositories

func (*Gdbc) Exec

func (g *Gdbc) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

Exec implements SqlGdbc.

func (*Gdbc) Get

func (g *Gdbc) Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error

Get implements SqlGdbc.

func (*Gdbc) Prepare

func (g *Gdbc) Prepare(ctx context.Context, query string) (*sql.Stmt, error)

Prepare implements SqlGdbc.

func (*Gdbc) Query

func (g *Gdbc) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

Query implements SqlGdbc.

func (*Gdbc) QueryRow

func (g *Gdbc) QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRow implements SqlGdbc.

func (*Gdbc) Select

func (g *Gdbc) Select(ctx context.Context, dest interface{}, query string, args ...interface{}) error

Select implements SqlGdbc.

func (*Gdbc) WithinTransaction

func (g *Gdbc) WithinTransaction(ctx context.Context, txFunc func(ctx context.Context) error) error

func (*Gdbc) WithinTransactionOptions

func (g *Gdbc) WithinTransactionOptions(ctx context.Context, txFunc func(ctx context.Context) error, txOptions *sql.TxOptions) error

type PoolOptions

type PoolOptions struct {
	MaxIdleCount int           // zero means defaultMaxIdleConns; negative means 0
	MaxOpen      int           // <= 0 means unlimited
	MaxLifetime  time.Duration // maximum amount of time a connection may be reused
	MaxIdleTime  time.Duration // maximum amount of time a connection may be idle before being closed
}

type SqlGdbc

type SqlGdbc interface {
	Transactor
	Exec(query string, args ...interface{}) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	Get(dest interface{}, query string, args ...interface{}) error
	Select(dest interface{}, query string, args ...interface{}) error
}

SqlGdbc (SQL Go database connection) is a wrapper for SQL database handler ( can be *sql.DB or *sql.Tx) It should be able to work with all SQL data that follows SQL standard.

func ExtractTx

func ExtractTx(ctx context.Context) SqlGdbc

type SqlxConnTx added in v1.0.0

type SqlxConnTx struct {
	DB *sqlx.Tx
}

SqlxConnx is the sqlx.Tx based implementation of GDBC

func NewSqlxConnGdbc added in v1.0.0

func NewSqlxConnGdbc(db *sqlx.Tx) *SqlxConnTx

func (*SqlxConnTx) Exec added in v1.0.0

func (s *SqlxConnTx) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements SqlGdbc.

func (*SqlxConnTx) Get added in v1.0.0

func (s *SqlxConnTx) Get(dest interface{}, query string, args ...interface{}) error

Get implements database.SqlGdbc.

func (*SqlxConnTx) Prepare added in v1.0.0

func (s *SqlxConnTx) Prepare(query string) (*sql.Stmt, error)

Prepare implements SqlGdbc.

func (*SqlxConnTx) Query added in v1.0.0

func (s *SqlxConnTx) Query(query string, args ...interface{}) (*sql.Rows, error)

Query implements SqlGdbc.

func (*SqlxConnTx) QueryRow added in v1.0.0

func (s *SqlxConnTx) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow implements SqlGdbc.

func (*SqlxConnTx) Select added in v1.0.0

func (s *SqlxConnTx) Select(dest interface{}, query string, args ...interface{}) error

Select implements database.SqlGdbc.

func (*SqlxConnTx) WithinTransaction added in v1.0.0

func (sct *SqlxConnTx) WithinTransaction(ctx context.Context, txFunc func(ctx context.Context) error) error

func (*SqlxConnTx) WithinTransactionOptions added in v1.0.0

func (sct *SqlxConnTx) WithinTransactionOptions(ctx context.Context, txFunc func(ctx context.Context) error, txOptions *sql.TxOptions) error

type SqlxDBTx added in v1.0.0

type SqlxDBTx struct {
	DB *sqlx.DB
}

SqlxDBx is the sqlx.DB based implementation of GDBC

func NewSqlxDBGdbc added in v1.0.0

func NewSqlxDBGdbc(db *sqlx.DB) *SqlxDBTx

func (*SqlxDBTx) Exec added in v1.0.0

func (s *SqlxDBTx) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements SqlGdbc.

func (*SqlxDBTx) Get added in v1.0.0

func (s *SqlxDBTx) Get(dest interface{}, query string, args ...interface{}) error

Get implements database.SqlGdbc.

func (*SqlxDBTx) Prepare added in v1.0.0

func (s *SqlxDBTx) Prepare(query string) (*sql.Stmt, error)

Prepare implements SqlGdbc.

func (*SqlxDBTx) Query added in v1.0.0

func (s *SqlxDBTx) Query(query string, args ...interface{}) (*sql.Rows, error)

Query implements SqlGdbc.

func (*SqlxDBTx) QueryRow added in v1.0.0

func (s *SqlxDBTx) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow implements SqlGdbc.

func (*SqlxDBTx) Select added in v1.0.0

func (s *SqlxDBTx) Select(dest interface{}, query string, args ...interface{}) error

Select implements database.SqlGdbc.

func (*SqlxDBTx) WithinTransaction added in v1.0.0

func (sdt *SqlxDBTx) WithinTransaction(ctx context.Context, txFunc func(ctx context.Context) error) error

func (*SqlxDBTx) WithinTransactionOptions added in v1.0.0

func (sdt *SqlxDBTx) WithinTransactionOptions(ctx context.Context, txFunc func(ctx context.Context) error, txOptions *sql.TxOptions) error

type SqlxDatabaseConnector added in v1.0.0

type SqlxDatabaseConnector struct {
}

func (*SqlxDatabaseConnector) Connect added in v1.0.0

func (c *SqlxDatabaseConnector) Connect(driverName string, dsn string, poolOptions *PoolOptions) (*Gdbc, error)

type Transactor

type Transactor interface {
	WithinTransaction(ctx context.Context, txFunc func(ctx context.Context) error) error
	WithinTransactionOptions(ctx context.Context, txFunc func(ctx context.Context) error, txOption *sql.TxOptions) error
}

type TxKey

type TxKey struct{}

Jump to

Keyboard shortcuts

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