db

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(driverName string, conStr string) (*sql.DB, error)

* e.g conn, err := db.New("postgres", "postgres://postgres:password@localhost:port_no/db_name")

Types

type Completer added in v0.1.3

type Completer interface {
	/*
	 *	set update data
	 * 	m equals struct matching db relation
	 */
	Set(m map[string]interface{}) Completer
	/*
	 * 	execute non returning query like update and delete
	 */
	Apply() error
	/*
	 * 	execute non returning query like update and delete with context
	 */
	ApplyCtx(ctx context.Context) error
	/*
	 * 	execute non returning query like update and delete with context in a transaction
	 */
	TxApplyCtx(ctx context.Context, tx *sql.Tx) error
	/*
	 * 	execute select or queries returning many rows
	 */
	Many(i interface{}) error
	/*
	 * 	execute select or queries returning many rows with context
	 */
	ManyCtx(ctx context.Context, i interface{}) error
	/*
	 * 	execute select or queries returning many rows with context in a transaction
	 */
	TxManyCtx(ctx context.Context, tx *sql.Tx, i interface{}) error
	/*
	 * 	execute select scan into provided interface
	 */
	One(i interface{}) error
	/*
	 * 	execute select scan into provided interface with context
	 */
	OneCtx(ctx context.Context, i interface{}) error
	/*
	 * 	execute select scan into provided interface with context in a transaction
	 */
	TxOneCtx(ctx context.Context, tx *sql.Tx, i interface{}) error
	/*
	 *	where condition
	 *	could be map[string]interface{} or []map[string]interface{}
	 *  e.g. map[string]interface{ "id": 1 }
	 */
	Where(any) Completer
	/*
	 * 	perform query for values in list
	 */
	In(field string, values []interface{}) Completer
}

type Query added in v0.1.3

type Query struct {
	Conn *sql.DB
}

func (Query) Create added in v0.1.3

func (q Query) Create(name string, definition ...string) error

create table

func (Query) CreateCtx added in v0.1.5

func (q Query) CreateCtx(ctx context.Context, name string, definition ...string) error

create table with context

func (Query) Delete added in v0.1.3

func (q Query) Delete(i interface{}) Completer

delete data

func (Query) Find added in v0.1.3

func (q Query) Find(i interface{}) Completer

find data from relation

func (Query) FindAll added in v0.1.3

func (q Query) FindAll(i interface{}) ([]map[string]interface{}, error)

find all from relation

func (Query) FindAllCtx added in v0.1.5

func (q Query) FindAllCtx(ctx context.Context, i interface{}) ([]map[string]interface{}, error)

find all with context from relation

func (Query) Insert added in v0.1.3

func (q Query) Insert(i interface{}) (int64, error)

insert into table

func (Query) InsertCtx added in v0.1.5

func (q Query) InsertCtx(ctx context.Context, i interface{}) (int64, error)

insert into table with context

func (Query) TxCreateCtx added in v0.1.9

func (q Query) TxCreateCtx(ctx context.Context, tx *sql.Tx, name string, definition ...string) error

tx create table with context

func (Query) TxFindAllCtx added in v0.1.9

func (q Query) TxFindAllCtx(ctx context.Context, tx *sql.Tx, i interface{}) ([]map[string]interface{}, error)

TX find all with context from relation

func (Query) TxInsertCtx added in v0.1.9

func (q Query) TxInsertCtx(ctx context.Context, tx *sql.Tx, i interface{}) (int64, error)

TX insert into table with context

func (Query) Update added in v0.1.3

func (q Query) Update(i interface{}) Completer

update table

Jump to

Keyboard shortcuts

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