dbx

package
v0.0.0-...-e93145e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2017 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const FAULT_EXEC_STATEMENT = "STMT02"
View Source
const FAULT_OPTIMISTIC_LOCK = "OPT_LOCK"
View Source
const FAULT_PARSE_STATEMENT = "STMT03"
View Source
const FAULT_PREP_STATEMENT = "STMT01"
View Source
const FAULT_QUERY = "QRY01"
View Source
const FAULT_TRANSFORM = "TRF01"
View Source
const FAULT_VALUES_STATEMENT = "STMT04"

Variables

This section is empty.

Functions

func FromCamelCase

func FromCamelCase(name string) string

converts helloWorld -> HELLO_WORLD

func ToCamelCase

func ToCamelCase(name string) string

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

type OptimisticLockFail struct {
	*tk.Fail
}

func NewOptimisticLockFail

func NewOptimisticLockFail(message string) *OptimisticLockFail

type PersistenceFail

type PersistenceFail struct {
	*tk.Fail
}

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) Delete

func (this *SimpleDBA) Delete(sql string, params ...interface{}) (int64, error)

func (*SimpleDBA) Insert

func (this *SimpleDBA) Insert(sql string, params ...interface{}) (int64, error)

func (*SimpleDBA) InsertReturning

func (this *SimpleDBA) InsertReturning(sql string, params ...interface{}) (int64, error)

func (*SimpleDBA) Query

func (this *SimpleDBA) Query(
	sql string,
	transformer func(rows *sql.Rows) (interface{}, error),
	params ...interface{},
) ([]interface{}, error)

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

func (*SimpleDBA) Update

func (this *SimpleDBA) Update(sql string, params ...interface{}) (int64, error)

/** Execute an SQL INSERT, UPDATE, or DELETE query.

param conn

The connection to use to run the query.

param sql

The SQL to execute.

param params

The query named parameters.

@return The number of rows affected. */

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL