Documentation
¶
Index ¶
- Constants
- Variables
- type Connection
- type DB
- func (r *DB) AddSelect(args ...string) *DB
- func (r *DB) AndHavingRaw(raw string) *DB
- func (r *DB) AndWhere(operand, operator string, val any) *DB
- func (r *DB) AndWhereBetween(col string, val1, val2 any) *DB
- func (r *DB) AndWhereIn(field string, in any) *DB
- func (r *DB) AndWhereNotBetween(col string, val1, val2 any) *DB
- func (r *DB) AndWhereNotIn(field string, in any) *DB
- func (r *DB) AndWhereNotNull(field string) *DB
- func (r *DB) AndWhereNull(field string) *DB
- func (r *DB) AndWhereRaw(raw string) *DB
- func (r *DB) Avg(column string) (avg float64, err error)
- func (r *DB) Chunk(src any, amount int64, fn func(rows []any) bool) error
- func (r *DB) Count() (cnt int64, err error)
- func (r *DB) Dd()
- func (r *DB) Decrement(column string, on uint64) (int64, error)
- func (r *DB) Delete() (int64, error)
- func (r *DB) DoesntExists() (bool, error)
- func (r *DB) Drop(tables string) (sql.Result, error)
- func (r *DB) DropIfExists(tables ...string) (res sql.Result, err error)
- func (r *DB) Dump()
- func (r *DB) EachToStruct(fn EachToStructFunc) error
- func (r *DB) Exists() (exists bool, err error)
- func (r *DB) Find(src any, id uint64) error
- func (r *DB) First(src any) error
- func (r *DB) From(fromTbl string) *DB
- func (r *DB) FullJoin(table, left, operator, right string) *DB
- func (r *DB) FullOuterJoin(table, left, operator, right string) *DB
- func (r *DB) GroupBy(expr string) *DB
- func (r *DB) HasColumns(schema, tbl string, cols ...string) (colsExists bool, err error)
- func (r *DB) HasTable(schema, tbl string) (tblExists bool, err error)
- func (r *DB) Having(operand, operator string, val any) *DB
- func (r *DB) HavingRaw(raw string) *DB
- func (r *DB) InRandomOrder() *DB
- func (r *DB) InTransaction(fn func() (any, error)) error
- func (r *DB) Increment(column string, on uint64) (int64, error)
- func (r *DB) InnerJoin(table, left, operator, right string) *DB
- func (r *DB) Insert(data any) error
- func (r *DB) InsertBatch(data any) error
- func (r *DB) InsertGetId(data any) (uint64, error)
- func (r *DB) LeftJoin(table, left, operator, right string) *DB
- func (r *DB) Limit(lim int64) *DB
- func (r *DB) LockForUpdate() *DB
- func (r *DB) Max(column string) (max float64, err error)
- func (r *DB) Min(column string) (min float64, err error)
- func (r *DB) Next(rows *sql.Rows, src any) error
- func (r *DB) Offset(off int64) *DB
- func (r *DB) OrHavingRaw(raw string) *DB
- func (r *DB) OrWhere(operand, operator string, val any) *DB
- func (r *DB) OrWhereBetween(col string, val1, val2 any) *DB
- func (r *DB) OrWhereIn(field string, in any) *DB
- func (r *DB) OrWhereNotBetween(col string, val1, val2 any) *DB
- func (r *DB) OrWhereNotIn(field string, in any) *DB
- func (r *DB) OrWhereNotNull(field string) *DB
- func (r *DB) OrWhereNull(field string) *DB
- func (r *DB) OrWhereRaw(raw string) *DB
- func (r *DB) OrderBy(column string, direction string) *DB
- func (r *DB) OrderByRaw(exp string) *DB
- func (r *DB) Pluck(src any) ([]any, error)
- func (r *DB) PluckMap(src any, colKey, colValue string) (val []map[any]any, err error)
- func (r *DB) Rename(from, to string) (sql.Result, error)
- func (r *DB) Replace(data any, conflict string) (int64, error)
- func (r *DB) RightJoin(table, left, operator, right string) *DB
- func (r *DB) ScanStruct(src any) error
- func (r *DB) Schema(tblName string, fn func(table *Table) error) (res sql.Result, err error)
- func (r *DB) SchemaIfNotExists(tblName string, fn func(table *Table) error) (res sql.Result, err error)
- func (r *DB) Select(args ...string) *DB
- func (r *DB) SelectRaw(raw string) *DB
- func (r *DB) Sql() *sql.DB
- func (r *DB) Sum(column string) (sum float64, err error)
- func (r *DB) Table(table string) *DB
- func (r *DB) Truncate(tables string) (sql.Result, error)
- func (r *DB) Union() *DB
- func (r *DB) UnionAll() *DB
- func (r *DB) Update(data any) (int64, error)
- func (r *DB) Value(src any, column string) error
- func (r *DB) Where(operand, operator string, val any) *DB
- func (r *DB) WhereBetween(col string, val1, val2 any) *DB
- func (r *DB) WhereExists(rr *DB) *DB
- func (r *DB) WhereIn(field string, in any) *DB
- func (r *DB) WhereNotBetween(col string, val1, val2 any) *DB
- func (r *DB) WhereNotExists(rr *DB) *DB
- func (r *DB) WhereNotIn(field string, in any) *DB
- func (r *DB) WhereNotNull(field string) *DB
- func (r *DB) WhereNull(field string) *DB
- func (r *DB) WhereRaw(raw string) *DB
- type EachToStructFunc
- type Table
- func (t *Table) BigIncrements(colNm string) *Table
- func (t *Table) BigInt(colNm string) *Table
- func (t *Table) Boolean(colNm string) *Table
- func (t *Table) Change()
- func (t *Table) Char(colNm string, len uint64) *Table
- func (t *Table) Collation(coll string) *Table
- func (t *Table) Comment(cmt string) *Table
- func (t *Table) Concurrently() *Table
- func (t *Table) Date(colNm string, isDefault bool) *Table
- func (t *Table) DateTime(colNm string, isDefault bool) *Table
- func (t *Table) DateTimeTz(colNm string, isDefault bool) *Table
- func (t *Table) DblPrecision(colNm string) *Table
- func (t *Table) Decimal(colNm string, precision, scale uint64) *Table
- func (t *Table) Default(val interface{}) *Table
- func (t *Table) DropColumn(colNm string) *Table
- func (t *Table) DropIndex(idxNm string) *Table
- func (t *Table) ForeignKey(idxName, rfcTbl, onCol string) *Table
- func (t *Table) IfExists() *Table
- func (t *Table) IfNotExists() *Table
- func (t *Table) Include(columns ...string) *Table
- func (t *Table) Increments(colNm string) *Table
- func (t *Table) Index(idxName string) *Table
- func (t *Table) Integer(colNm string) *Table
- func (t *Table) Json(colNm string) *Table
- func (t *Table) Jsonb(colNm string) *Table
- func (t *Table) NotNull() *Table
- func (t *Table) Numeric(colNm string, precision, scale uint64) *Table
- func (t *Table) Point(colNm string) *Table
- func (t *Table) Polygon(colNm string) *Table
- func (t *Table) Rename(from, to string) *Table
- func (t *Table) RenameIndex(idxName, newName string) *Table
- func (t *Table) SmallInt(colNm string) *Table
- func (t *Table) String(colNm string, len uint64) *Table
- func (t *Table) TableComment(cmt string)
- func (t *Table) Text(colNm string) *Table
- func (t *Table) Time(colNm string, isDefault bool) *Table
- func (t *Table) TsQuery(colNm string) *Table
- func (t *Table) TsVector(colNm string) *Table
- func (t *Table) Unique(idxName string) *Table
- type Txn
Constants ¶
const ( TypeSerial = "SERIAL" TypeBigSerial = "BIGSERIAL" TypeSmallInt = "SMALLINT" TypeInt = "INTEGER" TypeBigInt = "BIGINT" TypeBoolean = "BOOLEAN" TypeText = "TEXT" TypeVarchar = "VARCHAR" TypeChar = "CHAR" TypeDate = "DATE" TypeTime = "TIME" TypeDateTime = "TIMESTAMP" TypeDateTimeTz = "TIMESTAMPTZ" CurrentDate = "CURRENT_DATE" CurrentTime = "CURRENT_TIME" CurrentDateTime = "NOW()" TypeDblPrecision = "DOUBLE PRECISION" TypeNumeric = "NUMERIC" TypeTsVector = "TSVECTOR" TypeTsQuery = "TSQUERY" TypeJson = "JSON" TypeJsonb = "JSONB" TypePoint = "POINT" TypePolygon = "POLYGON" )
column types
const ( DefaultSchema = "public" SemiColon = ";" AlterTable = "ALTER TABLE " Add = " ADD " Modify = " ALTER " Drop = " DROP " Rename = " RENAME " IfExistsExp = " IF EXISTS " IfNotExistsExp = " IF NOT EXISTS " Concurrently = " CONCURRENTLY " Constraint = " CONSTRAINT " )
specific for PostgreSQL driver + SQL std
const ( IfExistsUndeclared = iota IfExists IfNotExists )
Variables ¶
var ErrNoMoreRows = errors.New("sql: no more rows")
ErrNoMoreRows is returned by Next when there were no more rows
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection encloses DB struct
func NewConnection ¶
func NewConnection(driverName, dataSourceName string) *Connection
NewConnection returns pre-defined Connection structure
func NewConnectionFromDb ¶ added in v0.8.7
func NewConnectionFromDb(db *sql.DB) *Connection
NewConnectionFromDb returns re-defined Connection structure created via db handle with connection(s)
type DB ¶
type DB struct { Builder *builder Conn *Connection Txn *Txn }
DB is an entity that composite builder and Conn types
func (*DB) AndHavingRaw ¶
AndHavingRaw accepts custom string to apply it to having clause with logical OR
func (*DB) AndWhere ¶
AndWhere accepts left operand-operator-right operand to apply them to where clause with AND logical operator
func (*DB) AndWhereBetween ¶
AndWhereBetween sets the clause AND BETWEEN 2 values
func (*DB) AndWhereIn ¶
AndWhereIn appends OR IN (val1, val2, val3...) stmt to WHERE clause
func (*DB) AndWhereNotBetween ¶
AndWhereNotBetween sets the clause AND BETWEEN 2 values
func (*DB) AndWhereNotIn ¶
AndWhereNotIn appends OR NOT IN (val1, val2, val3...) stmt to WHERE clause
func (*DB) AndWhereNotNull ¶
AndWhereNotNull appends fieldName IS NOT NULL stmt to WHERE clause
func (*DB) AndWhereNull ¶
AndWhereNull appends fieldName IS NULL stmt to WHERE clause
func (*DB) AndWhereRaw ¶
AndWhereRaw accepts custom string to apply it to where clause with logical OR
func (*DB) Chunk ¶
Chunk run queries by chinks by passing user-land function with an ability to stop execution when needed by returning false and proceed to execute queries when return true
func (*DB) Delete ¶
Delete builds a DELETE stmt with corresponding where clause if stated returning affected rows
func (*DB) DoesntExists ¶
DoesntExists an inverse of Exists
func (*DB) DropIfExists ¶
DropIfExists drops >=1 tables if they are existent
func (*DB) EachToStruct ¶ added in v1.0.0
func (r *DB) EachToStruct(fn EachToStructFunc) error
EachToStruct scans query into specific struct per row with iterative behaviour
func (*DB) Exists ¶
Exists checks whether conditional rows are existing (returns true) or not (returns false)
func (*DB) From ¶
From prepares sql stmt to set data from another table, ex.: UPDATE employees SET sales_count = sales_count + 1 FROM accounts
func (*DB) FullOuterJoin ¶
FullOuterJoin joins tables by getting an outer sets
func (*DB) HasColumns ¶
HasColumns checks whether those cols exists in a particular schema/table
func (*DB) InRandomOrder ¶
InRandomOrder add ORDER BY random() - note be cautious on big data-tables it can lead to slowing down perf
func (*DB) InTransaction ¶
InTransaction executes fn passed as an argument in transaction mode if there are no results returned - txn will be rolled back, otherwise committed and returned
func (*DB) InsertBatch ¶
InsertBatch inserts multiple rows based on transaction
func (*DB) InsertGetId ¶
InsertGetId inserts one row with param bindings and returning id
func (*DB) LeftJoin ¶
LeftJoin joins tables by getting elements from left without those that null on the right
func (*DB) Next ¶ added in v1.0.0
Next will parse the next row into a struct passed as src parameter. Returns ErrNoMoreRows if there are no more row to parse
func (*DB) OrHavingRaw ¶
OrHavingRaw accepts custom string to apply it to having clause with logical OR
func (*DB) OrWhere ¶
OrWhere accepts left operand-operator-right operand to apply them to where clause with OR logical operator
func (*DB) OrWhereBetween ¶
OrWhereBetween sets the clause OR BETWEEN 2 values
func (*DB) OrWhereNotBetween ¶
OrWhereNotBetween sets the clause OR BETWEEN 2 values
func (*DB) OrWhereNotIn ¶
OrWhereNotIn appends OR NOT IN (val1, val2, val3...) stmt to WHERE clause
func (*DB) OrWhereNotNull ¶
OrWhereNotNull appends fieldName IS NOT NULL stmt to WHERE clause
func (*DB) OrWhereNull ¶
OrWhereNull appends fieldName IS NULL stmt to WHERE clause
func (*DB) OrWhereRaw ¶
OrWhereRaw accepts custom string to apply it to where clause with logical OR
func (*DB) OrderByRaw ¶
OrderByRaw adds ORDER BY raw expression to SQL stmt
func (*DB) Pluck ¶
Pluck getting values of a particular column(s) of a struct and place them into slice
func (*DB) PluckMap ¶
PluckMap getting values of a particular key/value columns and place them into map values of the returning map is a structure passed as src and filled with data from DB
func (*DB) Replace ¶
Replace inserts data if conflicting row hasn't been found, else it will update an existing one
func (*DB) RightJoin ¶
RightJoin joins tables by getting elements from right without those that null on the left
func (*DB) ScanStruct ¶ added in v1.0.0
ScanStruct scans query into specific struct
func (*DB) Schema ¶
Schema creates and/or manipulates table structure with an appropriate types/indices/comments/defaults/nulls etc
func (*DB) SchemaIfNotExists ¶ added in v0.8.0
func (r *DB) SchemaIfNotExists(tblName string, fn func(table *Table) error) (res sql.Result, err error)
SchemaIfNotExists creates table structure if not exists with an appropriate types/indices/comments/defaults/nulls etc
func (*DB) UnionAll ¶
UnionAll joins multiple queries to select all rows from both tables with duplicate
func (*DB) Update ¶
Update builds an UPDATE sql stmt with corresponding where/from clauses if stated returning affected rows
func (*DB) WhereBetween ¶
WhereBetween sets the clause BETWEEN 2 values
func (*DB) WhereExists ¶
WhereExists constructs one builder from another to implement WHERE EXISTS sql/dml clause
func (*DB) WhereNotBetween ¶
WhereNotBetween sets the clause NOT BETWEEN 2 values
func (*DB) WhereNotExists ¶
WhereNotExists constructs one builder from another to implement WHERE NOT EXISTS sql/dml clause
func (*DB) WhereNotIn ¶
WhereNotIn appends NOT IN (val1, val2, val3...) stmt to WHERE clause
func (*DB) WhereNotNull ¶
WhereNotNull appends fieldName IS NOT NULL stmt to WHERE clause
type EachToStructFunc ¶ added in v1.0.0
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is the type for operations on table schema
func (*Table) BigIncrements ¶
BigIncrements creates auto incremented primary key big integer column
func (*Table) Concurrently ¶ added in v0.8.1
func (*Table) DateTime ¶
DateTime creates datetime column with an ability to set NOW() as default value
func (*Table) DateTimeTz ¶
DateTimeTz creates datetime column with an ability to set NOW() as default value + time zone support
func (*Table) DblPrecision ¶
DblPrecision creates dbl precision type column
func (*Table) DropColumn ¶
DropColumn the column named colNm in this table context
func (*Table) ForeignKey ¶
ForeignKey sets the last column to reference rfcTbl on onCol with idxName foreign key index
func (*Table) IfNotExists ¶ added in v0.8.0
IfNotExists add column/index if not exists
func (*Table) Increments ¶
Increments creates auto incremented primary key integer column
func (*Table) RenameIndex ¶ added in v1.0.6
RenameIndex changes the name of a particular index
func (*Table) TableComment ¶
TableComment sets the comment for table
type Txn ¶ added in v0.8.9
func (*Txn) Delete ¶ added in v0.8.9
Delete builds a DELETE stmt with corresponding where clause if stated returning affected rows
func (*Txn) Insert ¶ added in v0.8.9
Insert inserts one row with param bindings from struct in transaction context
func (*Txn) InsertGetId ¶ added in v0.8.9
InsertGetId inserts one row with param bindings and returning id in transaction context