Documentation ¶
Index ¶
- func ToSnakeCase(str string) string
- type DB
- func (d *DB) Begin() (*Tx, error)
- func (d *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (d *DB) HealthCheck() datasource.Health
- func (d *DB) Prepare(query string) (*sql.Stmt, error)
- func (d *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (d *DB) QueryRow(query string, args ...interface{}) *sql.Row
- func (d *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (d *DB) Select(ctx context.Context, data interface{}, query string, args ...interface{})
- type DBConfig
- type Log
- type Tx
- func (t *Tx) Commit() error
- func (t *Tx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (t *Tx) Prepare(query string) (*sql.Stmt, error)
- func (t *Tx) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (t *Tx) QueryRow(query string, args ...interface{}) *sql.Row
- func (t *Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (t *Tx) Rollback() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToSnakeCase ¶
Types ¶
type DB ¶
DB is a wrapper around sql.DB which provides some more features.
func (*DB) HealthCheck ¶
func (d *DB) HealthCheck() datasource.Health
func (*DB) QueryRowContext ¶
func (*DB) Select ¶
Select runs a query with args and binds the result of the query to the data. data should ba a point to a slice, struct or any type. Slice will return multiple objects whereas struct will return a single object.
Example Usages:
Get multiple rows with only one column ids := make([]int, 0) db.Select(ctx, &ids, "select id from users")
Get a single object from database type user struct { Name string ID int Image string } u := user{} db.Select(ctx, &u, "select * from users where id=?", 1)
Get array of objects from multiple rows type user struct { Name string ID int Image string `db:"image_url"` } users := []user{} db.Select(ctx, &users, "select * from users")
type DBConfig ¶
DBConfig has those members which are necessary variables while connecting to database.