simplesql

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInsertConflict = errors.New("insert conflict")
	ErrRecordNotFound = errors.New("record not found")
	ErrInternal       = errors.New("internal error")
)

Functions

func MySQLErrHandler

func MySQLErrHandler(err error) error

MySQLErrHandler processes MySQL errors and returns a custom StorageError

func SQLiteErrHandler

func SQLiteErrHandler(err error) error

SQLiteErrHandler processes SQLite errors and returns a custom StorageError

Types

type Database

type Database struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(db *sqlx.DB, opts ...Option) Database

func (*Database) ApplyMigrations

func (d *Database) ApplyMigrations(schemaMigrations []Migration) error

func (*Database) GetRowByKey

func (d *Database) GetRowByKey(
	ctx context.Context, tableName string, key interface{}, row interface{},
) error

func (*Database) HardDeleteByKey

func (d *Database) HardDeleteByKey(
	ctx context.Context, tableName string, key interface{}, row interface{},
) error

func (*Database) InsertRow

func (d *Database) InsertRow(
	ctx context.Context, execer sqlx.ExecerContext, tableName string, row interface{},
) error

func (*Database) SelectRows

func (d *Database) SelectRows(
	ctx context.Context, tableName string, filters interface{}, result interface{},
) error

func (*Database) UpdateRow

func (d *Database) UpdateRow(
	ctx context.Context, execer sqlx.ExecerContext, ID string, version uint64, tableName string, fields interface{},
) error

type ErrHandler

type ErrHandler func(error) error

type Migration

type Migration struct {
	Version int
	Up      string
	Down    string
}

type Option

type Option func(*Database)

func WithErrHandler

func WithErrHandler(errHandler ErrHandler) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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