Documentation
¶
Index ¶
- Constants
- func FromCamelCase(name string) string
- func ToCamelCase(name string) string
- type IConnection
- type IRowTransformer
- type OptimisticLockFail
- type PersistenceFail
- type SimpleDBA
- func (this *SimpleDBA) Delete(sql string, params ...interface{}) (int64, error)
- func (this *SimpleDBA) Insert(sql string, params ...interface{}) (int64, error)
- func (this *SimpleDBA) InsertReturning(sql string, params ...interface{}) (int64, error)
- func (this *SimpleDBA) Query(sql string, transformer func(rows *sql.Rows) (interface{}, error), ...) ([]interface{}, error)
- func (this *SimpleDBA) QueryClosure(query string, transformer func(rows *sql.Rows) error, params ...interface{}) error
- func (this *SimpleDBA) QueryCollection(sql string, rt IRowTransformer, params ...interface{}) (coll.Collection, error)
- func (this *SimpleDBA) QueryFirst(sql string, params map[string]interface{}, rt IRowTransformer) (interface{}, error)
- func (this *SimpleDBA) QueryInto(query string, closure interface{}, params ...interface{}) ([]interface{}, error)
- func (this *SimpleDBA) QueryRow(sql string, params []interface{}, dest ...interface{}) (bool, error)
- func (this *SimpleDBA) Update(sql string, params ...interface{}) (int64, error)
Constants ¶
const FAULT_EXEC_STATEMENT = "STMT02"
const FAULT_OPTIMISTIC_LOCK = "OPT_LOCK"
const FAULT_PARSE_STATEMENT = "STMT03"
const FAULT_PREP_STATEMENT = "STMT01"
const FAULT_QUERY = "QRY01"
const FAULT_TRANSFORM = "TRF01"
const FAULT_VALUES_STATEMENT = "STMT04"
Variables ¶
This section is empty.
Functions ¶
func ToCamelCase ¶
Types ¶
type IConnection ¶
type IConnection interface { Exec(query string, args ...interface{}) (sql.Result, error) // The implementor of Prepare should cache the prepared statements Prepare(query string) (*sql.Stmt, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row }
type IRowTransformer ¶
type IRowTransformer interface { // Initializes the collection that will hold the results // return Creates a Collection BeforeAll() coll.Collection Transform(rows *sql.Rows) (interface{}, error) // Executes additional decision/action over the transformed object.<br> // For example, It can decide not to include if the result is repeated... // // param object: The transformed instance OnTransformation(result coll.Collection, instance interface{}) AfterAll(result coll.Collection) }
type OptimisticLockFail ¶
func NewOptimisticLockFail ¶
func NewOptimisticLockFail(message string) *OptimisticLockFail
type PersistenceFail ¶
func NewPersistenceFail ¶
func NewPersistenceFail(code string, message string) *PersistenceFail
type SimpleDBA ¶
type SimpleDBA struct {
// contains filtered or unexported fields
}
Class that simplifies the execution o Database Access
func NewSimpleDBA ¶
func NewSimpleDBA(connection IConnection) *SimpleDBA
func (*SimpleDBA) InsertReturning ¶
func (*SimpleDBA) QueryClosure ¶
func (this *SimpleDBA) QueryClosure( query string, transformer func(rows *sql.Rows) error, params ...interface{}, ) error
the transformer will be responsible for creating the result list
func (*SimpleDBA) QueryCollection ¶
func (this *SimpleDBA) QueryCollection( sql string, rt IRowTransformer, params ...interface{}, ) (coll.Collection, error)
Execute an SQL SELECT with named replacement parameters.<br> The caller is responsible for closing the connection.
param sql: The query to execute. param params: The replacement parameters. param rt: The handler that converts the results into an object. return The Collection returned by the handler and a Fail if a database access error occurs
func (*SimpleDBA) QueryFirst ¶
func (this *SimpleDBA) QueryFirst( sql string, params map[string]interface{}, rt IRowTransformer, ) (interface{}, error)
Execute an SQL SELECT query with named parameters returning the first result.
param <T>
the result object type
param conn
The connection to execute the query in.
param sql
The query to execute.
param rt
The handler that converts the results into an object.
param params
The named parameters.
@return The transformed result
func (*SimpleDBA) QueryInto ¶
func (this *SimpleDBA) QueryInto( query string, closure interface{}, params ...interface{}, ) ([]interface{}, error)
List using the closure arguments. A function is used to build the result list. The types for scanning are supplied by the function arguments. Arguments can be pointers or not. Reflection is used to determine the arguments types.
ex:
roles = make([]string, 0) var role string q.QueryInto(func(role *string) { roles = append(roles, *role) })
func (*SimpleDBA) QueryRow ¶
func (this *SimpleDBA) QueryRow( sql string, params []interface{}, dest ...interface{}, ) (bool, error)
Execute an SQL SELECT query with named parameters returning the first result.
param conn
The connection to execute the query in.
param sql
The query to execute.
param params
The named parameters.
@return if there was a row scan and error