Documentation
¶
Overview ¶
*
- Date: 12/03/14
- Time: 06:34 PM
*
- Date: 22/02/14
- Time: 11:17 AM
*
- Date: 9/02/14
- Time: 7:06 PM
*
- Date: 9/02/14
- Time: 7:03 PM
*
- Date: 9/02/14
- Time: 6:40 PM
*
- Date: 8/02/14
- Time: 11:22 AM
*
- Date: 11/02/14
- Time: 7:17 PM
Index ¶
- Constants
- func ABool(p bool) *bool
- func BindArgs(pModel Model) []interface{}
- func INIT(pBaseModel BaseModel)
- func SetMagic(pId *OpalMagic)
- func SwitchGem(pGem Gem) bool
- type Action
- type ActiveRecord
- type ActiveRecordDAO
- type Args
- type AutoIncrement
- type BaseModel
- type Bool
- type Column
- type DefaultDialect
- type Dialect
- type DialectEncoder
- type Domain
- type DomainModel
- type Entity
- type Execor
- type Float64
- type Gem
- func (o *Gem) Begin(fAction Action) *Txn
- func (o Gem) Exec(pSql Sql, pArgs ...interface{}) (sql.Result, error)
- func (o Gem) Metadata(pModelName ModelName) ModelMetadata
- func (o Gem) Query(pModelName ModelName, pSql Sql) ([]Model, error)
- func (o Gem) QueryRow(pModelName ModelName, pSql Sql, pArgs ...interface{}) Model
- type GenerationType
- type Int64
- type Key
- type KeyColumn
- type KeyField
- type Mapper
- type Model
- type ModelArgs
- type ModelDAO
- type ModelHook
- type ModelIDAO
- func (o *ModelIDAO) Delete(pModel Model) Result
- func (o *ModelIDAO) ExecorStmt(pModel ModelName, pNamedStmt string) *sql.Stmt
- func (o ModelIDAO) FindAllModels() []Model
- func (o ModelIDAO) FindModel(pKeys ...interface{}) Model
- func (o ModelIDAO) Gem() Gem
- func (o *ModelIDAO) Insert(pModel Model) Result
- func (ModelIDAO) Kind() reflect.Kind
- func (o ModelIDAO) Model() ModelName
- func (o *ModelIDAO) Save(pModel Model) Result
- func (o *ModelIDAO) SqlBuilder() *SqlBuilder
- type ModelMetadata
- func (o *ModelMetadata) AddColumn(pField string, pIndex int, pColumn Column, pKind reflect.Kind)
- func (o *ModelMetadata) AddKey(pField string, pIndex int, pColumn Column, pKind reflect.Kind)
- func (o *ModelMetadata) AddTable(pTable Table, pKeyFieldNames ...string)
- func (o ModelMetadata) Column(pField string) Column
- func (o ModelMetadata) ColumnByFieldIndex(pIndex int) Column
- func (o ModelMetadata) ColumnByIndex(index int) Column
- func (o *ModelMetadata) ColumnListWithConstraints(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
- func (o ModelMetadata) Columns() []Column
- func (o *ModelMetadata) ColumnsBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
- func (o *ModelMetadata) ColumnsList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
- func (o *ModelMetadata) ColumnsListEqualsColumnsBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
- func (o *ModelMetadata) KeyListEqualsKeyBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
- func (o *ModelMetadata) NonKeyListEqualsNonKeyBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
- func (o *ModelMetadata) ReplaceColumnIdentifiers(sql string, fDialect DialectEncoder) string
- func (o *ModelMetadata) ReplaceTableIdentifiers(sql string, fDialect DialectEncoder) string
- func (o ModelMetadata) Table() Table
- func (o ModelMetadata) Type() reflect.Type
- type ModelName
- type ModelQueries
- type ModelTemplate
- type ModifyDB
- type Opal
- type OpalEntity
- func (o OpalEntity) ActiveRecord() ActiveRecordDAO
- func (o *OpalEntity) Delete() Result
- func (o *OpalEntity) Insert() Result
- func (o *OpalEntity) Metadata() ModelMetadata
- func (o OpalEntity) Model() Model
- func (o OpalEntity) ModelName() ModelName
- func (o OpalEntity) New(pModel Model) Entity
- func (o *OpalEntity) Save() Result
- func (o *OpalEntity) String() string
- type OpalMagic
- type OpalSql
- type PostDelete
- type PostInsert
- type PostUpdate
- type PreDelete
- type PreInsert
- type PreUpdate
- type PreparedQuery
- type Result
- type Rows
- type Select
- type Slice
- type Sql
- type SqlBuilder
- func (o *SqlBuilder) Add(p string) *SqlBuilder
- func (o *SqlBuilder) Create() *SqlBuilder
- func (o *SqlBuilder) Delete() *SqlBuilder
- func (o *SqlBuilder) Do(...interface{}) *SqlBuilder
- func (o *SqlBuilder) Insert() *SqlBuilder
- func (o *SqlBuilder) Select(pColumns ...string) *SqlBuilder
- func (o *SqlBuilder) Sql() Sql
- func (o *SqlBuilder) Truncate(pInt int) *SqlBuilder
- func (o *SqlBuilder) Update() *SqlBuilder
- func (o *SqlBuilder) Values() *SqlBuilder
- func (o *SqlBuilder) Where(pMap Mapper) *SqlBuilder
- func (o *SqlBuilder) WhereAll() *SqlBuilder
- func (o *SqlBuilder) WherePk() *SqlBuilder
- func (o *SqlBuilder) With(fBuild SqlBuilderDialectEncoder, fDialect DialectEncoder) *SqlBuilder
- type SqlBuilderDialectEncoder
- type StartArgs
- type StmtExec
- type StmtQuery
- type StmtQueryRow
- type String
- type T
- type Table
- type Tag
- type TemplateField
- type TemplateType
- type Time
- type Transaction
- type TxArgs
- type Txn
- func (o *Txn) Create(pModel Model, pArgs Args) Result
- func (o *Txn) Delete(pModel Model) Result
- func (o *Txn) Exec(pSql Sql, pArgs ...interface{}) Result
- func (o *Txn) ExecorStmt(pModelName ModelName, pNamedStmt string) *sql.Stmt
- func (o *Txn) Go() (result Result, success bool)
- func (o *Txn) Insert(pModel Model) Result
- func (o *Txn) Update(pModel Model) Result
- type Type
- type Validation
Constants ¶
const ( PrimaryKey reflect.Kind = iota + reflect.UnsafePointer + 1 OpalTime Embedded DAO )
Variables ¶
This section is empty.
Functions ¶
func BindArgs ¶
func BindArgs(pModel Model) []interface{}
Gets all the bind args for a model. Does not include any join columns.
func INIT ¶
func INIT(pBaseModel BaseModel)
INIT will scan each supplied Model/Domain object and generate the relevant Boilerplate code with which you can run TODO doco
Types ¶
type Action ¶
type Action func(pTx Transaction) Result
User simplified function types to build transactions
type ActiveRecord ¶
type ActiveRecord interface { // Takes a Model saves it as a new data-store entity and // returns a result Insert(pModel Model) Result // Takes a Model, updates an existing entity from the // data-store and returns a result Save(pModel Model) Result // Takes a Model and removes an existing entity from the // data-store Delete(pModel Model) Result }
ActiveRecordDAO acts as a data provider for a Model's Entity. It is a limited version of the full Domain access object.
type ActiveRecordDAO ¶
type ActiveRecordDAO interface { // Takes a Model saves it as a new data-store entity and // returns a result Insert(pModel Model) Result // Takes a Model, updates an existing entity from the // data-store and returns a result Save(pModel Model) Result // Takes a Model and removes an existing entity from the // data-store Delete(pModel Model) Result }
ActiveRecordDAO acts as a data provider for a Model's Entity. It is a limited version of the full Domain access object.
type Args ¶
type Args interface {
// Retrieve args from the type
Get() []interface{}
}
Args interface allows you to retrieve the args from any type which implements this
type AutoIncrement ¶
type AutoIncrement struct {
Int64
}
Is an Int64 under the covers where its name flags its use
type BaseModel ¶
type BaseModel interface {
Models() []Domain
}
The Base model acts as the container to retrieve all Models and their corresponding metadata in the Domain.
Each domain must define a BaseModel ¶
BaseModel / Entity overlap in function TODO re-consider use and requirement
type Bool ¶
type Bool struct {
Bool *bool
}
Bool represents an int64 that may be null. Bool implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.
type Column ¶
type Column struct { Identifier string Name string AutoIncrement bool Unique bool Nilable bool Insertable bool Updatable bool Length uint Precision uint Scale uint Kind reflect.Kind }
TODO
func (Column) BuildColumnSchema ¶
func (o Column) BuildColumnSchema(pBuilder *SqlBuilder) *SqlBuilder
TODO
func (Column) BuildKeySchema ¶
func (o Column) BuildKeySchema(pBuilder *SqlBuilder) *SqlBuilder
TODO
type Dialect ¶
type Dialect interface { // All identifiers will be transformed into a string // compatible with the dialect to ensure that any keywords // that might be used as identifiers do not cause Sql errors. // E.g. In Sqlite if you want to use a keyword as a name, // you need to quote it: // // 'keyword' A keyword in single quotes is a string // literal. // // "keyword" A keyword in double-quotes is an identifier. // // [keyword] A keyword enclosed in square brackets is an // identifier. This is not standard SQL. This quoting // mechanism is used by MS Access and SQL Server and // is included in SQLite for compatibility. // // `keyword` A keyword enclosed in grave accents (ASCII // code 96) is an identifier. This is not standard SQL. // This quoting mechanism is used by MySQL and is // included in SQLite for compatibility. // // Sqlite enforces quoted string literals as identifiers based on // context EncodeIdentifier(pIdentifier string) string TransformTypeDeclaration(pColumn Column) string }
The Dialect interface performs sql syntax modification to conform to the differences in implementations of the SQL standard. Initially the Dialect will be made with the differences of Sqlite3 in mind. Will be expanded in the future.
type DialectEncoder ¶
type Domain ¶
type Domain interface {
ModelName() ModelName
}
Domain is the skeleton interface for a Model. The metadata tied to a Model is based on its domain name. A ModelName is derived from the package path and the standard name used to access a type in a package.
type DomainModel ¶
type DomainModel struct { Domain Interface interface{} }
type Entity ¶
type Entity interface { // Should return an ActiveRecordDAO interface instance // of the main DAO ActiveRecord() ActiveRecordDAO // Returns the Entity's ModelName which represents its // domain or type ModelName() ModelName // Returns the model address so it can be used as // an ActiveRecord Model() Model // Each creation of a Model requires its own Entity // Creating a new Entity is based on the Domain's // default Entity for the Model which is created // through the NewEntity func passed at GEM startup. // The creation links the new Domain Entity with a // Model instance allowing database functions to be // performed on it. New(pModel Model) Entity // Insert passes the Model address to the the ModelDAO // service for persisting into the data-store Insert() Result // Save should update an already managed Model into // the data-store Save() Result // Delete should destroy and remove the Model from // the data-store Delete() Result // Metadata gets a copy of the Model's metadata Metadata() ModelMetadata // String returns a string representation of the Model String() string }
The Entity interface is used to provide ActiveRecord and DAO access to a Model instance.
type Float64 ¶
type Float64 struct {
Float64 *float64
}
Float64 represents an int64 that may be null. Float64 implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.
type Gem ¶
Go entity manager This struct acts as a mediator between Models and a sql.DB
func (*Gem) Begin ¶
result, success := gemInstance.New((func(t Transaction)Result{ person := domain.NewPerson() person.SetKey(190) person.Name.Set(name) person.Save() person = NewPerson() person.SetKey(191) person.Name.Set("Doong Gong Sum") return t.Persist(person) })).Go()
func (Gem) Metadata ¶
func (o Gem) Metadata(pModelName ModelName) ModelMetadata
Gets a copy of the metadata associated with the Model which is identified by its ModelName
type GenerationType ¶
type GenerationType int
const ( AUTO GenerationType = iota INCREMENT TABLE IDENTITY SEQUENCE )
type Int64 ¶
type Int64 struct {
Int64 *int64
}
Int64 represents an int64 that may be null. Int64 implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.
type KeyColumn ¶
type KeyColumn struct { Auto bool Type GenerationType }
type Model ¶
type Model interface { // A Model must implement the Entity interface. // This is achieved by Embedding the Entity implementation // into the Model implementation. Entity // It also retrieves a function to create the Models domain // specific DAO. This object can be used to perform tasks // associated with the Models domain rather than a single instance. Gather(pMetadata *ModelMetadata) (ModelName, *Entity, func(*ModelIDAO) ModelDAO) // ScanInto should return a new Model which can interact with // the base DAO system and addresses to its columns so data // can be scanned into it. ScanInto() (Model, []interface{}) // Returns all columns' primary keys which can be scanned // into. Keys() []interface{} // Returns all columns' non primary keys which can be scanned // into. Parameters() []interface{} }
A Model is the interface type which can represent any object that can be stored as a Database store item
type ModelArgs ¶
type ModelArgs func(Model) []interface{}
Any function which takes a Model and returns an arg slice
type ModelDAO ¶
type ModelDAO interface { Opal ActiveRecordDAO // Find all models within the domain FindAllModels() []Model // Find a specific Model using its keys FindModel(pKeys ...interface{}) Model // Create a Sql Builder for the specified Model SqlBuilder() *SqlBuilder // Returns the ModelName associated with this instance Model() ModelName }
ModelDAO acts a data provider for a Model's domain Methods are
type ModelHook ¶
type ModelHook func() error
ModelHook can be used by a Model implementation to do a specific task on one of the pre defined sql execution events. A Model must implement one of the Hook interfaces below for the ModelHook function to run during Model related execution.
type ModelIDAO ¶
type ModelIDAO struct {
// contains filtered or unexported fields
}
ModelIDAO Implements ModelDAO
func (*ModelIDAO) ExecorStmt ¶
func (ModelIDAO) FindAllModels ¶
func (*ModelIDAO) Insert ¶
TODO find why insert prepared statement does not work TODO fix persis gets a primary key unique constraint error
func (*ModelIDAO) SqlBuilder ¶
func (o *ModelIDAO) SqlBuilder() *SqlBuilder
type ModelMetadata ¶
func NewMetadata ¶
func NewMetadata(pModel Model, pType reflect.Type) *ModelMetadata
Hold special data about a domain object model
func (*ModelMetadata) AddTable ¶
func (o *ModelMetadata) AddTable(pTable Table, pKeyFieldNames ...string)
TODO
func (ModelMetadata) Column ¶
func (o ModelMetadata) Column(pField string) Column
Get the column metadata by the domains field name
func (ModelMetadata) ColumnByFieldIndex ¶
func (o ModelMetadata) ColumnByFieldIndex(pIndex int) Column
Get the column metadata by the domains field index
func (ModelMetadata) ColumnByIndex ¶
func (o ModelMetadata) ColumnByIndex(index int) Column
Get the column metadata by its natural index
func (*ModelMetadata) ColumnListWithConstraints ¶
func (o *ModelMetadata) ColumnListWithConstraints(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
TODO
func (*ModelMetadata) ColumnsBindList ¶
func (o *ModelMetadata) ColumnsBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
Adds columns onto a sql builder in the form :Name, :Name,... or ?, ?... // TODO
func (*ModelMetadata) ColumnsList ¶
func (o *ModelMetadata) ColumnsList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
TODO
func (*ModelMetadata) ColumnsListEqualsColumnsBindList ¶
func (o *ModelMetadata) ColumnsListEqualsColumnsBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
TODO
func (*ModelMetadata) KeyListEqualsKeyBindList ¶
func (o *ModelMetadata) KeyListEqualsKeyBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
TODO
func (*ModelMetadata) NonKeyListEqualsNonKeyBindList ¶
func (o *ModelMetadata) NonKeyListEqualsNonKeyBindList(pBuilder *SqlBuilder, fDialect DialectEncoder) *SqlBuilder
sqlite seems to ignore incorrect set pk bindings when updating TODO need to ignore primary keys columns
func (*ModelMetadata) ReplaceColumnIdentifiers ¶
func (o *ModelMetadata) ReplaceColumnIdentifiers(sql string, fDialect DialectEncoder) string
TODO
func (*ModelMetadata) ReplaceTableIdentifiers ¶
func (o *ModelMetadata) ReplaceTableIdentifiers(sql string, fDialect DialectEncoder) string
TODO
func (ModelMetadata) Type ¶
func (o ModelMetadata) Type() reflect.Type
Get the type of the entity domain parent
type ModelName ¶
type ModelName string
A ModelName is an identifying string specific to a Model. It must be unique across all entities e.g: domain.Person
type ModelQueries ¶
type ModelQueries interface { NamedQueries() []PreparedQuery DerivedQueries() []PreparedQuery }
type ModelTemplate ¶
type ModelTemplate struct { Version string Date string Time string Types map[string]*TemplateType }
Some rules 1: Primary keys if not one of the four base types will be an embedded type where only one param will be generated. 2: Compound keys which are expanded will be of the four base
base types and their primitives will be expanded into the
parameters.
type OpalEntity ¶
type OpalEntity struct {
// contains filtered or unexported fields
}
OpalEntity implements the Entity interface If you require your own implementation you can supply Gem a function through which to create the Model embeddable instances of the Entity.
func (OpalEntity) ActiveRecord ¶
func (o OpalEntity) ActiveRecord() ActiveRecordDAO
func (*OpalEntity) Delete ¶
func (o *OpalEntity) Delete() Result
func (*OpalEntity) Insert ¶
func (o *OpalEntity) Insert() Result
func (*OpalEntity) Metadata ¶
func (o *OpalEntity) Metadata() ModelMetadata
func (OpalEntity) Model ¶
func (o OpalEntity) Model() Model
func (OpalEntity) ModelName ¶
func (o OpalEntity) ModelName() ModelName
func (OpalEntity) New ¶
func (o OpalEntity) New(pModel Model) Entity
TODO shrink use of instances here if possible heavy on performance
func (*OpalEntity) Save ¶
func (o *OpalEntity) Save() Result
func (*OpalEntity) String ¶
func (o *OpalEntity) String() string
type OpalSql ¶
type OpalSql string
Future type for using when the opal sql has more of its own nuances
type PreparedQuery ¶
type PreparedQuery interface { }
type Result ¶
Result is a wrapper around a sql.Result and any affiliated error. It is used to simplify the API TODO change package for Result as its associated to DAO
type Select ¶
type Select func(pTx Transaction) ([]Model, error)
type Slice ¶
type Slice struct {
Slice []byte
}
Slice implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.
type SqlBuilder ¶
type SqlBuilder struct { *ModelMetadata Dialect bytes.Buffer }
func (*SqlBuilder) Add ¶
func (o *SqlBuilder) Add(p string) *SqlBuilder
func (*SqlBuilder) Create ¶
func (o *SqlBuilder) Create() *SqlBuilder
func (*SqlBuilder) Delete ¶
func (o *SqlBuilder) Delete() *SqlBuilder
func (*SqlBuilder) Do ¶
func (o *SqlBuilder) Do(...interface{}) *SqlBuilder
func (*SqlBuilder) Insert ¶
func (o *SqlBuilder) Insert() *SqlBuilder
func (*SqlBuilder) Select ¶
func (o *SqlBuilder) Select(pColumns ...string) *SqlBuilder
func (*SqlBuilder) Sql ¶
func (o *SqlBuilder) Sql() Sql
func (*SqlBuilder) Truncate ¶
func (o *SqlBuilder) Truncate(pInt int) *SqlBuilder
func (*SqlBuilder) Update ¶
func (o *SqlBuilder) Update() *SqlBuilder
func (*SqlBuilder) Values ¶
func (o *SqlBuilder) Values() *SqlBuilder
func (*SqlBuilder) Where ¶
func (o *SqlBuilder) Where(pMap Mapper) *SqlBuilder
func (*SqlBuilder) WhereAll ¶
func (o *SqlBuilder) WhereAll() *SqlBuilder
func (*SqlBuilder) WherePk ¶
func (o *SqlBuilder) WherePk() *SqlBuilder
func (*SqlBuilder) With ¶
func (o *SqlBuilder) With(fBuild SqlBuilderDialectEncoder, fDialect DialectEncoder) *SqlBuilder
type SqlBuilderDialectEncoder ¶
type SqlBuilderDialectEncoder func(*SqlBuilder, DialectEncoder) *SqlBuilder
type StmtQueryRow ¶
type String ¶
type String struct {
Str *string
}
String represents an int64 that may be null. String implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.
type Tag ¶
type Tag string
A StructTag is the tag string in a struct field.
By convention, tag strings are a concatenation of optionally space-separated key:"value" pairs. Each key is a non-empty string consisting of non-control characters other than space (U+0020 ' '), quote (U+0022 '"'), and colon (U+003A ':'). Each value is quoted using U+0022 '"' characters and Go string literal syntax.
func ExtractOpalTags ¶
type TemplateField ¶
type TemplateType ¶
type Time ¶
Time represents an time.Time that may be null. Time implements the Scanner interface so It can be used as a scan destination, similar to sql.NullString.
type Transaction ¶
type Transaction struct {
*Txn
}
Transaction is a wrapper of a *Txn for building Transactions. It is used to simplify Transaction building from a user perspective. t Transaction is much easier to remember than t *Txn
type TxArgs ¶
type TxArgs func(pTx Transaction, pArgs interface{}) error
type Txn ¶
type Txn struct { //Embedded so Txn behaves like a standard Tx *sql.Tx // contains filtered or unexported fields }
Txn is a sql.Tx wrapper which holds the action to run and its result It also carries a reference to the current Gem.
func (*Txn) Create ¶
Persist will insert the Model within a Transaction. Call this within a Txn func Action
func (*Txn) Delete ¶
Delete will delete the Model within a Transaction. Call this within a Txn func Action
func (*Txn) ExecorStmt ¶
func (*Txn) Go ¶
Go runs the Transaction it has in from Gem.Begin Begin Running Go will defer control of Rollback and Commit functionality to the system. If required a user can manually run a transaction using the *sql.DB connection. Returns the result and whether the transaction was successful
type Validation ¶
type Validation interface { }