vanilla

package
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2020 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package vanilla provides a re-usable table API.

Index

Constants

View Source
const NumRecordColumns = 1

NumRecordColumns is the total number of columns in Record.

View Source
const NumRecordDataColumns = 0

NumRecordDataColumns is the number of columns in Record not including the auto-increment key.

View Source
const RecordColumnNames = "id"

RecordColumnNames is the list of columns in Record.

View Source
const RecordDataColumnNames = ""

RecordDataColumnNames is the list of data columns in Record.

Variables

This section is empty.

Functions

This section is empty.

Types

type Record

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

Record 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 RecordTable

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

RecordTable 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 CopyTableAsRecordTable

func CopyTableAsRecordTable(origin pgxapi.Table) RecordTable

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

It serves to provide methods appropriate for 'Record'. This is most useful when this is used to represent a join result. In such cases, there won't be any need for DDL methods, nor Exec, Insert, Update or Delete.

func NewRecordTable

func NewRecordTable(name string, d pgxapi.SqlDB) RecordTable

NewRecordTable returns a new table instance. If a blank table name is supplied, the default name "records" will be used instead. The request context is initialised with the background.

func (RecordTable) Constraints

func (tbl RecordTable) Constraints() constraint.Constraints

Constraints returns the table's constraints.

func (RecordTable) Ctx

func (tbl RecordTable) Ctx() context.Context

Ctx gets the current request context.

func (RecordTable) DB

func (tbl RecordTable) DB() pgxapi.SqlDB

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 (RecordTable) Dialect

func (tbl RecordTable) Dialect() driver.Dialect

Dialect gets the database dialect.

func (RecordTable) Execer

func (tbl RecordTable) Execer() pgxapi.Execer

Execer gets the wrapped database or transaction handle.

func (RecordTable) IsTx

func (tbl RecordTable) IsTx() bool

IsTx tests whether this is within a transaction.

func (RecordTable) Logger

func (tbl RecordTable) Logger() pgxapi.Logger

Logger gets the trace logger.

func (RecordTable) Name

func (tbl RecordTable) Name() pgxapi.TableName

Name gets the table name.

func (RecordTable) PkColumn

func (tbl RecordTable) PkColumn() string

PkColumn gets the column name used as a primary key.

func (RecordTable) Query

func (tbl RecordTable) Query(query string, args ...interface{}) (pgxapi.SqlRows, 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.

Wrap the result in *pgxapi.Rows if you need to access its data as a map.

func (RecordTable) QueryOneNullFloat64

func (tbl RecordTable) QueryOneNullFloat64(req require.Requirement, 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 (RecordTable) QueryOneNullInt64

func (tbl RecordTable) QueryOneNullInt64(req require.Requirement, 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 (RecordTable) QueryOneNullString

func (tbl RecordTable) QueryOneNullString(req require.Requirement, 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 (RecordTable) SetPkColumn

func (tbl RecordTable) SetPkColumn(pk string) RecordTable

SetPkColumn sets the name of the primary key column. It defaults to "id". The result is a modified copy of the table; the original is unchanged.

func (RecordTable) Tx

func (tbl RecordTable) Tx() pgxapi.SqlTx

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 (RecordTable) Using

func (tbl RecordTable) Using(tx pgxapi.SqlTx) RecordTable

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 (RecordTable) WithConstraint

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

WithConstraint returns a modified Table with added data consistency constraints.

func (RecordTable) WithContext

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

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

The shared context in the *Database is not altered by this method. So it is possible to use different contexts for different (groups of) queries.

func (RecordTable) WithPrefix

func (tbl RecordTable) WithPrefix(pfx string) RecordTable

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