Documentation ¶
Index ¶
- type ContextInterface
- type Database
- type DatabaseTransactionContext
- type InsertUpdateDeleteInterface
- type Interface
- type Pagination
- type QueryInterface
- type Settings
- type SqlContextInterface
- type SqlInterface
- type SqlWrapper
- func (sqlWrapper SqlWrapper) Context(tx DatabaseTransactionContext) ContextInterface
- func (sqlWrapper SqlWrapper) Delete() error
- func (sqlWrapper SqlWrapper) Insert() (int, error)
- func (sqlWrapper SqlWrapper) NoACL() SqlInterface
- func (sqlWrapper SqlWrapper) Pagination(pagination Pagination, selectFields []string) QueryInterface
- func (sqlWrapper SqlWrapper) PaginationWithCountSQLTemplate(pagination Pagination, countSQLTemplateOverride string) QueryInterface
- func (sqlWrapper SqlWrapper) Parameter(key string, value interface{}) SqlContextInterface
- func (sqlWrapper SqlWrapper) ParameterNullable(key string, value interface{}) SqlContextInterface
- func (sqlWrapper SqlWrapper) Query(result interface{}) error
- func (sqlWrapper SqlWrapper) QueryOne(result interface{}) error
- func (sqlWrapper SqlWrapper) QueryWithCount(result interface{}) (int, error)
- func (sqlWrapper SqlWrapper) SQL(sqlTemplate string) SqlContextInterface
- func (sqlWrapper SqlWrapper) SetAuditableContext(databaseSettingName string, value interface{}) error
- func (sqlWrapper SqlWrapper) Update() (int, error)
- type TransactionContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextInterface ¶
type ContextInterface interface { // NoACL declares that no ACL-checks are needed. NoACL() SqlInterface // SetAuditableContext sets database setting name into current transaction's variable for auditing purposes. SetAuditableContext(databaseSettingName string, value interface{}) error }
type Database ¶
type Database interface { sqlbuilder.Database Settings }
Database is the wrapper-interface for upper.io/db that also contains our custom database settings.
type DatabaseTransactionContext ¶
type DatabaseTransactionContext interface { sqlbuilder.SQLBuilder Settings }
type InsertUpdateDeleteInterface ¶
type InsertUpdateDeleteInterface interface { // Insert executes a sql insert query and returns inserted records ID (only if query ends with "returning id;"). Insert() (int, error) // Update executes a sql update query and returns affected rows count (do not use `;` in the sql). Update() (int, error) // Delete executes a sql delete query. Delete() error }
InsertUpdateDeleteInterface describes insert, update, delete methods
type Interface ¶
type Interface interface { // Context sets an query context: // tx - database or transaction reference Context(tx DatabaseTransactionContext) ContextInterface }
Interface for SqlWrapper
type Pagination ¶
Pagination holds general pagination input data
type QueryInterface ¶
type QueryInterface interface { // QueryOne executes a sql select query to retrieve one object. QueryOne(result interface{}) error // Query executes a sql select query to retrieve many objects. Query(result interface{}) error // QueryWithCount executes a count and a select query to retrieve many objects and the total count. // Meant to be used with pagination. QueryWithCount(result interface{}) (int, error) }
QueryInterface describes querying methods
type Settings ¶
type Settings interface { // SetStatementTimeout sets the default statement timeout (in seconds). // Database queries will return with an error after this time. 0 = no timeout. SetStatementTimeout(int) // StatementTimeout returns the default statement timeout (in seconds). // Database queries will return with an error after this time. 0 = no timeout. StatementTimeout() int }
Settings is an interface for reading and setting custom database settings that are not included in upper.io/db.
type SqlContextInterface ¶
type SqlContextInterface interface { InsertUpdateDeleteInterface QueryInterface // Parameter declares an sql parameter // key - key of the parameter (i.e. "application_id"). // value - value of the parameter. Parameter(key string, value interface{}) SqlContextInterface // ParameterNullable declares an sql parameter // key - key of the parameter (i.e. "application_id"). // value - value of the parameter. If value is default, then parameter will be used as NULL ParameterNullable(key string, value interface{}) SqlContextInterface // Pagination declares pagination settings (with automatic count query). // pagination - pagination settings. // selectFields - these fields will be selected when performing query. Pagination(pagination Pagination, selectFields []string) QueryInterface // PaginationWithCountSQLTemplate declares pagination settings (with implicit count sql template). // pagination - pagination settings. // countSQLTemplateOverride - this sql template will be used for count query (optional). PaginationWithCountSQLTemplate(pagination Pagination, countSQLTemplateOverride string) QueryInterface }
SqlContextInterface describes methods for SQL context
type SqlInterface ¶
type SqlInterface interface { // SQL sets the sql template to be used for the query. // Possible placeholders: // {{select}} - use when querying with count. // {{footer}} - use when using pagination or querying with count. // Custom parameters are also allowed (i.e. {{id}})) but have to be provided by Parameter-declarations. SQL(sqlTemplate string) SqlContextInterface }
SqlInterface describes methods for SQL template defining
type SqlWrapper ¶
type SqlWrapper struct {
// contains filtered or unexported fields
}
SqlWrapper wraps db query making
func (SqlWrapper) Context ¶
func (sqlWrapper SqlWrapper) Context(tx DatabaseTransactionContext) ContextInterface
Context sets an query context: tx - database or transaction reference
func (SqlWrapper) Delete ¶
func (sqlWrapper SqlWrapper) Delete() error
Delete executes a sql delete query.
func (SqlWrapper) Insert ¶
func (sqlWrapper SqlWrapper) Insert() (int, error)
Insert executes a sql insert query and returns inserted records ID (only if query ends with "returning id;").
func (SqlWrapper) NoACL ¶
func (sqlWrapper SqlWrapper) NoACL() SqlInterface
NoACL declares that no ACL-checks are needed.
func (SqlWrapper) Pagination ¶
func (sqlWrapper SqlWrapper) Pagination(pagination Pagination, selectFields []string) QueryInterface
Pagination declares pagination settings (with automatic count query). pagination - pagination settings. selectFields - these fields will be selected when performing query.
func (SqlWrapper) PaginationWithCountSQLTemplate ¶
func (sqlWrapper SqlWrapper) PaginationWithCountSQLTemplate(pagination Pagination, countSQLTemplateOverride string) QueryInterface
PaginationWithCountSQLTemplate declares pagination settings (with implicit count sql template). pagination - pagination settings. countSQLTemplateOverride - this sql template will be used for count query (optional).
func (SqlWrapper) Parameter ¶
func (sqlWrapper SqlWrapper) Parameter(key string, value interface{}) SqlContextInterface
Parameter declares an sql parameter key - key of the parameter (i.e. "id"). value - value of the parameter.
func (SqlWrapper) ParameterNullable ¶
func (sqlWrapper SqlWrapper) ParameterNullable(key string, value interface{}) SqlContextInterface
ParameterNullable declares an sql parameter key - key of the parameter (i.e. "id"). value - value of the parameter. If value is default, then parameter will be used as NULL
func (SqlWrapper) Query ¶
func (sqlWrapper SqlWrapper) Query(result interface{}) error
Query executes a sql select query to retrieve many objects.
func (SqlWrapper) QueryOne ¶
func (sqlWrapper SqlWrapper) QueryOne(result interface{}) error
QueryOne executes a sql select query to retrieve one object.
func (SqlWrapper) QueryWithCount ¶
func (sqlWrapper SqlWrapper) QueryWithCount(result interface{}) (int, error)
QueryWithCount executes a count and a select query to retrieve many objects and the total count. Meant to be used with pagination.
func (SqlWrapper) SQL ¶
func (sqlWrapper SqlWrapper) SQL(sqlTemplate string) SqlContextInterface
SQL sets the sql template to be used for the query. Possible placeholders: {{select}} - use when querying with count. {{footer}} - use when using pagination or querying with count. Custom parameters are also allowed (i.e. {{id}})) but have to be provided by Parameter-declarations.
func (SqlWrapper) SetAuditableContext ¶
func (sqlWrapper SqlWrapper) SetAuditableContext(databaseSettingName string, value interface{}) error
SetAuditableContext sets database setting name into current transaction's variable for auditing purposes.
func (SqlWrapper) Update ¶
func (sqlWrapper SqlWrapper) Update() (int, error)
Update executes a sql update query.
type TransactionContext ¶
type TransactionContext interface { sqlbuilder.Tx Settings }