db.v3: upper.io/db.v3/internal/sqladapter Index | Files | Directories

package sqladapter

import "upper.io/db.v3/internal/sqladapter"

Package sqladapter provides common logic for SQL adapters.

Index

Package Files

collection.go database.go result.go sqladapter.go statement.go tx.go

func IsKeyValue Uses

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 Uses

func NumActiveStatements() int64

NumActiveStatements returns the global number of prepared statements in use at any point.

func ReplaceWithDollarSign Uses

func ReplaceWithDollarSign(in string) string

ReplaceWithDollarSign turns a SQL statament with '?' placeholders into dollar placeholders, like $1, $2, ..., $n

func RunTx Uses

func RunTx(d sqlbuilder.Database, ctx context.Context, fn func(tx sqlbuilder.Tx) error) error

RunTx creates a transaction context and runs fn within it.

type BaseCollection Uses

type BaseCollection interface {
    // Exists returns true if the collection exists.
    Exists() bool

    // Find creates and returns a new result set.
    Find(conds ...interface{}) db.Result

    // Truncate removes all items on the collection.
    Truncate() error

    // InsertReturning inserts a new item and updates it with the
    // actual values from the database.
    InsertReturning(interface{}) error

    // UpdateReturning updates an item and returns the actual values from the
    // database.
    UpdateReturning(interface{}) error

    // PrimaryKeys returns the table's primary keys.
    PrimaryKeys() []string
}

BaseCollection provides logic for methods that can be shared across all SQL adapters.

func NewBaseCollection Uses

func NewBaseCollection(p PartialCollection) BaseCollection

NewBaseCollection returns a collection with basic methods.

type BaseDatabase Uses

type BaseDatabase interface {
    db.Settings

    // 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

    // ClearCache clears all caches the session is using
    ClearCache()

    // Collection returns a new collection.
    Collection(string) db.Collection

    // Driver returns the underlying driver the session is using
    Driver() interface{}

    // WaitForConnection attempts to run the given connection function a fixed
    // number of times before failing.
    WaitForConnection(func() error) error

    // BindSession sets the *sql.DB the session will use.
    BindSession(*sql.DB) error

    // Session returns the *sql.DB the session is using.
    Session() *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() BaseTx

    // NewClone clones the database using the given PartialDatabase as base.
    NewClone(PartialDatabase, bool) (BaseDatabase, error)

    // Context returns the default context the session is using.
    Context() context.Context

    // SetContext sets a default context for the session.
    SetContext(context.Context)

    // TxOptions returns the default TxOptions for new transactions in the
    // session.
    TxOptions() *sql.TxOptions

    // SetTxOptions sets default TxOptions for the session.
    SetTxOptions(txOptions sql.TxOptions)
}

BaseDatabase provides logic for methods that can be shared across all SQL adapters.

func NewBaseDatabase Uses

func NewBaseDatabase(p PartialDatabase) BaseDatabase

NewBaseDatabase provides a BaseDatabase given a PartialDatabase

type BaseTx Uses

type BaseTx interface {
    db.Tx

    // Committed returns true if the transaction was already commited.
    Committed() bool
}

BaseTx provides logic for methods that can be shared across all SQL adapters.

type Collection Uses

type Collection interface {
    PartialCollection
    BaseCollection
}

Collection represents a SQL table.

type Database Uses

type Database interface {
    PartialDatabase
    BaseDatabase
}

Database represents a SQL database.

type DatabaseTx Uses

type DatabaseTx interface {
    BaseDatabase
    PartialDatabase

    BaseTx
}

DatabaseTx represents a database session within a transaction.

func NewDatabaseTx Uses

func NewDatabaseTx(db Database) DatabaseTx

NewDatabaseTx creates a database session within a transaction.

type PartialCollection Uses

type PartialCollection interface {
    // Database returns the parent database.
    Database() Database

    // Name returns the name of the table.
    Name() string

    // Insert inserts a new item into the collection.
    Insert(interface{}) (interface{}, error)
}

PartialCollection defines methods that must be implemented by the adapter.

type PartialDatabase Uses

type PartialDatabase interface {
    sqlbuilder.SQLBuilder

    // Collections returns a list of non-system tables from the database.
    Collections() ([]string, error)

    // Open opens a new connection
    Open(db.ConnectionURL) error

    // TableExists returns an error if the given table does not exist.
    TableExists(name string) error

    // LookupName returns the name of the database.
    LookupName() (string, error)

    // PrimaryKeys returns all primary keys on the table.
    PrimaryKeys(name string) ([]string, error)

    // NewCollection allocates a new collection by name.
    NewCollection(name string) db.Collection

    // CompileStatement transforms an internal statement into a format
    // database/sql can understand.
    CompileStatement(stmt *exql.Statement, args []interface{}) (string, []interface{})

    // ConnectionURL returns the database's connection URL, if any.
    ConnectionURL() db.ConnectionURL

    // Err wraps specific database errors (given in string form) and transforms them
    // into error values.
    Err(in error) (out error)

    // NewDatabaseTx begins a transaction block and returns a new
    // session backed by it.
    NewDatabaseTx(ctx context.Context) (DatabaseTx, error)
}

