Documentation ¶
Overview ¶
Package dbobj provides a simple ORM-like framework for SQLite and derivatives
Index ¶
- Variables
- func Placeholders(n int) string
- type Common
- type DBList
- type DBObject
- type DBS
- type DBU
- func (du *DBU) Add(o DBObject) error
- func (du *DBU) Close()
- func (du *DBU) DB() *sql.DB
- func (du *DBU) Delete(o DBObject) error
- func (du *DBU) DeleteByID(o DBObject, id interface{}) error
- func (du *DBU) Exec(query string, args ...interface{}) (rowsAffected, lastInsertID int64, err error)
- func (du *DBU) Find(o DBObject, keys map[string]interface{}) error
- func (du *DBU) FindBy(o DBObject, key string, value interface{}) error
- func (du *DBU) FindByID(o DBObject, value interface{}) error
- func (du *DBU) FindSelf(o DBObject) error
- func (du *DBU) InsertMany(query string, args ...[]interface{}) error
- func (du *DBU) List(list DBList) error
- func (du *DBU) ListQuery(list DBList, extra string) error
- func (du *DBU) MakeList(h ListHandler, query string, args ...interface{}) error
- func (du *DBU) Query(fn SetHandler, query string, args ...interface{}) error
- func (du *DBU) Replace(o DBObject) error
- func (du *DBU) Save(o DBObject) error
- func (du *DBU) SetLogger(logger *log.Logger)
- type ListHandler
- type SQLDB
- type SetHandler
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrNoKeyField is returned for tables without primary key identified ErrNoKeyField = errors.New("table has no key field") // ErrKeyMissing is returned when key value is not set ErrKeyMissing = errors.New("key is not set") // ErrNilWritePointers is returned when a list handler returns a nil slice ErrNilWritePointers = errors.New("nil record dest members") )
Functions ¶
func Placeholders ¶ added in v0.0.3
Placeholders returns SQLite values placeholders
Types ¶
type DBObject ¶
type DBObject interface { // TableName is the name of the sql table TableName() string // KeyFields are the names of the table fields // comprising the primary id //KeyFields() []string KeyField() string // KeyNames are the struct names of the // primary id fields //KeyNames() []string KeyName() string // Names returns the struct element names Names() []string // SelectFields returns the comma separated // list of fields to be selected SelectFields() string // InsertFields returns the comma separated // list of fields to be selected InsertFields() string // Key returns the int64 id value of the object Key() int64 // SetID updates the id of the object SetID(int64) // InsertValues returns the values of the object to be inserted InsertValues() []interface{} // UpdateValues returns the values of the object to be updated UpdateValues() []interface{} // MemberPointers returns a slice of pointers to values // for the db scan function MemberPointers() []interface{} // ModifiedBy returns the user id and timestamp of when the object was last modified ModifiedBy(int64, time.Time) }
DBObject provides methods for object storage The functions are generated for each object annotated accordingly
type DBS ¶
type DBS interface { // Query takes a SetHandler, which returns a slice of pointers to the members of a struct // It is incumbant upon the caller to build a slice and pass receivers to build a list Query(fn SetHandler, query string, args ...interface{}) error // Exec models the standard Golang exec but with direct values returned Exec(query string, args ...interface{}) (RowsAffected, LastInsertID int64, err error) }
DBS is an abstracted database interface, intended to work with both rqlite and regular sql.DB connections
type DBU ¶
type DBU struct {
// contains filtered or unexported fields
}
DBU is a DataBaseUnit
func (*DBU) DeleteByID ¶
DeleteByID object from datastore by id
func (*DBU) InsertMany ¶ added in v0.0.2
InsertMany inserts multiple records as a single transaction
func (*DBU) MakeList ¶ added in v0.0.7
func (du *DBU) MakeList(h ListHandler, query string, args ...interface{}) error
MakeList is an alternative list creation interface
func (*DBU) Query ¶ added in v0.0.5
func (du *DBU) Query(fn SetHandler, query string, args ...interface{}) error
Query satisfies DBS interface
type ListHandler ¶ added in v0.0.7
type ListHandler interface { Receivers() []interface{} Ready() }
type SetHandler ¶
type SetHandler func() []interface{}
SetHandler returns a slice of value pointer interfaces If there are no values to set it returns a nil instead
Directories ¶
Path | Synopsis |
---|---|
dbgen is a tool to automate the creation of create/update/delete methods that satisfy the github.com/paulstuart/dbobj.DBObject interface.
|
dbgen is a tool to automate the creation of create/update/delete methods that satisfy the github.com/paulstuart/dbobj.DBObject interface. |
Click to show internal directories.
Click to hide internal directories.