vanilla

package
v0.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2018 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package vanilla provides a re-usable table API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PrimaryKey

type PrimaryKey struct {
	Id int64 `sql:"pk: true, auto: true"`
}

PrimaryKey provides access to the primary key only; all other database columns are ignored. This is useful in situations where identity is the only concern.

type PrimaryKeyTable

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

PrimaryKeyTable holds a given table name with the database reference, providing access methods below. The Prefix field is often blank but can be used to hold a table name prefix (e.g. ending in '_'). Or it can specify the name of the schema, in which case it should have a trailing '.'.

func CopyTableAsPrimaryKeyTable

func CopyTableAsPrimaryKeyTable(origin sqlgen2.Table) PrimaryKeyTable

CopyTableAsPrimaryKeyTable copies a table instance, retaining the name etc but providing methods appropriate for the primary key. It doesn't copy the constraints of the original table.

func NewPrimaryKeyTable

func NewPrimaryKeyTable(name sqlgen2.TableName, d *sqlgen2.Database) PrimaryKeyTable

NewPrimaryKeyTable returns a new table instance. The primary key column defaults to "id" but can subsequently be altered. The request context is initialised with the background.

func (PrimaryKeyTable) BeginTx

func (tbl PrimaryKeyTable) BeginTx(opts *sql.TxOptions) (PrimaryKeyTable, error)

Begin starts a transaction. The default isolation level is dependent on the driver. The result is a modified copy of the table; the original is unchanged.

func (PrimaryKeyTable) Constraints added in v0.14.0

func (tbl PrimaryKeyTable) Constraints() constraint.Constraints

Constraints gets the constraints.

func (PrimaryKeyTable) Count

func (tbl PrimaryKeyTable) Count(wh where.Expression) (count int64, err error)

Count counts the PrimaryKeys in the table that match a 'where' clause. Use a nil value for the 'wh' argument if it is not needed.

func (PrimaryKeyTable) CountWhere

func (tbl PrimaryKeyTable) CountWhere(where string, args ...interface{}) (count int64, err error)

CountWhere counts PrimaryKeys in the table that match a 'where' clause. Use a blank string for the 'where' argument if it is not needed.

The args are for any placeholder parameters in the query.

func (PrimaryKeyTable) Ctx

func (tbl PrimaryKeyTable) Ctx() context.Context

Ctx gets the current request context.

func (PrimaryKeyTable) DB

func (tbl PrimaryKeyTable) DB() *sql.DB

DB gets the wrapped database handle, provided this is not within a transaction. Panics if it is in the wrong state - use IsTx() if necessary.

func (PrimaryKeyTable) Database

func (tbl PrimaryKeyTable) Database() *sqlgen2.Database

Database gets the shared database information.

func (PrimaryKeyTable) Delete

Delete deletes one or more rows from the table, given a 'where' clause. Use a nil value for the 'wh' argument if it is not needed (very risky!).

func (PrimaryKeyTable) DeleteIn

func (tbl PrimaryKeyTable) DeleteIn(req require.Requirement, id ...int64) (int64, error)

DeleteIn deletes rows from the table, given some primary keys. The list of ids can be arbitrarily long.

func (PrimaryKeyTable) Dialect

func (tbl PrimaryKeyTable) Dialect() schema.Dialect

Dialect gets the database dialect.

func (PrimaryKeyTable) Execer

func (tbl PrimaryKeyTable) Execer() sqlgen2.Execer

Execer gets the wrapped database or transaction handle.

func (PrimaryKeyTable) IsTx

func (tbl PrimaryKeyTable) IsTx() bool

IsTx tests whether this is within a transaction.

func (PrimaryKeyTable) Logger

func (tbl PrimaryKeyTable) Logger() *log.Logger

Logger gets the trace logger.

func (PrimaryKeyTable) MustQueryOneNullFloat64

func (tbl PrimaryKeyTable) MustQueryOneNullFloat64(query string, args ...interface{}) (result sql.NullFloat64, err error)

MustQueryOneNullFloat64 is a low-level access method for one float64. This can be used for 'AVG(...)' queries and such like.

It places a requirement that exactly one result must be found; an error is generated when this expectation is not met.

Note that this applies ReplaceTableName to the query string.

The args are for any placeholder parameters in the query.

func (PrimaryKeyTable) MustQueryOneNullInt64

func (tbl PrimaryKeyTable) MustQueryOneNullInt64(query string, args ...interface{}) (result sql.NullInt64, err error)

MustQueryOneNullInt64 is a low-level access method for one int64. This can be used for 'COUNT(1)' queries and such like.

