Documentation ¶
Index ¶
- Constants
- func IdsPlaceholdersArgs(ids []data.Id) (string, []interface{})
- func List(value string, count int) string
- func Normalize(d Dialect, query string) string
- type Dialect
- type ExecerContext
- type PostgresqlDialect
- type QueryExecerContext
- type QueryerContext
- type Repo
- func (r *Repo) BeginContext(ctx context.Context) (Tx, error)
- func (r *Repo) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (r *Repo) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (r *Repo) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (r *Repo) TxWorkContext(ctx context.Context, work func(QueryExecerContext) error) error
- type Scanner
- type Tx
- type UTCTime
Constants ¶
const Placeholder = "?"
Placeholder is the only placeholder recognized by this package. It is transparently parsed in queries into the Dialect specific representation.
Variables ¶
This section is empty.
Functions ¶
func IdsPlaceholdersArgs ¶
IdsPlaceholdersArgs returns a list of placeholders (from List(Placeholder, len(ids)) and a slice of arguments that is a copy of ids.
Types ¶
type Dialect ¶
type Dialect interface { //Placeholder should return the DBMS specific placeholder for index. //Index is zero-based. Placeholder(index int) string }
Dialect allows client code to use this package in a DBMS independent way by providing methods to abstract the differences betwenn DBMSs.
type ExecerContext ¶
type ExecerContext interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
ExecerContext provides the execute methods with Contexts for a sql database.
type PostgresqlDialect ¶
type PostgresqlDialect struct{}
PostgresqlDialect is a Dialect that understands the Postgresql DBMS.
func (PostgresqlDialect) Placeholder ¶
func (p PostgresqlDialect) Placeholder(index int) string
Placeholder is the Dialect implementation.
type QueryExecerContext ¶
type QueryExecerContext interface { QueryerContext ExecerContext }
QueryExecerContext provides the query and exec with Contexts methods for a sql database.
type QueryerContext ¶
type QueryerContext interface { QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row }
QueryerContext provides the query methods with Contexts for a sql database.
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
Repo provides utility methods to help working with the SQL package.
func (*Repo) BeginContext ¶
BeginContext starts a transaction in r. The interface returned wraps the QueryExecerContext and the necessary methods on the sql.Tx type. it calls BeginTx on r's underlying sql.DB.
func (*Repo) ExecContext ¶
func (r *Repo) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext is the QueryExecerContext implementation. It calls ExecContext on r's underlying sql.DB.
func (*Repo) QueryContext ¶
func (r *Repo) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext is the QueryerContext implementation. It calls QueryContext on r's underlying sql.DB.
func (*Repo) QueryRowContext ¶
QueryRowContext is the QueryerContext implementation. It calls QueryRowContext on r's underlying sql.DB.
func (*Repo) TxWorkContext ¶
TxWorkContext executes work inside of a transaction with ctx with committing and rollback handled for you.
type Scanner ¶
type Scanner interface { //Scan is the method to get a row into data. Scan(dst ...interface{}) error }
Scanner is a wrapper interface around sql.Rows and sql.Row.
type Tx ¶
type Tx interface { //QueryExecerContext provides the query and exec context methods. QueryExecerContext //Commit commits the transaction. Commit() error //Rollback rolls back the transaction. Rollback() error }
Tx is a QueryExecer with the Commit and Rollback methods required for transactions. It also provides a Stmt method so prepared statements can be executed within this transaction.