database

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeMySQL    = "mysql"
	TypePostgres = "postgres"
	TypeSQLite   = "sqlite"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	Type() string
	Connect(ctx context.Context) error
	Migrate(ctx context.Context, toVersion uint) error
	Ping(ctx context.Context) error
	WithinTransaction(ctx context.Context, txCallback func(ctx context.Context) error) error
}

type MySQL

type MySQL struct {
	SQL
	Config config.MySQLConfig
}

func NewMySQL

func NewMySQL(config config.MySQLConfig) *MySQL

func (*MySQL) Connect

func (ds *MySQL) Connect(ctx context.Context) error

func (MySQL) Migrate added in v0.6.0

func (ds MySQL) Migrate(ctx context.Context, toVersion uint) error

func (MySQL) Ping

func (ds MySQL) Ping(ctx context.Context) error

func (MySQL) Type

func (ds MySQL) Type() string

type NullString

type NullString struct {
	sql.NullString
}

NullString type representing a nullable string

func StringToNullString

func StringToNullString(str *string) NullString

func (NullString) MarshalJSON

func (s NullString) MarshalJSON() ([]byte, error)

MarshalJSON returns the marshaled json string

func (*NullString) UnmarshalJSON

func (s *NullString) UnmarshalJSON(data []byte) error

UnmarshalJSON returns the unmarshaled struct

type NullTime

type NullTime struct {
	sql.NullTime
}

NullTime type representing a nullable string

func (NullTime) MarshalJSON

func (t NullTime) MarshalJSON() ([]byte, error)

MarshalJSON returns the marshaled json string

type Postgres added in v0.4.0

type Postgres struct {
	SQL
	Config config.PostgresConfig
}

func NewPostgres added in v0.4.0

func NewPostgres(config config.PostgresConfig) *Postgres

func (*Postgres) Connect added in v0.4.0

func (ds *Postgres) Connect(ctx context.Context) error

func (Postgres) Migrate added in v0.6.0

func (ds Postgres) Migrate(ctx context.Context, toVersion uint) error

func (Postgres) Ping added in v0.4.0

func (ds Postgres) Ping(ctx context.Context) error

func (Postgres) Type added in v0.4.0

func (ds Postgres) Type() string

type SQL

type SQL struct {
	DB *sqlx.DB
}

func (SQL) ExecContext

func (ds SQL) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (SQL) GetContext

func (ds SQL) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (SQL) NamedExecContext

func (ds SQL) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)

func (SQL) PrepareContext

func (ds SQL) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

func (SQL) QueryContext

func (ds SQL) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (SQL) QueryRowContext

func (ds SQL) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (SQL) SelectContext

func (ds SQL) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (SQL) WithinTransaction

func (ds SQL) WithinTransaction(ctx context.Context, txFunc func(ctx context.Context) error) error

type SQLRepository

type SQLRepository struct {
	DB *SQL
}

SQLRepository type

func NewSQLRepository

func NewSQLRepository(db *SQL) SQLRepository

NewSQLRepository returns an instance of SQLRepository

type SQLite added in v0.11.0

type SQLite struct {
	SQL
	Config config.SQLiteConfig
}

func NewSQLite added in v0.11.0

func NewSQLite(config config.SQLiteConfig) *SQLite

func (*SQLite) Connect added in v0.11.0

func (ds *SQLite) Connect(ctx context.Context) error

func (SQLite) Migrate added in v0.11.0

func (ds SQLite) Migrate(ctx context.Context, toVersion uint) error

func (SQLite) Ping added in v0.11.0

func (ds SQLite) Ping(ctx context.Context) error

func (SQLite) Type added in v0.11.0

func (ds SQLite) Type() string

type SqlQueryable

type SqlQueryable interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

type SqlTx

type SqlTx struct {
	Tx *sqlx.Tx
}

func (SqlTx) ExecContext

func (q SqlTx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (SqlTx) GetContext

func (q SqlTx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (SqlTx) NamedExecContext

func (q SqlTx) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)

func (SqlTx) PrepareContext

func (q SqlTx) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)

func (SqlTx) QueryContext

func (q SqlTx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

func (SqlTx) QueryRowContext

func (q SqlTx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

func (SqlTx) SelectContext

func (q SqlTx) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error

Jump to

Keyboard shortcuts

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