Documentation ¶
Index ¶
- Constants
- func Alias(from, to string) alias
- func SetDriver(driverType string)
- type CombineType
- type Comparison
- type Compat
- type ConditionBuilder
- type Data
- type Date
- type Datetime
- type Executor
- type Join
- type MysqlCompat
- type Order
- type PostgresCompat
- type QueryBuilder
- func (q *QueryBuilder) AddWhere(c ConditionBuilder) *QueryBuilder
- func (q *QueryBuilder) BulkInsert(table interface{}, data []Data) (sql.Result, error)
- func (q *QueryBuilder) BulkInsertContext(ctx context.Context, table interface{}, data []Data) (sql.Result, error)
- func (q *QueryBuilder) Delete(table interface{}) (sql.Result, error)
- func (q *QueryBuilder) DeleteContext(ctx context.Context, table interface{}) (sql.Result, error)
- func (q *QueryBuilder) Get(table interface{}) (Results, error)
- func (q *QueryBuilder) GetContext(ctx context.Context, table interface{}) (Results, error)
- func (q *QueryBuilder) GetOne(table interface{}) (*Result, error)
- func (q *QueryBuilder) GetOneContext(ctx context.Context, table interface{}) (*Result, error)
- func (q *QueryBuilder) GroupBy(fields ...string) *QueryBuilder
- func (q *QueryBuilder) Insert(table interface{}, data Data) (sql.Result, error)
- func (q *QueryBuilder) InsertContext(ctx context.Context, table interface{}, data Data) (sql.Result, error)
- func (q *QueryBuilder) Join(table, from, to string, c Comparison) *QueryBuilder
- func (q *QueryBuilder) Like(field string, value interface{}) *QueryBuilder
- func (q *QueryBuilder) Limit(limit int64) *QueryBuilder
- func (q *QueryBuilder) NotLike(field string, value interface{}) *QueryBuilder
- func (q *QueryBuilder) Offset(offset int64) *QueryBuilder
- func (q *QueryBuilder) OrLike(field string, value interface{}) *QueryBuilder
- func (q *QueryBuilder) OrNotLike(field string, value interface{}) *QueryBuilder
- func (q *QueryBuilder) OrWhere(field string, value interface{}, comparison Comparison) *QueryBuilder
- func (q *QueryBuilder) OrWhereGroup(generator func(g *WhereGroup)) *QueryBuilder
- func (q *QueryBuilder) OrWhereIn(field string, values ...interface{}) *QueryBuilder
- func (q *QueryBuilder) OrWhereNotIn(field string, values ...interface{}) *QueryBuilder
- func (q *QueryBuilder) OrWhereRaw(raw string) *QueryBuilder
- func (q *QueryBuilder) OrderBy(field string, sort SortMode) *QueryBuilder
- func (q *QueryBuilder) Reset()
- func (q *QueryBuilder) Select(fields ...interface{}) *QueryBuilder
- func (q *QueryBuilder) SelectAvg(field string) *QueryBuilder
- func (q *QueryBuilder) SelectCount(field string) *QueryBuilder
- func (q *QueryBuilder) SelectMax(field string) *QueryBuilder
- func (q *QueryBuilder) SelectMin(field string) *QueryBuilder
- func (q *QueryBuilder) Update(table interface{}, data Data) (sql.Result, error)
- func (q *QueryBuilder) UpdateContext(ctx context.Context, table interface{}, data Data) (sql.Result, error)
- func (q *QueryBuilder) Where(field string, value interface{}, comparison Comparison) *QueryBuilder
- func (q *QueryBuilder) WhereGroup(generator func(g *WhereGroup)) *QueryBuilder
- func (q *QueryBuilder) WhereIn(field string, values ...interface{}) *QueryBuilder
- func (q *QueryBuilder) WhereNotIn(field string, values ...interface{}) *QueryBuilder
- func (q *QueryBuilder) WhereRaw(raw string) *QueryBuilder
- type Raw
- type Result
- func (r *Result) Bytes(f string) ([]byte, error)
- func (r *Result) Date(f string) (time.Time, error)
- func (r *Result) Datetime(f string) (time.Time, error)
- func (r *Result) Float64(f string) (float64, error)
- func (r *Result) Int(f string) (int, error)
- func (r *Result) Int64(f string) (int64, error)
- func (r *Result) Map(dest interface{}) error
- func (r *Result) MarshalJSON() ([]byte, error)
- func (r *Result) MustBytes(f string) []byte
- func (r *Result) MustDate(f string) time.Time
- func (r *Result) MustDatetime(f string) time.Time
- func (r *Result) MustFloat64(f string) float64
- func (r *Result) MustInt(f string) int
- func (r *Result) MustInt64(f string) int64
- func (r *Result) MustString(f string) string
- func (r *Result) Nil(f string) bool
- func (r *Result) String(f string) (string, error)
- type Results
- type SQLiteCompat
- type SortMode
- type Time
- type WhereGroup
- func (w *WhereGroup) AddWhere(c ConditionBuilder) *WhereGroup
- func (w *WhereGroup) Build(binds []interface{}) (string, []interface{})
- func (w *WhereGroup) Combine() string
- func (w *WhereGroup) Like(field string, value interface{}) *WhereGroup
- func (w *WhereGroup) OrLike(field string, value interface{}) *WhereGroup
- func (w *WhereGroup) OrWhere(field string, value interface{}, comparison Comparison) *WhereGroup
- func (w *WhereGroup) OrWhereIn(field string, values ...interface{}) *WhereGroup
- func (w *WhereGroup) OrWhereRaw(raw string) *WhereGroup
- func (w *WhereGroup) Where(field string, value interface{}, comparison Comparison) *WhereGroup
- func (w *WhereGroup) WhereIn(field string, values ...interface{}) *WhereGroup
- func (w *WhereGroup) WhereRaw(raw string) *WhereGroup
Constants ¶
const ( // Equal compares equavbalence between column and value Equal Comparison = "=" // Alias for Equal Eq Comparison = "=" // NotEqual compares not equavbalence between column and value NotEqual Comparison = "<>" // Alias for NotEqual NotEq Comparison = "<>" // Gt compares greater than between column and value Gt Comparison = ">" // Gte compares greater than equal between column and value Gte Comparison = "<=" // Lt compares less than between column and value Lt Comparison = "<" // Lte compares less than equal between column and value Lte Comparison = "<=" // In compares within values In Comparison = "IN" // NotIn compares whithout values NotIn Comparison = "NOT IN" // Like compares value matching phrase Like Comparison = "LIKE" // Like compares value not matching phrase NotLike Comparison = "NOT LIKE" // Desc indicates decendant Desc SortMode = "DESC" // Asc indicates ascendant Asc SortMode = "ASC" // Rand indicates random Rand SortMode = "RAND" // And concats conditions with AND And CombineType = "AND" // Or concats conditions with OR Or CombineType = "OR" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CombineType ¶
type CombineType string
combine type indicates how to concat multiple WHERE conditions. This type is used for WHERE and private type
type Comparison ¶
type Comparison string
Comparison type indicates how to compare between column and value. This type is used for WHERE.
type ConditionBuilder ¶
type ConditionBuilder interface { // buildCondition() builds WHERE condition string and append bind parameters. Build([]interface{}) (string, []interface{}) // getCombine() should return concatenation string AND/OR Combine() string }
conditionBuilder is private interface with create WHERE condition string.
type Data ¶
type Data map[string]interface{}
Data type is used for INSERT/UPDATE data definition. This is suger syntax for map[string]interface{}, but always fields are sorted by key.
type Date ¶
Date format for column types. This type corresponds to "DATE" column on mysql, "date" column on postgres.
type Datetime ¶
Datetime format for column types This type corresponds to "DATETIME" on mysql, "timestamp" on postgres.
type Executor ¶
type Executor interface { QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) ExecContext(context.Context, string, ...interface{}) (sql.Result, error) }
SQL executor interface, this is enough to implement QueryContext() and ExecContext(). It's useful for running query in transation or not, because Executor accepts both of *sql.DB and *sql.Tx.
type Join ¶
type Join struct {
// contains filtered or unexported fields
}
Join is struct for making JOIN phrase
type MysqlCompat ¶
type MysqlCompat struct { }
func (MysqlCompat) PlaceHolder ¶
func (c MysqlCompat) PlaceHolder(index int) string
func (MysqlCompat) Quote ¶
func (c MysqlCompat) Quote(str string) string
func (MysqlCompat) RandFunc ¶
func (c MysqlCompat) RandFunc() string
type Order ¶
type Order struct {
// contains filtered or unexported fields
}
Order is struct for making ORDER BY phrase
type PostgresCompat ¶
type PostgresCompat struct { }
func (PostgresCompat) PlaceHolder ¶
func (c PostgresCompat) PlaceHolder(index int) string
func (PostgresCompat) Quote ¶
func (c PostgresCompat) Quote(str string) string
func (PostgresCompat) RandFunc ¶
func (c PostgresCompat) RandFunc() string
type QueryBuilder ¶
type QueryBuilder struct {
// contains filtered or unexported fields
}
QueryBuilder is struct for stack some conditions, orders, ... with method chain.
func (*QueryBuilder) AddWhere ¶
func (q *QueryBuilder) AddWhere(c ConditionBuilder) *QueryBuilder
Add condition
func (*QueryBuilder) BulkInsert ¶
func (q *QueryBuilder) BulkInsert(table interface{}, data []Data) (sql.Result, error)
Execute bulk INSERT query
func (*QueryBuilder) BulkInsertContext ¶
func (q *QueryBuilder) BulkInsertContext(ctx context.Context, table interface{}, data []Data) (sql.Result, error)
Execute bulk INSERT query with context
func (*QueryBuilder) Delete ¶
func (q *QueryBuilder) Delete(table interface{}) (sql.Result, error)
Execute DELETE query
func (*QueryBuilder) DeleteContext ¶
Execute DELETE query with context
func (*QueryBuilder) Get ¶
func (q *QueryBuilder) Get(table interface{}) (Results, error)
Execute query and get results
func (*QueryBuilder) GetContext ¶
func (q *QueryBuilder) GetContext(ctx context.Context, table interface{}) (Results, error)
Execute query and get results with context
func (*QueryBuilder) GetOne ¶
func (q *QueryBuilder) GetOne(table interface{}) (*Result, error)
Execute query and get first result
func (*QueryBuilder) GetOneContext ¶
func (q *QueryBuilder) GetOneContext(ctx context.Context, table interface{}) (*Result, error)
Execute query and get first result with context
func (*QueryBuilder) GroupBy ¶
func (q *QueryBuilder) GroupBy(fields ...string) *QueryBuilder
Add GROUP BY clause
func (*QueryBuilder) Insert ¶
func (q *QueryBuilder) Insert(table interface{}, data Data) (sql.Result, error)
Execute INSERT query
func (*QueryBuilder) InsertContext ¶
func (q *QueryBuilder) InsertContext(ctx context.Context, table interface{}, data Data) (sql.Result, error)
Execute INSERT query with context
func (*QueryBuilder) Join ¶
func (q *QueryBuilder) Join(table, from, to string, c Comparison) *QueryBuilder
Add JOIN table with condition
func (*QueryBuilder) Like ¶
func (q *QueryBuilder) Like(field string, value interface{}) *QueryBuilder
Add LIKE condition with AND combination
func (*QueryBuilder) Limit ¶
func (q *QueryBuilder) Limit(limit int64) *QueryBuilder
Set LIMIT field
func (*QueryBuilder) NotLike ¶
func (q *QueryBuilder) NotLike(field string, value interface{}) *QueryBuilder
Add NOT LIKE condition with AND combination
func (*QueryBuilder) Offset ¶
func (q *QueryBuilder) Offset(offset int64) *QueryBuilder
Set OFFSET field
func (*QueryBuilder) OrLike ¶
func (q *QueryBuilder) OrLike(field string, value interface{}) *QueryBuilder
Add LIKE condition with OR combination
func (*QueryBuilder) OrNotLike ¶
func (q *QueryBuilder) OrNotLike(field string, value interface{}) *QueryBuilder
Add NOT LIKE condition with OR combination
func (*QueryBuilder) OrWhere ¶
func (q *QueryBuilder) OrWhere(field string, value interface{}, comparison Comparison) *QueryBuilder
Add condition with OR combination
func (*QueryBuilder) OrWhereGroup ¶
func (q *QueryBuilder) OrWhereGroup(generator func(g *WhereGroup)) *QueryBuilder
Add WHERE condition group with OR. The first argument is generator function which accepts *ConditionGroup as argument. After call the generator function, add WHERE stack with called state
func (*QueryBuilder) OrWhereIn ¶
func (q *QueryBuilder) OrWhereIn(field string, values ...interface{}) *QueryBuilder
Add IN condition with OR combination
func (*QueryBuilder) OrWhereNotIn ¶
func (q *QueryBuilder) OrWhereNotIn(field string, values ...interface{}) *QueryBuilder
Add NOT IN condition with OR combination
func (*QueryBuilder) OrWhereRaw ¶
func (q *QueryBuilder) OrWhereRaw(raw string) *QueryBuilder
Add user specific raw condition with OR combination
func (*QueryBuilder) OrderBy ¶
func (q *QueryBuilder) OrderBy(field string, sort SortMode) *QueryBuilder
Add ORDER BY cluase
func (*QueryBuilder) Select ¶
func (q *QueryBuilder) Select(fields ...interface{}) *QueryBuilder
Add SELECT fields
func (*QueryBuilder) SelectAvg ¶
func (q *QueryBuilder) SelectAvg(field string) *QueryBuilder
Add SELECT AVG fields
func (*QueryBuilder) SelectCount ¶
func (q *QueryBuilder) SelectCount(field string) *QueryBuilder
Add SELECT COUNT fields
func (*QueryBuilder) SelectMax ¶
func (q *QueryBuilder) SelectMax(field string) *QueryBuilder
Add SELECT MAX fields
func (*QueryBuilder) SelectMin ¶
func (q *QueryBuilder) SelectMin(field string) *QueryBuilder
Add SELECT MIN fields
func (*QueryBuilder) Update ¶
func (q *QueryBuilder) Update(table interface{}, data Data) (sql.Result, error)
Execute UPDATE query
func (*QueryBuilder) UpdateContext ¶
func (q *QueryBuilder) UpdateContext(ctx context.Context, table interface{}, data Data) (sql.Result, error)
Execute UPDATE query with context
func (*QueryBuilder) Where ¶
func (q *QueryBuilder) Where(field string, value interface{}, comparison Comparison) *QueryBuilder
Add condition with AND combination
func (*QueryBuilder) WhereGroup ¶
func (q *QueryBuilder) WhereGroup(generator func(g *WhereGroup)) *QueryBuilder
Add WHERE condition group with AND. The first argument is generator function which accepts *ConditionGroup as argument. After call the generator function, add WHERE stack with called state
func (*QueryBuilder) WhereIn ¶
func (q *QueryBuilder) WhereIn(field string, values ...interface{}) *QueryBuilder
Add IN condition with AND combination
func (*QueryBuilder) WhereNotIn ¶
func (q *QueryBuilder) WhereNotIn(field string, values ...interface{}) *QueryBuilder
Add NOT IN condition with AND combination
func (*QueryBuilder) WhereRaw ¶
func (q *QueryBuilder) WhereRaw(raw string) *QueryBuilder
Add user specific raw condition with AND combination
type Raw ¶
type Raw string
Raw type indicates "raw query phrase", it means gqb won't quote any string, columns. You should tableke carefully when use this type, but it's useful for use function like "COUNT(*)".
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result is struct for SELECT query result mapper
func (*Result) Date ¶
Get field value as time.Time with caring type conversion, time parsing. The value must be and date format string
func (*Result) Datetime ¶
Get field value as time.Time with caring type conversion, time parsing. The value must be and dateitme format string
func (*Result) MarshalJSON ¶
json.Marshaller interface implementation
func (*Result) MustDatetime ¶
Force get field value as time.Time with datetime format
func (*Result) MustFloat64 ¶
Force get field value as float64
func (*Result) MustString ¶
Force get field value as string
type SQLiteCompat ¶
type SQLiteCompat struct { }
func (SQLiteCompat) PlaceHolder ¶
func (c SQLiteCompat) PlaceHolder(index int) string
func (SQLiteCompat) Quote ¶
func (c SQLiteCompat) Quote(str string) string
func (SQLiteCompat) RandFunc ¶
func (c SQLiteCompat) RandFunc() string
type SortMode ¶
type SortMode string
SortMode type indicates how to sort records. This type is used for ORDER BY
type WhereGroup ¶
type WhereGroup struct {
// contains filtered or unexported fields
}
WhereGroup is struct which wraps multiple Condition struct. This struct also implement ConditionBuilder inteface, so we can treat as same as Condition struct. This is used for grouped condition like "SELECT * FROM example WHERE A = 1 AND (B = 2 AND C = 3)" Parentheses inside condition is made by ConditionGroup
func (*WhereGroup) AddWhere ¶
func (w *WhereGroup) AddWhere(c ConditionBuilder) *WhereGroup
Add condition
func (*WhereGroup) Build ¶
func (w *WhereGroup) Build(binds []interface{}) (string, []interface{})
ConditionBuilder::Build() interface implementation
func (*WhereGroup) Combine ¶
func (w *WhereGroup) Combine() string
ConditionBuilder::Combine() interface implementation
func (*WhereGroup) Like ¶
func (w *WhereGroup) Like(field string, value interface{}) *WhereGroup
Add LIKE condition with AND combination
func (*WhereGroup) OrLike ¶
func (w *WhereGroup) OrLike(field string, value interface{}) *WhereGroup
Add LIKE condition with OR combination
func (*WhereGroup) OrWhere ¶
func (w *WhereGroup) OrWhere(field string, value interface{}, comparison Comparison) *WhereGroup
Add condition with OR combination
func (*WhereGroup) OrWhereIn ¶
func (w *WhereGroup) OrWhereIn(field string, values ...interface{}) *WhereGroup
Add IN condition with OR combination
func (*WhereGroup) OrWhereRaw ¶
func (w *WhereGroup) OrWhereRaw(raw string) *WhereGroup
Add user specific raw condition with OR combination
func (*WhereGroup) Where ¶
func (w *WhereGroup) Where(field string, value interface{}, comparison Comparison) *WhereGroup
Add condition with AND combination
func (*WhereGroup) WhereIn ¶
func (w *WhereGroup) WhereIn(field string, values ...interface{}) *WhereGroup
Add IN condition with AND combination
func (*WhereGroup) WhereRaw ¶
func (w *WhereGroup) WhereRaw(raw string) *WhereGroup
Add user specific raw condition with AND combination