Documentation ¶
Index ¶
- func AllField(ti TableRecordInterface) string
- func Delete(ti TableRecordInterface) (int64, error)
- func FetchSingleRow(tri TableRecordInterface, query string, params ...interface{}) error
- func GetFieldMapper(ti TableRecordInterface) (fieldsName []string, fieldsValue []interface{})
- func GetPrimaryKeyValue(ti TableRecordInterface) interface{}
- func LoadByID(ti TableRecordInterface, id interface{}) error
- func LoadFromRow(r *sqlx.Rows, tri TableRecordInterface) error
- func Save(ti TableRecordInterface) error
- type NewTableModel
- type TableRecord
- func (t *TableRecord) DriverName() string
- func (t *TableRecord) GetDB() db.SQLConnector
- func (t *TableRecord) IsLoaded() bool
- func (t *TableRecord) IsNew() bool
- func (t *TableRecord) PrepareStmt(tableName string) (*sqlx.Stmt, error)
- func (t *TableRecord) SetIsNew(new bool) *TableRecord
- func (t *TableRecord) SetSQLConnection(db db.SQLConnector) *TableRecord
- type TableRecordInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
func Delete(ti TableRecordInterface) (int64, error)
Delete - Deletes the model from database
func FetchSingleRow ¶
func FetchSingleRow(tri TableRecordInterface, query string, params ...interface{}) error
FetchSingleRow - Execs the query and retrieves only the first result
func GetFieldMapper ¶
func GetFieldMapper(ti TableRecordInterface) (fieldsName []string, fieldsValue []interface{})
GetFieldMapper - Returns a slice of table name fields and a slice of struct field ptr
func GetPrimaryKeyValue ¶
func GetPrimaryKeyValue(ti TableRecordInterface) interface{}
GetPrimaryKeyValue - Returs the primary key value
func LoadByID ¶
func LoadByID(ti TableRecordInterface, id interface{}) error
LoadByID - Loads the model passed by primary key value
func LoadFromRow ¶
func LoadFromRow(r *sqlx.Rows, tri TableRecordInterface) error
LoadFromRow - Loads the passed TableRecordInterface with the row sql result
func Save ¶
func Save(ti TableRecordInterface) error
Save - Saves the model to the database, if the model is "new" inserts a new one otherwise update the record
Types ¶
type NewTableModel ¶
type NewTableModel func() TableRecordInterface
NewTableModel - Defines a func that return a TableRecordInterface
type TableRecord ¶
TableRecord - Common struct to access all utility func with TableRecordInterface implements QueryBuilderInterface
func NewTableRecord ¶
func NewTableRecord(isNew bool, isReadOnly bool) *TableRecord
NewTableRecord - Returns a new instance of TableRecord
func (*TableRecord) DriverName ¶
func (t *TableRecord) DriverName() string
DriverName - Returns the sql driver name for TableRecord's instance
func (*TableRecord) GetDB ¶
func (t *TableRecord) GetDB() db.SQLConnector
GetDB - Returns TableRecord db resource instance
func (*TableRecord) IsLoaded ¶
func (t *TableRecord) IsLoaded() bool
IsLoaded - Returns if TableRecord is loaded successfully, might useful after a LoadByID or similar func
func (*TableRecord) PrepareStmt ¶
func (t *TableRecord) PrepareStmt(tableName string) (*sqlx.Stmt, error)
PrepareStmt - Returns the query stmt built with QueryBuilder
func (*TableRecord) SetIsNew ¶
func (t *TableRecord) SetIsNew(new bool) *TableRecord
SetIsNew - Sets isNew field
func (*TableRecord) SetSQLConnection ¶
func (t *TableRecord) SetSQLConnection(db db.SQLConnector) *TableRecord
SetSQLConnection - Sets the db resource instance
type TableRecordInterface ¶
type TableRecordInterface interface { GetTableRecord() *TableRecord GetPrimaryKeyName() string GetTableName() string }
TableRecordInterface - Defines a generics struct to interact with database
func All ¶
func All(ntm NewTableModel) ([]TableRecordInterface, error)
All - Returns all models from database, requires a func constructor that return a TableRecordInterface
func ExecQuery ¶
func ExecQuery(ti TableRecordInterface, ntm NewTableModel) ([]TableRecordInterface, error)
ExecQuery - Execs the query built with QueryBuilder