Documentation ¶
Index ¶
- Variables
- func CloseDatabase() error
- func Exec(sql string, args ...interface{}) (sql.Result, error)
- func ExecSQL(query string, args ...interface{}) (sql.Result, error)
- func OpenDatabase(opts map[string]string, mu *sync.RWMutex) error
- func QuerySQL(query string, args ...interface{}) (*sql.Rows, error)
- func Rows(sql string, args ...interface{}) (*sql.Rows, error)
- func SetMaxOpenConns(max int)
- func TimeString(t time.Time) string
- func ToCamel(text string, private ...bool) string
- func ToPlural(text string) (plural string)
- func ToSingular(word string) (singular string)
- func ToSnake(text string) string
- func Truncate(s string, length int) string
- func TruncateWithEllipsis(s string, length int, ellipsis string) string
- type Func
- type Query
- func (q *Query) Apply(f Func) *Query
- func (q *Query) Conditions(funcs ...Func) *Query
- func (q *Query) Copy() *Query
- func (q *Query) Count() (int64, error)
- func (q *Query) DebugString() string
- func (q *Query) Delete() error
- func (q *Query) DeleteAll() error
- func (q *Query) FirstResult() (Result, error)
- func (q *Query) Group(sql string) *Query
- func (q *Query) Having(sql string) *Query
- func (q *Query) Insert(params map[string]string) (int64, error)
- func (q *Query) InsertJoin(a int64, b int64) error
- func (q *Query) InsertJoins(a []int64, b []int64) error
- func (q *Query) Join(otherModel string) *Query
- func (q *Query) Limit(limit int) *Query
- func (q *Query) Offset(offset int) *Query
- func (q *Query) OrWhere(sql string, args ...interface{}) *Query
- func (q *Query) Order(sql string) *Query
- func (q *Query) QueryString() string
- func (q *Query) Result() (sql.Result, error)
- func (q *Query) ResultFloat64(c string) (float64, error)
- func (q *Query) ResultIDSets(a, b string) map[int64][]int64
- func (q *Query) ResultIDs() []int64
- func (q *Query) ResultInt64(c string) (int64, error)
- func (q *Query) Results() ([]Result, error)
- func (q *Query) Rows() (*sql.Rows, error)
- func (q *Query) SQL(sql string) *Query
- func (q *Query) Select(sql string) *Query
- func (q *Query) Update(params map[string]string) error
- func (q *Query) UpdateAll(params map[string]string) error
- func (q *Query) UpdateJoins(id int64, a []int64, b []int64) error
- func (q *Query) Where(sql string, args ...interface{}) *Query
- func (q *Query) WhereIn(col string, IDs []int64) *Query
- type Result
Constants ¶
This section is empty.
Variables ¶
var Debug bool
Debug sets whether we output debug statements for SQL
Functions ¶
func CloseDatabase ¶
func CloseDatabase() error
CloseDatabase closes the database opened by OpenDatabase
func Exec ¶
Exec the given sql and args against the database directly Returning sql.Result (NB not rows)
func ExecSQL ¶
ExecSQL executes the given sql against our database with arbitrary args NB returns sql.Result - not to be used when rows expected
func OpenDatabase ¶
OpenDatabase opens the database with the given options
func SetMaxOpenConns ¶
func SetMaxOpenConns(max int)
SetMaxOpenConns sets the maximum number of open connections
func TimeString ¶
TimeString returns a string formatted as a time for this db if the database is nil, an empty string is returned.
func ToCamel ¶
ToCamel converts a string from database column names to corresponding struct field names (e.g. field_name to FieldName).
func ToPlural ¶
ToPlural returns the plural version of an English word using some simple rules and a table of exceptions.
func ToSingular ¶
ToSingular converts a word to singular. NB reversal from plurals may fail
func ToSnake ¶
ToSnake converts a string from struct field names to corresponding database column names (e.g. FieldName to field_name).
Types ¶
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query provides all the chainable relational query builder methods
func (*Query) Apply ¶
Apply the Func to this query, and return the modified Query This allows chainable finders from other packages e.g. q.Apply(status.Published) where status.Published is a Func
func (*Query) Conditions ¶
Conditions applies a series of query funcs to a query
func (*Query) Copy ¶
Copy returns a new copy of this query which can be mutated without affecting the original
func (*Query) DebugString ¶
DebugString returns a query representation string useful for debugging
func (*Query) FirstResult ¶
FirstResult executes the SQL and returrns the first result
func (*Query) InsertJoin ¶
InsertJoin inserts a join clause on the query
func (*Query) InsertJoins ¶
InsertJoins using an array of ids (more general version of above) This inserts joins for every possible relation between the ids
func (*Query) OrWhere ¶
OrWhere defines a where clause on SQL - Additional calls add WHERE () OR () clauses
func (*Query) QueryString ¶
QueryString builds a query string to use for results
func (*Query) Result ¶
Result executes the query against the database, returning sql.Result, and error (no rows) (Executes SQL)
func (*Query) ResultFloat64 ¶
ResultFloat64 returns the first result from a query stored in the column named col as a float64.
func (*Query) ResultIDSets ¶
ResultIDSets returns a map from a values to arrays of b values, the order of a,b is respected not the table key order
func (*Query) ResultIDs ¶
ResultIDs returns an array of ids as the result of a query FIXME - this should really use the query primary key, not "id" hardcoded
func (*Query) ResultInt64 ¶
ResultInt64 returns the first result from a query stored in the column named col as an int64.
func (*Query) Rows ¶
Rows executes the query against the database, and return the sql rows result for this query (Executes SQL)
func (*Query) SQL ¶
SQL defines sql manually and overrides all other setters Completely replaces all stored sql
func (*Query) Update ¶
Update one model specified in this query - the column names MUST be verified in the model
func (*Query) UpdateJoins ¶
UpdateJoins updates the given joins, using the given id to clear joins first