Documentation
¶
Index ¶
- type RuleParser
- type SQLExecutor
- type SQLTXManager
- func (tm *SQLTXManager) Begin(ctx context.Context, opts *sql.TxOptions) (newCtx context.Context, err error)
- func (tm *SQLTXManager) Commit(tx any) error
- func (tm *SQLTXManager) DB() interface{}
- func (tm *SQLTXManager) Name() TXName
- func (tm *SQLTXManager) OriginTXOrDB(ctx context.Context) SQLExecutor
- func (tm *SQLTXManager) Rollback(tx any) error
- func (tm *SQLTXManager) TX(ctx context.Context) interface{}
- func (tm *SQLTXManager) TXOrDB(ctx context.Context) interface{}
- type TXManager
- type TXName
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RuleParser ¶
type RuleParser struct {
}
RuleParser Format: $Subject [$SubjectModifier] [@Filter] [$Sort]
Subject:
Find Query Get Search:General query method returning typically the repository type,slice or struct Count : Count projection returning a numeric result. Exists : Exists projection, returning typically a boolean result. Delete Remove : Delete query method returning either no result (void) or the delete count.
SubjectModifier:
Distinct: Use a distinct query to return only unique results. Top<Number>: Limit the query results to the first <number> of results.
Filter: By$Field$Predicate[$FilterModifier][And|Or $Field$Predicate[$FilterModifier]]
Remark: If you want to support nested fields later, use _ to separate the nesting
Predicate:
Is, Equals, (or no keyword) Contains: for string contains substring or collection contains an element StartsWith EndsWith: for string Between: The BETWEEN operator is inclusive: begin and end values are included. GT LT GTE LTE: for comparable IsNull IsNotNull: IsEmpty IsNotEmpty: for string or collection is empty IsFalse IsTrue: for bool In NotIn: Matches: match the regex wait for support: Exists, ContainsAny(for array), ContainsAll(for array)
FilterModifier:
IgnoreCase: Used with a predicate keyword for case-insensitive comparison. AllIgnoreCase: Ignore case for all suitable properties. Used somewhere in the query method predicate.
Sort: Specify a static sorting order followed by the field path and direction
Format: OrderBy$Field[$Direction], EX: OrderByFirstnameAscLastnameDesc
$Direction:
Desc Asc: default is Desc
func NewRuleParser ¶
func NewRuleParser() *RuleParser
func (*RuleParser) ParseSubject ¶
func (r *RuleParser) ParseSubject(method string) (*query.Subject, error)
type SQLExecutor ¶
type SQLExecutor interface {
// PrepareContext creates a prepared statement for later queries or executions.
// Multiple queries or executions may be run concurrently from the
// returned statement.
// The caller must call the statement's Close method
// when the statement is no longer needed.
//
// The provided context is used for the preparation of the statement, not for the
// execution of the statement.
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
// Prepare creates a prepared statement for later queries or executions.
// Multiple queries or executions may be run concurrently from the
// returned statement.
// The caller must call the statement's Close method
// when the statement is no longer needed.
//
// Prepare uses context.Background internally; to specify the context, use
// PrepareContext.
Prepare(query string) (*sql.Stmt, error)
// ExecContext executes a query that doesn't return rows.
// For example: an INSERT and UPDATE.
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
// Exec executes a query that doesn't return rows.
// For example: an INSERT and UPDATE.
//
// Exec uses context.Background internally; to specify the context, use
// ExecContext.
Exec(query string, args ...any) (sql.Result, error)
// QueryContext executes a query that returns rows, typically a SELECT.
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
// Query executes a query that returns rows, typically a SELECT.
//
// Query uses context.Background internally; to specify the context, use
// QueryContext.
Query(query string, args ...any) (*sql.Rows, error)
// QueryRowContext executes a query that is expected to return at most one row.
// QueryRowContext always returns a non-nil value. Errors are deferred until
// Row's Scan method is called.
// If the query selects no rows, the *Row's Scan will return ErrNoRows.
// Otherwise, the *Row's Scan scans the first selected row and discards
// the rest.
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
// QueryRow executes a query that is expected to return at most one row.
// QueryRow always returns a non-nil value. Errors are deferred until
// Row's Scan method is called.
// If the query selects no rows, the *Row's Scan will return ErrNoRows.
// Otherwise, the *Row's Scan scans the first selected row and discards
// the rest.
//
// QueryRow uses context.Background internally; to specify the context, use
// QueryRowContext.
QueryRow(query string, args ...any) *sql.Row
}
SQLExecutor (SQL Go database connection) is a wrapper for SQL database handler ( can be *sql.DB or *sql.Tx) It should be able to work with all SQL data that follows SQL standard.
type SQLTXManager ¶
type SQLTXManager struct {
// contains filtered or unexported fields
}
func NewSqlTxManager ¶
func NewSqlTxManager(name string, db *sql.DB) *SQLTXManager
func (*SQLTXManager) Commit ¶
func (tm *SQLTXManager) Commit(tx any) error
func (*SQLTXManager) DB ¶
func (tm *SQLTXManager) DB() interface{}
func (*SQLTXManager) Name ¶
func (tm *SQLTXManager) Name() TXName
func (*SQLTXManager) OriginTXOrDB ¶
func (tm *SQLTXManager) OriginTXOrDB(ctx context.Context) SQLExecutor
func (*SQLTXManager) Rollback ¶
func (tm *SQLTXManager) Rollback(tx any) error
func (*SQLTXManager) TX ¶
func (tm *SQLTXManager) TX(ctx context.Context) interface{}
func (*SQLTXManager) TXOrDB ¶
func (tm *SQLTXManager) TXOrDB(ctx context.Context) interface{}
Click to show internal directories.
Click to hide internal directories.