It places a requirement that exactly one result must be found; an error is generated when this expectation is not met.

Note that this applies ReplaceTableName to the query string.

The args are for any placeholder parameters in the query.

func (PrimaryKeyTable) MustQueryOneNullString

func (tbl PrimaryKeyTable) MustQueryOneNullString(query string, args ...interface{}) (result sql.NullString, err error)

MustQueryOneNullString is a low-level access method for one string. This can be used for function queries and such like.

It places a requirement that exactly one result must be found; an error is generated when this expectation is not met.

Note that this applies ReplaceTableName to the query string.

The args are for any placeholder parameters in the query.

func (PrimaryKeyTable) Name

func (tbl PrimaryKeyTable) Name() sqlgen2.TableName

Name gets the table name.

func (PrimaryKeyTable) Query

func (tbl PrimaryKeyTable) Query(query string, args ...interface{}) (*sql.Rows, error)

Query is the low-level request method for this table. The query is logged using whatever logger is configured. If an error arises, this too is logged.

If you need a context other than the background, use WithContext before calling Query.

The args are for any placeholder parameters in the query.

The caller must call rows.Close() on the result.

func (PrimaryKeyTable) QueryOneNullFloat64

func (tbl PrimaryKeyTable) QueryOneNullFloat64(query string, args ...interface{}) (result sql.NullFloat64, err error)

QueryOneNullFloat64 is a low-level access method for one float64. This can be used for 'AVG(...)' queries and such like. If the query selected many rows, only the first is returned; the rest are discarded. If not found, the result will be invalid.

Note that this applies ReplaceTableName to the query string.

The args are for any placeholder parameters in the query.

func (PrimaryKeyTable) QueryOneNullInt64

func (tbl PrimaryKeyTable) QueryOneNullInt64(query string, args ...interface{}) (result sql.NullInt64, err error)

QueryOneNullInt64 is a low-level access method for one int64. This can be used for 'COUNT(1)' queries and such like. If the query selected many rows, only the first is returned; the rest are discarded. If not found, the result will be invalid.

Note that this applies ReplaceTableName to the query string.

The args are for any placeholder parameters in the query.

func (PrimaryKeyTable) QueryOneNullString

func (tbl PrimaryKeyTable) QueryOneNullString(query string, args ...interface{}) (result sql.NullString, err error)

QueryOneNullString is a low-level access method for one string. This can be used for function queries and such like. If the query selected many rows, only the first is returned; the rest are discarded. If not found, the result will be invalid.

Note that this applies ReplaceTableName to the query string.

The args are for any placeholder parameters in the query.

func (PrimaryKeyTable) ReplaceTableName

func (tbl PrimaryKeyTable) ReplaceTableName(query string) string

ReplaceTableName replaces all occurrences of "{TABLE}" with the table's name.

func (PrimaryKeyTable) SetPkColumn

func (tbl PrimaryKeyTable) SetPkColumn(pk string) PrimaryKeyTable

SetPkColumn sets the name of the primary key column The result is a modified copy of the table; the original is unchanged.

func (PrimaryKeyTable) SliceId

SliceId gets the primary key column for all rows that match the 'where' condition. Any order, limit or offset clauses can be supplied in query constraint 'qc'. Use nil values for the 'wh' and/or 'qc' arguments if they are not needed.

func (PrimaryKeyTable) Tx

func (tbl PrimaryKeyTable) Tx() *sql.Tx

Tx gets the wrapped transaction handle, provided this is within a transaction. Panics if it is in the wrong state - use IsTx() if necessary.

func (PrimaryKeyTable) Using

func (tbl PrimaryKeyTable) Using(tx *sql.Tx) PrimaryKeyTable

Using returns a modified Table using the transaction supplied. This is needed when making multiple queries across several tables within a single transaction. The result is a modified copy of the table; the original is unchanged.

func (PrimaryKeyTable) WithConstraint

func (tbl PrimaryKeyTable) WithConstraint(cc ...constraint.Constraint) PrimaryKeyTable

WithConstraint returns a modified Table with added data consistency constraints.

func (PrimaryKeyTable) WithContext

func (tbl PrimaryKeyTable) WithContext(ctx context.Context) PrimaryKeyTable

WithContext sets the context for subsequent queries. The result is a modified copy of the table; the original is unchanged.

func (PrimaryKeyTable) WithPrefix

func (tbl PrimaryKeyTable) WithPrefix(pfx string) PrimaryKeyTable

WithPrefix sets the table name prefix for subsequent queries. The result is a modified copy of the table; the original is unchanged.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL