Documentation ¶
Overview ¶
Package sqladapter provides common logic for SQL adapters.
Index ¶
- func IsKeyValue(v interface{}) bool
- func NumActiveStatements() int64
- func RegisterAdapter(name string, adapter AdapterSession) sqlbuilder.Adapter
- func ReplaceWithDollarSign(buf []byte) []byte
- func TxContext(ctx context.Context, sess db.Session, fn func(tx db.Session) error, ...) error
- type AdapterSession
- type Collection
- type CollectionAdapter
- type Result
- func (r *Result) All(dst interface{}) error
- func (r *Result) And(conds ...interface{}) db.Result
- func (r *Result) Base() interface{}
- func (r *Result) Close() error
- func (r *Result) Count() (uint64, error)
- func (r *Result) Cursor(cursorColumn string) db.Result
- func (r *Result) Delete() error
- func (r *Result) Err() error
- func (r *Result) Exists() (bool, error)
- func (r *Result) Fn(in interface{}) error
- func (r *Result) GroupBy(fields ...interface{}) db.Result
- func (r *Result) Limit(n int) db.Result
- func (r *Result) Next(dst interface{}) bool
- func (r *Result) NextPage(cursorValue interface{}) db.Result
- func (r *Result) Offset(n int) db.Result
- func (r *Result) One(dst interface{}) error
- func (r *Result) OrderBy(fields ...interface{}) db.Result
- func (r *Result) Page(pageNumber uint) db.Result
- func (r *Result) Paginate(pageSize uint) db.Result
- func (r *Result) Paginator() (db.Paginator, error)
- func (r *Result) Prev() immutable.Immutable
- func (r *Result) PrevPage(cursorValue interface{}) db.Result
- func (r *Result) SQL() db.SQL
- func (r *Result) Select(fields ...interface{}) db.Result
- func (r *Result) String() string
- func (r *Result) TotalEntries() (uint64, error)
- func (r *Result) TotalPages() (uint, error)
- func (r *Result) Update(values interface{}) error
- func (r *Result) Where(conds ...interface{}) db.Result
- type Session
- type Stmt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsKeyValue ¶
func IsKeyValue(v interface{}) bool
IsKeyValue reports whether v is a valid value for a primary key that can be used with Find(pKey).
func NumActiveStatements ¶
func NumActiveStatements() int64
NumActiveStatements returns the global number of prepared statements in use at any point.
func RegisterAdapter ¶
func RegisterAdapter(name string, adapter AdapterSession) sqlbuilder.Adapter
RegisterAdapter registers a new SQL adapter.
func ReplaceWithDollarSign ¶
ReplaceWithDollarSign turns a SQL statament with '?' placeholders into dollar placeholders, like $1, $2, ..., $n
Types ¶
type AdapterSession ¶
type AdapterSession interface { Template() *exql.Template NewCollection() CollectionAdapter // Open opens a new connection OpenDSN(sess Session, dsn string) (*sql.DB, error) // Collections returns a list of non-system tables from the database. Collections(sess Session) ([]string, error) // TableExists returns an error if the given table does not exist. TableExists(sess Session, name string) error // LookupName returns the name of the database. LookupName(sess Session) (string, error) // PrimaryKeys returns all primary keys on the table. PrimaryKeys(sess Session, name string) ([]string, error) }
AdapterSession defines methods to be implemented by SQL adapters.
type Collection ¶
type Collection interface { // Insert inserts a new item into the collection. Insert(interface{}) (db.InsertResult, error) // Name returns the name of the collection. Name() string // Session returns the db.Session the collection belongs to. Session() db.Session // Exists returns true if the collection exists, false otherwise. Exists() (bool, error) // Find defined a new result set. Find(conds ...interface{}) db.Result Count() (uint64, error) // Truncate removes all elements on the collection and resets the // collection's IDs. Truncate() error // InsertReturning inserts a new item into the collection and refreshes the // item with actual data from the database. This is useful to get automatic // values, such as timestamps, or IDs. InsertReturning(item interface{}) error // UpdateReturning updates a record from the collection and refreshes the item // with actual data from the database. This is useful to get automatic // values, such as timestamps, or IDs. UpdateReturning(item interface{}) error // PrimaryKeys returns the names of all primary keys in the table. PrimaryKeys() ([]string, error) // SQLBuilder returns a db.SQL instance. SQL() db.SQL }
Collection satisfies db.Collection.
type CollectionAdapter ¶
type CollectionAdapter interface { // Insert prepares and executes an INSERT statament. When the item is // succefully added, Insert returns a unique identifier of the newly added // element (or nil if the unique identifier couldn't be determined). Insert(Collection, interface{}) (interface{}, error) }
CollectionAdapter defines methods to be implemented by SQL adapters.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
func NewResult ¶
NewResult creates and Results a new Result set on the given table, this set is limited by the given exql.Where conditions.
func (*Result) Err ¶
Err returns the last error that has happened with the result set, nil otherwise
func (*Result) GroupBy ¶
GroupBy is used to group Results that have the same value in the same column or columns.
func (*Result) Offset ¶
Offset determines how many documents will be skipped before starting to grab Results.
func (*Result) OrderBy ¶
OrderBy determines sorting of Results according to the provided names. Fields may be prefixed by - (minus) which means descending order, ascending order would be used otherwise.
func (*Result) TotalEntries ¶
func (*Result) TotalPages ¶
type Session ¶
type Session interface { SQL() db.SQL // PrimaryKeys returns all primary keys on the table. PrimaryKeys(tableName string) ([]string, error) // Collections returns a list of references to all collections in the // database. Collections() ([]db.Collection, error) // Name returns the name of the database. Name() string // Close closes the database session Close() error // Ping checks if the database server is reachable. Ping() error // Reset clears all caches the session is using Reset() // Collection returns a new collection. Collection(string) db.Collection // ConnectionURL returns the ConnectionURL that was used to create the // Session. ConnectionURL() db.ConnectionURL // Open attempts to establish a connection to the database server. Open() error // TableExists returns an error if the table doesn't exists. TableExists(name string) error // Driver returns the underlying driver the session is using Driver() interface{} Save(db.Record) error Get(db.Record, interface{}) error Delete(db.Record) error // WaitForConnection attempts to run the given connection function a fixed // number of times before failing. WaitForConnection(func() error) error // BindDB sets the *sql.DB the session will use. BindDB(*sql.DB) error // Session returns the *sql.DB the session is using. DB() *sql.DB // BindTx binds a transaction to the current session. BindTx(context.Context, *sql.Tx) error // Returns the current transaction the session is using. Transaction() *sql.Tx // NewClone clones the database using the given AdapterSession as base. NewClone(AdapterSession, bool) (Session, error) // Context returns the default context the session is using. Context() context.Context // SetContext sets the default context for the session. SetContext(context.Context) NewTransaction(ctx context.Context, opts *sql.TxOptions) (Session, error) Tx(fn func(sess db.Session) error) error TxContext(ctx context.Context, fn func(sess db.Session) error, opts *sql.TxOptions) error WithContext(context.Context) db.Session IsTransaction() bool Commit() error Rollback() error db.Settings }
Session satisfies db.Session.
func NewSession ¶
func NewSession(connURL db.ConnectionURL, adapter AdapterSession) Session
NewSession creates a new Session.
type Stmt ¶
Stmt represents a *sql.Stmt that is cached and provides the OnEvict method to allow it to clean after itself.
func NewStatement ¶
NewStatement creates an returns an opened statement