dbx

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: BSD-2-Clause Imports: 7 Imported by: 6

Documentation

Index

Constants

View Source
const FAULT_OPTIMISTIC_LOCK = "optimistic-lock"
View Source
const FAULT_PARSE_STATEMENT = "sql-parse"
View Source
const FAULT_VALUES_STATEMENT = "sql-values"

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 {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, 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 deprecated

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

Deprecated: use DeleteX

func (*SimpleDBA) DeleteX added in v1.5.0

func (s *SimpleDBA) DeleteX(ctx context.Context, sql string, params ...interface{}) (int64, error)

func (*SimpleDBA) Insert deprecated

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

Deprecated: use InsertX

func (*SimpleDBA) InsertReturning deprecated

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

Deprecated: use InsertReturningX

func (*SimpleDBA) InsertReturningX added in v1.5.0

func (s *SimpleDBA) InsertReturningX(ctx context.Context, sql string, params ...interface{}) (int64, error)

func (*SimpleDBA) InsertX added in v1.5.0

func (s *SimpleDBA) InsertX(ctx context.Context, sql string, params ...interface{}) (int64, error)

func (*SimpleDBA) Query deprecated

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

Deprecated: use QueryX

func (*SimpleDBA) QueryClosure deprecated

func (s *SimpleDBA) QueryClosure(
	query string,
	transformer func(rows *sql.Rows) error,
	params ...interface{},
) error

the transformer will be responsible for creating the result list

Deprecated: use QueryClosureX

func (*SimpleDBA) QueryClosureX added in v1.5.0

func (s *SimpleDBA) QueryClosureX(
	ctx context.Context,
	query string,
	transformer func(rows *sql.Rows) error,
	params ...interface{},
) error

the transformer will be responsible for creating the result list

func (*SimpleDBA) QueryCollection deprecated

func (s *SimpleDBA) QueryCollection(
	sql string,
	rt IRowTransformer,
	params ...interface{},
) (coll.Collection, error)

QueryCollectionX 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

Deprecated: use QueryCollectionX

func (*SimpleDBA) QueryCollectionX added in v1.5.0

func (s *SimpleDBA) QueryCollectionX(
	ctx context.Context,
	sql string,
	rt IRowTransformer,
	params ...interface{},
) (coll.Collection, error)

QueryCollectionX 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 deprecated

func (s *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

Deprecated: use QueryFirstX

func (*SimpleDBA) QueryFirstX added in v1.5.0

func (s *SimpleDBA) QueryFirstX(
	ctx context.Context,
	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 deprecated

func (s *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)
 })

Deprecated: use QueryIntoX

func (*SimpleDBA) QueryIntoX added in v1.5.0

func (s *SimpleDBA) QueryIntoX(
	ctx context.Context,
	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 deprecated

func (s *SimpleDBA) QueryRow(
	query 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

Deprecated: use QueryRowX

func (*SimpleDBA) QueryRowX added in v1.5.0

func (s *SimpleDBA) QueryRowX(
	ctx context.Context,
	query 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) QueryX added in v1.5.0

func (s *SimpleDBA) QueryX(
	ctx context.Context,
	sql string,
	transformer func(rows *sql.Rows) (interface{}, error),
	params ...interface{},
) ([]interface{}, error)

func (*SimpleDBA) Update deprecated

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

Deprecated: use UpdateX

func (*SimpleDBA) UpdateX added in v1.5.0

func (s *SimpleDBA) UpdateX(ctx context.Context, 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