PartialDatabase defines methods to be implemented by SQL database adapters.

type Result Uses

type Result struct {
    // contains filtered or unexported fields
}

func NewResult Uses

func NewResult(builder sqlbuilder.SQLBuilder, table string, conds []interface{}) *Result

NewResult creates and Results a new Result set on the given table, this set is limited by the given exql.Where conditions.

func (*Result) All Uses

func (r *Result) All(dst interface{}) error

All dumps all Results into a pointer to an slice of structs or maps.

func (*Result) And Uses

func (r *Result) And(conds ...interface{}) db.Result

And adds more conditions on top of the existing ones.

func (*Result) Base Uses

func (r *Result) Base() interface{}

func (*Result) Close Uses

func (r *Result) Close() error

Close closes the Result set.

func (*Result) Count Uses

func (r *Result) Count() (uint64, error)

Count counts the elements on the set.

func (*Result) Cursor Uses

func (r *Result) Cursor(cursorColumn string) db.Result

func (*Result) Delete Uses

func (r *Result) Delete() error

Delete deletes all matching items from the collection.

func (*Result) Err Uses

func (r *Result) Err() error

Err returns the last error that has happened with the result set, nil otherwise

func (*Result) Exists Uses

func (r *Result) Exists() (bool, error)

Exists returns true if at least one item on the collection exists.

func (*Result) Fn Uses

func (r *Result) Fn(in interface{}) error

func (*Result) Group Uses

func (r *Result) Group(fields ...interface{}) db.Result

Group is used to group Results that have the same value in the same column or columns.

func (*Result) Limit Uses

func (r *Result) Limit(n int) db.Result

Limit determines the maximum limit of Results to be returned.

func (*Result) Next Uses

func (r *Result) Next(dst interface{}) bool

Next fetches the next Result from the set.

func (*Result) NextPage Uses

func (r *Result) NextPage(cursorValue interface{}) db.Result

func (*Result) Offset Uses

func (r *Result) Offset(n int) db.Result

Offset determines how many documents will be skipped before starting to grab Results.

func (*Result) One Uses

func (r *Result) One(dst interface{}) error

One fetches only one Result from the set.

func (*Result) OrderBy Uses

func (r *Result) OrderBy(fields ...interface{}) db.Result

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) Page Uses

func (r *Result) Page(pageNumber uint) db.Result

func (*Result) Paginate Uses

func (r *Result) Paginate(pageSize uint) db.Result

func (*Result) Prev Uses

func (r *Result) Prev() immutable.Immutable

func (*Result) PrevPage Uses

func (r *Result) PrevPage(cursorValue interface{}) db.Result

func (*Result) SQLBuilder Uses

func (r *Result) SQLBuilder() sqlbuilder.SQLBuilder

func (*Result) Select Uses

func (r *Result) Select(fields ...interface{}) db.Result

Select determines which fields to return.

func (*Result) String Uses

func (r *Result) String() string

String satisfies fmt.Stringer

func (*Result) TotalEntries Uses

func (r *Result) TotalEntries() (uint64, error)

func (*Result) TotalPages Uses

func (r *Result) TotalPages() (uint, error)

func (*Result) Update Uses

func (r *Result) Update(values interface{}) error

Update updates matching items from the collection with values of the given map or struct.

func (*Result) Where Uses

func (r *Result) Where(conds ...interface{}) db.Result

Where sets conditions for the result set.

type Stmt Uses

type Stmt struct {
    *sql.Stmt
    // contains filtered or unexported fields
}

Stmt represents a *sql.Stmt that is cached and provides the OnPurge method to allow it to clean after itself.

func NewStatement Uses

func NewStatement(stmt *sql.Stmt, query string) *Stmt

NewStatement creates an returns an opened statement

func (*Stmt) Close Uses

func (c *Stmt) Close() error

Close closes the underlying statement if no other go-routine is using it.

func (*Stmt) OnPurge Uses

func (c *Stmt) OnPurge()

OnPurge marks the statement as ready to be cleaned up.

func (*Stmt) Open Uses

func (c *Stmt) Open() (*Stmt, error)

Open marks the statement as in-use

Directories

PathSynopsis
compat
exql

Package sqladapter imports 18 packages (graph) and is imported by 5 packages. Updated 2018-09-26. Refresh now. Tools for package owners.