Documentation
¶
Index ¶
- Constants
- type Action
- func (self *Action) GetActionName() string
- func (self *Action) GetIsDo(option ...string) bool
- func (self *Action) GetNextpages() []*Connection
- func (self *Action) GetPicked() []string
- func (self *Action) GetPrepares() []*Connection
- func (self *Action) SetActionName(name string)
- func (self *Action) SetIsDo(is bool)
- func (self *Action) SetNextpages(x []*Connection)
- func (self *Action) SetPicked(picked []string)
- func (self *Action) SetPrepares(x []*Connection)
- type Atom
- func (self *Atom) GetAction(actionName string) Capability
- func (self *Atom) MergeCustomActions(custom ...Capability)
- func (self *Atom) RunAtom(db *sql.DB, action string, ARGS interface{}, extra ...map[string]interface{}) ([]interface{}, error)
- func (self *Atom) RunAtomContext(ctx context.Context, db *sql.DB, action string, ARGS interface{}, ...) ([]interface{}, error)
- func (self *Atom) UnmarshalHCL(bs []byte, labels ...string) error
- func (self *Atom) UnmarshalJSON(bs []byte) error
- type Capability
- type Col
- type ConnectType
- type Connection
- type DBI
- func (self *DBI) DoSQL(query string, args ...interface{}) error
- func (self *DBI) DoSQLContext(ctx context.Context, query string, args ...interface{}) error
- func (self *DBI) DoSQLs(query string, args ...[]interface{}) error
- func (self *DBI) DoSQLsContext(ctx context.Context, query string, args ...[]interface{}) error
- func (self *DBI) GetSQL(res map[string]interface{}, query string, labels []interface{}, ...) error
- func (self *DBI) GetSQLContext(ctx context.Context, res map[string]interface{}, query string, ...) error
- func (self *DBI) InsertID(query string, args ...interface{}) error
- func (self *DBI) InsertIDContext(ctx context.Context, query string, args ...interface{}) error
- func (self *DBI) InsertSerial(query string, args ...interface{}) error
- func (self *DBI) InsertSerialContext(ctx context.Context, query string, args ...interface{}) error
- func (self *DBI) Select(lists *[]interface{}, query string, args ...interface{}) error
- func (self *DBI) SelectContext(ctx context.Context, lists *[]interface{}, query string, args ...interface{}) error
- func (self *DBI) SelectSQL(lists *[]interface{}, query string, labels []interface{}, args ...interface{}) error
- func (self *DBI) SelectSQLContext(ctx context.Context, lists *[]interface{}, query string, labels []interface{}, ...) error
- func (self *DBI) TxSQL(query string, args ...interface{}) error
- func (self *DBI) TxSQLContext(ctx context.Context, query string, args ...interface{}) error
- type DBType
- type Delecs
- type Delete
- type Edit
- type Fk
- type Insert
- type Insupd
- type Joint
- type Molecule
- type PreStopper
- type Stmt
- type StmtContext
- type Stopper
- type Table
- type Topics
- type Update
Constants ¶
const (
STMT = "stmt"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { ActionName string `json:"actionName,omitempty" hcl:"actionName,label"` Picked []string `json:"picked,omitempty" hcl:"picked,optional"` Prepares []*Connection `json:"prepares,omitempty" hcl:"prepares,block"` Nextpages []*Connection `json:"nextpages,omitempty" hcl:"nextpages,block"` // contains filtered or unexported fields }
Action is the base struct for REST actions. Prepares and Nextpages are edges to other tables before and after the action.
func (*Action) GetActionName ¶
GetActionName gets the action name
func (*Action) GetNextpages ¶
func (self *Action) GetNextpages() []*Connection
GetNextpages gets the nextpages
func (*Action) GetPrepares ¶
func (self *Action) GetPrepares() []*Connection
GetPrepares gets the prepares
func (*Action) SetActionName ¶ added in v1.3.0
SetActionName sets the action name
func (*Action) SetNextpages ¶
func (self *Action) SetNextpages(x []*Connection)
SetNextpages sets the nextpages
func (*Action) SetPrepares ¶
func (self *Action) SetPrepares(x []*Connection)
SetPrepares sets the prepares
type Atom ¶
type Atom struct { AtomName string `json:"atomName,omitempty" hcl:"atomName,label"` Table Actions []Capability `json:"actions,omitempty" hcl:"actions,block"` // contains filtered or unexported fields }
Atom is a table with multiple actions
func (*Atom) GetAction ¶
func (self *Atom) GetAction(actionName string) Capability
GetAction gets a specific action by name
func (*Atom) MergeCustomActions ¶ added in v1.3.0
func (self *Atom) MergeCustomActions(custom ...Capability)
MergeCustomActions merges custom actions
func (*Atom) RunAtom ¶
func (self *Atom) RunAtom(db *sql.DB, action string, ARGS interface{}, extra ...map[string]interface{}) ([]interface{}, error)
RunAtom runs an action by name
func (*Atom) RunAtomContext ¶
func (self *Atom) RunAtomContext(ctx context.Context, db *sql.DB, action string, ARGS interface{}, extra ...map[string]interface{}) ([]interface{}, error)
RunAtom runs an action with context by name
func (*Atom) UnmarshalHCL ¶ added in v1.3.0
Atom is a HCL unmarshaler
func (*Atom) UnmarshalJSON ¶ added in v1.0.4
Atom is a JSON unmarshaler
type Capability ¶
type Capability interface { GetActionName() string SetActionName(string) GetPrepares() []*Connection GetNextpages() []*Connection GetIsDo(...string) bool SetIsDo(bool) SetPrepares([]*Connection) SetNextpages([]*Connection) GetPicked() []string SetPicked([]string) // RunActionContext runs the action with context, db, table, and args RunActionContext(context.Context, *sql.DB, *Table, map[string]interface{}, ...map[string]interface{}) ([]interface{}, error) }
Action is to implement Capability interface
type Col ¶
type Col struct { ColumnName string `json:"columnName" hcl:"columnName,label"` TypeName string `json:"typeName" hcl:"typeName,optional"` Label string `json:"label" hcl:"columnLabel,optional"` Notnull bool `json:"notnull,omitempty" hcl:"notnull,optional"` Constraint bool `json:"constraint,omitempty" hcl:"constraint,optional"` Auto bool `json:"auto,omitempty" hcl:"auto,optional"` // true for a one-to-may recurse column Recurse bool `json:"recurse,omitempty" hcl:"recurse,optional"` }
Col defines table column in GO struct
type ConnectType ¶
type ConnectType int
const ( CONNECTDefault ConnectType = iota CONNECTOne CONNECTArray CONNECTMap CONNECTMany )
type Connection ¶
type Connection struct { // AtomName: the name of the table AtomName string `json:"atomName" hcl:"atomName,label"` // ActionName: the action on the atom ActionName string `json:"actionName" hcl:"actionName,label"` // RelateArgs: map current page's columns to nextpage's columns as input RelateArgs map[string]string `json:"relateArgs,omitempty" hcl:"relateArgs,optional"` // RelateExtra: map current page's columns to nextpage's columns (for Nextpages), or prepared page's columns to current page's columns (for Prepares) as constrains. RelateExtra map[string]string `json:"relateExtra,omitempty" hcl:"relateExtra,optional"` // Dimension: for nextpage's output format Dimension ConnectType `json:"dimension,omitempty" hcl:"dimension,optional"` // Marker: for input data, this marks a whole data set for the next or previous object; for output data, this is the key for the next whole data set. Marker string `json:"marker,omitempty" hcl:"marker,optional"` }
Connection describes linked page 1) for Nextpages, it maps item in lists to next ARGS and next Extra 2) for Prepares, it maps current ARGS to the next ARGS and next Extra
func (*Connection) Subname ¶
func (self *Connection) Subname() string
Subname is the marker string used to store the output
type DBI ¶
type DBI struct { // Embedding the generic database handle. *sql.DB // LastID: the last auto id inserted, if the database provides LastID int64 }
DBI embeds GO's generic SQL handler and adds few functions for database executions and queries.
func (*DBI) DoSQLContext ¶
DoSQLContext executes a SQL the same as DB's Exec, only save the last inserted ID
func (*DBI) DoSQLs ¶
DoSQLs executes multiple rows using the same prepared statement, The rows are expressed as a slice of slices.
func (*DBI) DoSQLsContext ¶
DoSQLsContext executes multiple rows using the same prepared statement, The rows are expressed as a slice of slices.
func (*DBI) GetSQL ¶
func (self *DBI) GetSQL(res map[string]interface{}, query string, labels []interface{}, args ...interface{}) error
GetSQL returns single row 'res'.
func (*DBI) GetSQLContext ¶
func (self *DBI) GetSQLContext(ctx context.Context, res map[string]interface{}, query string, labels []interface{}, args ...interface{}) error
GetSQLContext returns single row 'res'.
func (*DBI) InsertID ¶
InsertID executes a SQL the same as DB's Exec, only save the last inserted ID
func (*DBI) InsertIDContext ¶
InsertIDContext executes a SQL the same as DB's Exec, only save the last inserted ID
func (*DBI) InsertSerial ¶
InsertSerial insert a SQL row into Postgres table with Serail , only save the last inserted ID
func (*DBI) InsertSerialContext ¶
InsertSerialContext insert a SQL into Postgres table with Serial, only save the last inserted ID
func (*DBI) Select ¶
Select returns queried data 'list' as a slice of maps, whose data types are determined dynamically by the generic handle.
func (*DBI) SelectContext ¶
func (self *DBI) SelectContext(ctx context.Context, lists *[]interface{}, query string, args ...interface{}) error
SelectContext returns queried data 'lists' as a slice of maps, whose data types are determined dynamically by the generic handle.
func (*DBI) SelectSQL ¶
func (self *DBI) SelectSQL(lists *[]interface{}, query string, labels []interface{}, args ...interface{}) error
SelectSQL returns queried data 'list' as a slice of maps. The map keys and their data types are pre-defined in 'labels', expressed as a slice of interfaces:
- when an interface is a string, this is the key name. The data types are determined dynamically by the generic handler.
- when an interface is a 2-string slice, the first element is the key and the second the data type in "int64", "int", "string" etc.
func (*DBI) SelectSQLContext ¶
func (self *DBI) SelectSQLContext(ctx context.Context, lists *[]interface{}, query string, labels []interface{}, args ...interface{}) error
SelectSQL returns queried data 'list' as a slice of maps. The map keys and their data types are pre-defined in 'labels', expressed as a slice of interfaces:
- when an interface is a string, this is the key name. The data types are determined dynamically by the generic handler.
- when an interface is a 2-string slice, the first element is the key and the second the data type in "int64", "int", "string" etc.
type Delecs ¶
type Delecs struct {
Action
}
Delecs is a special Topics action that returns all foreign keys
func (*Delecs) RunActionContext ¶
func (self *Delecs) RunActionContext(ctx context.Context, db *sql.DB, t *Table, ARGS map[string]interface{}, extra ...map[string]interface{}) ([]interface{}, error)
RunActionContext of Delecs is to populate Fks before making delete, so that Fks could be passed to other Prepared delete actions. If there is no Fks, we putput the input, then Delecs does nothing.
type Delete ¶
type Delete struct {
Action
}
Delete struct for row deletion by primary key
type Fk ¶
type Fk struct { // the parent table name FkTable string `json:"fkTable" hcl:"fkTable,optional"` // the parant table column FkColumn string `json:"fkColumn" hcl:"fkColumn,optional"` // column of this table Column string `json:"column" hcl:"column,optional"` }
Fk defines foreign key struct
type Insert ¶
type Insert struct {
Action
}
Insert struct for table insert
type Insupd ¶
type Insupd struct {
Action
}
Insupd struct for table update, if not existing according to the unique key, do insert
type Joint ¶
type Joint struct { TableName string `json:"tableName" hcl:"tableName,label"` Alias string `json:"alias,omitempty" hcl:"alias,optional"` JoinType string `json:"type,omitempty" hcl:"type,optional"` JoinUsing string `json:"using,omitempty" hcl:"using,optional"` JoinOn string `json:"on,omitempty" hcl:"on,optional"` Sortby string `json:"sortby,omitempty" hcl:"sortby,optional"` }
Joint struct describes the joined search
type Molecule ¶
type Molecule struct { Atoms []*Atom `json:"atoms" hcl:"atoms,block"` DBDriver DBType `json:"dbDriver" hcl:"dbDriver,optional"` Stopper PreStopper // contains filtered or unexported fields }
Molecule describes all atoms and actions in a database schema
func (*Molecule) Initialize ¶
Initialize initializes molecule with args and extra args is the input data, shared by all sub actions. extra is specific data list for sub actions, starting with the current one.
func (*Molecule) RunContext ¶
func (self *Molecule) RunContext(ctx context.Context, db *sql.DB, atom, action string, rest ...interface{}) ([]interface{}, error)
RunContext runs action by atom and action string names. It returns the searched data and optional error code. atom is the atom name, and action the action name. rest are:
- the input data, shared by all sub actions.
- specific data list for sub actions, starting with the current one.
type PreStopper ¶ added in v1.3.0
type Stmt ¶ added in v1.3.0
type Stmt struct { Action StmtContext Others map[string]*StmtContext `json:"others,omitempty" hcl:"others,block"` }
Stmt struct for search one specific row by primary key
type StmtContext ¶ added in v1.3.0
type Stopper ¶ added in v1.0.3
type Stopper interface { PreStopper Sign(tableObj *Table, item map[string]interface{}) }
type Table ¶
type Table struct { TableName string `json:"tableName" hcl:"tableName,optional"` Columns []*Col `json:"columns" hcl:"columns,block"` Pks []string `json:"pks,omitempty" hcl:"pks,optional"` IdAuto string `json:"idAuto,omitempty" hcl:"idAuto,optional"` Fks []*Fk `json:"fks,omitempty" hcl:"fks,block"` Uniques []string `json:"uniques,omitempty" hcl:"uniques,optional"` // contains filtered or unexported fields }
Table defines a table by name, columns, primary key, foreign keys, auto id and unique columns
func (*Table) IsRecursive ¶
IsRecursive indicates if table references to itself in one to multiple relations
func (*Table) RecursiveColumn ¶
RecursiveColumn returns the name of the resursive column
func (*Table) SetDBDriver ¶
SetDBDriver sets the driver type
type Topics ¶
type Topics struct { Action FIELDS string `json:"fields,omitempty" hcl:"fields,optional"` Totalforce int `json:"totalforce,omitempty" hcl:"totalforce,optional"` MAXPAGENO string `json:"maxpageno,omitempty" hcl:"maxpageno,optional"` TOTALNO string `json:"totalno,omitempty" hcl:"totalno,optional"` PAGESIZE string `json:"pagesize,omitempty" hcl:"pagesize,optional"` PAGENO string `json:"pageno,omitempty" hcl:"pageno,optional"` SORTBY string `json:"sortby,omitempty" hcl:"sortby,optional"` SORTREVERSE string `json:"sortreverse,omitempty" hcl:"sortreverse,optional"` }
Topics struct for search multiple rows by constraints