Documentation ¶
Overview ¶
Package db is a db wrapper
Index ¶
- Variables
- type Config
- type Db
- func (db *Db) Close()
- func (db *Db) Delete(options SearchOptions) (err error)
- func (db *Db) DeleteAll(table string) (err error)
- func (db *Db) DeleteByCol(column, columnValue, table string) (err error)
- func (db *Db) DeleteByID(id uuid.UUID, table string) (err error)
- func (db *Db) Update(id uuid.UUID, table string, updates interface{}) (data []map[string]interface{}, err error)
- type SearchOptions
Constants ¶
This section is empty.
Variables ¶
var ( AutoParam = map[string]bool{ "created": true, } SkipParam = map[string]bool{ "post_results": true, "pre_results": true, } TimeParam = map[string]bool{ "created": true, "logged_in": true, "expires_after": true, "time": true, } )
AutoParam are parameters that are created automatically SkipParam are parameters that are supposed to be skipped over TimeParams are parameters of type time.Time
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Host string Port string User string Password string Database string URL string }
Config is a database configuration
type Db ¶
Db contains the database connection pool and its config
func (*Db) Delete ¶
func (db *Db) Delete(options SearchOptions) (err error)
Delete attempts to provide a generalized search through the specified table based on the provided queries. It takes a query for the queryable fields, and an operator such as "AND" or "OR" to define the context of the search. It takes in a table name to act on. It returns all the data for all found objects and an error if one exists.
func (*Db) DeleteAll ¶
DeleteAll permanently removes all objects from the table. It takes in a string representing the table name. It returns an error if one exists.
func (*Db) DeleteByCol ¶
DeleteByCol removes the one row from table where column=columnValue
func (*Db) DeleteByID ¶
DeleteByID removes one row from table where id=id
func (*Db) Update ¶
func (db *Db) Update(id uuid.UUID, table string, updates interface{}) (data []map[string]interface{}, err error)
Update updates the model row(s) in the table based on the incoming object. It takes in an id to identify the object in the DB, a string representing the table name and the fileds to update the object on. It returns the data representing an updated model.
type SearchOptions ¶
type SearchOptions struct { Query interface{} // The query to use Op string // AND / OR CompareOp string // The comparison operator to use (default =) TableName string // Name of table to query from Order string // ASC or DESC OrderQuery string // Columns to order by Limit int64 // Number of rows to select }
SearchOptions is a list of options to call db.Get with