demopgx

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2019 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const AddressTableColumnNames = "id,lines,town,postcode"

AddressTableColumnNames is the list of columns in AddressTable.

View Source
const AddressTableDataColumnNames = "lines,town,postcode"

AddressTableDataColumnNames is the list of data columns in AddressTable.

View Source
const DbUserTableColumnNames = "uid,name,emailaddress,addressid,avatar,role,active,admin,fave,lastupdated,i8,u8,i16,u16,i32,u32,i64,u64,f32,f64,token,secret"

DbUserTableColumnNames is the list of columns in DbUserTable.

View Source
const DbUserTableDataColumnNames = "name,emailaddress,addressid,avatar,role,active,admin,fave,lastupdated,i8,u8,i16,u16,i32,u32,i64,u64,f32,f64,token,secret"

DbUserTableDataColumnNames is the list of data columns in DbUserTable.

View Source
const NumAddressTableColumns = 4

NumAddressTableColumns is the total number of columns in AddressTable.

View Source
const NumAddressTableDataColumns = 3

NumAddressTableDataColumns is the number of columns in AddressTable not including the auto-increment key.

View Source
const NumDbUserTableColumns = 22

NumDbUserTableColumns is the total number of columns in DbUserTable.

View Source
const NumDbUserTableDataColumns = 21

NumDbUserTableDataColumns is the number of columns in DbUserTable not including the auto-increment key.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Id       int64    `sql:"pk: true, auto: true"`
	Lines    []string `sql:"encode: json"`
	Town     *string  `sql:"size: 80, index: townIdx"`
	Postcode string   `sql:"size: 20, index: postcodeIdx"`
}

type AddressTable

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

AddressTable 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 CopyTableAsAddressTable

func CopyTableAsAddressTable(origin pgxapi.Table) AddressTable

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

It serves to provide methods appropriate for 'Address'. 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 NewAddressTable

func NewAddressTable(name string, d pgxapi.Database) AddressTable

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

func (AddressTable) BeginTx

func (tbl AddressTable) BeginTx(opts *pgx.TxOptions) (AddressTable, error)

BeginTx starts a transaction using the table's context. This context is used until the transaction is committed or rolled back.

If this context is cancelled, the sql package will roll back the transaction. In this case, Tx.Commit will then return an error.

The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.

Panics if the Execer is not TxStarter.

func (AddressTable) Constraints

func (tbl AddressTable) Constraints() constraint.Constraints

Constraints returns the table's constraints.

func (AddressTable) Count

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

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

func (AddressTable) CountWhere

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

CountWhere counts Addresses 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 (AddressTable) CreateIndexes

func (tbl AddressTable) CreateIndexes(ifNotExist bool) (err error)

CreateIndexes executes queries that create the indexes needed by the Address table.

func (AddressTable) CreatePostcodeIdxIndex

func (tbl AddressTable) CreatePostcodeIdxIndex(ifNotExist bool) error

CreatePostcodeIdxIndex creates the postcodeIdx index.

func (AddressTable) CreateTable

func (tbl AddressTable) CreateTable(ifNotExists bool) (int64, error)

CreateTable creates the table.

func (AddressTable) CreateTableWithIndexes

func (tbl AddressTable) CreateTableWithIndexes(ifNotExist bool) (err error)

CreateTableWithIndexes invokes CreateTable then CreateIndexes.

func (AddressTable) CreateTownIdxIndex

func (tbl AddressTable) CreateTownIdxIndex(ifNotExist bool) error

CreateTownIdxIndex creates the townIdx index.

func (AddressTable) Ctx

func (tbl AddressTable) Ctx() context.Context

Ctx gets the current request context.

func (AddressTable) DB

func (tbl AddressTable) 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 (AddressTable) Database

func (tbl AddressTable) Database() pgxapi.Database

Database gets the shared database information.

func (AddressTable) Delete

func (tbl AddressTable) Delete(req require.Requirement, wh where.Expression) (int64, error)

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 (AddressTable) DeleteAddresses

func (tbl AddressTable) DeleteAddresses(req require.Requirement, id ...int64) (int64, error)

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

func (AddressTable) Dialect

func (tbl AddressTable) Dialect() dialect.Dialect

Dialect gets the database dialect.

func (AddressTable) DropIndexes

func (tbl AddressTable) DropIndexes(ifExist bool) (err error)

DropIndexes executes queries that drop the indexes on by the Address table.

func (AddressTable) DropPostcodeIdxIndex

func (tbl AddressTable) DropPostcodeIdxIndex(ifExists bool) error

DropPostcodeIdxIndex drops the postcodeIdx index.

func (AddressTable) DropTable

func (tbl AddressTable) DropTable(ifExists bool) (int64, error)

DropTable drops the table, destroying all its data.

func (AddressTable) DropTownIdxIndex

func (tbl AddressTable) DropTownIdxIndex(ifExists bool) error

DropTownIdxIndex drops the townIdx index.

func (AddressTable) Exec

func (tbl AddressTable) Exec(req require.Requirement, query string, args ...interface{}) (int64, error)

Exec executes a query without returning any rows. It returns the number of rows affected (if the database driver supports this).

The args are for any placeholder parameters in the query.

func (AddressTable) Execer

func (tbl AddressTable) Execer() pgxapi.Execer

Execer gets the wrapped database or transaction handle.

func (AddressTable) Fetch

func (tbl AddressTable) Fetch(req require.Requirement, query string, args ...interface{}) ([]*Address, error)

Fetch fetches a list of Address based on a supplied query. This is mostly used for join queries that map its result columns to the fields of Address. Other queries might be better handled by GetXxx or Select methods.

func (AddressTable) GetAddressById

func (tbl AddressTable) GetAddressById(req require.Requirement, id int64) (*Address, error)

GetAddressById gets the record with a given primary key value. If not found, *Address will be nil.

func (AddressTable) GetAddressesById

func (tbl AddressTable) GetAddressesById(req require.Requirement, id ...int64) (list []*Address, err error)

GetAddressesById gets records from the table according to a list of primary keys. Although the list of ids can be arbitrarily long, there are practical limits; note that Oracle DB has a limit of 1000.

It places a requirement, which may be nil, on the size of the expected results: in particular, require.All controls whether an error is generated not all the ids produce a result.

func (AddressTable) GetAddressesByPostcode

func (tbl AddressTable) GetAddressesByPostcode(req require.Requirement, postcode string) ([]*Address, error)

GetAddressesByPostcode gets the records with a given postcode value. If not found, the resulting slice will be empty (nil).

func (AddressTable) GetAddressesByTown

func (tbl AddressTable) GetAddressesByTown(req require.Requirement, town string) ([]*Address, error)

GetAddressesByTown gets the records with a given town value. If not found, the resulting slice will be empty (nil).

func (AddressTable) Insert

func (tbl AddressTable) Insert(req require.Requirement, vv ...*Address) error

Insert adds new records for the Addresses. The Addresses have their primary key fields set to the new record identifiers. The Address.PreInsert() method will be called, if it exists.

func (AddressTable) IsTx

func (tbl AddressTable) IsTx() bool

IsTx tests whether this is within a transaction.

func (AddressTable) Logger

func (tbl AddressTable) Logger() pgxapi.Logger

Logger gets the trace logger.

func (AddressTable) Name

func (tbl AddressTable) Name() pgxapi.TableName

Name gets the table name.

func (AddressTable) PkColumn

func (tbl AddressTable) PkColumn() string

PkColumn gets the column name used as a primary key.

func (AddressTable) Query

func (tbl AddressTable) 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 (AddressTable) QueryOneNullFloat64

func (tbl AddressTable) 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 (AddressTable) QueryOneNullInt64

func (tbl AddressTable) 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 (AddressTable) QueryOneNullString

func (tbl AddressTable) 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 (AddressTable) Select

Select allows Addresses to be obtained from the table that match a 'where' clause. 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.

It places a requirement, which may be nil, on the size of the expected results: for example require.AtLeastOne controls whether an error is generated when no result is found.

func (AddressTable) SelectOne

SelectOne allows a single Address to be obtained from the database. 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. If not found, *Example will be nil.

It places a requirement, which may be nil, on the size of the expected results: for example require.One controls whether an error is generated when no result is found.

func (AddressTable) SelectOneWhere

func (tbl AddressTable) SelectOneWhere(req require.Requirement, where, orderBy string, args ...interface{}) (*Address, error)

SelectOneWhere allows a single Example to be obtained from the table that match a 'where' clause and some limit. Any order, limit or offset clauses can be supplied in 'orderBy'. Use blank strings for the 'where' and/or 'orderBy' arguments if they are not needed. If not found, *Example will be nil.

It places a requirement, which may be nil, on the size of the expected results: for example require.One controls whether an error is generated when no result is found.

The args are for any placeholder parameters in the query.

func (AddressTable) SelectWhere

func (tbl AddressTable) SelectWhere(req require.Requirement, where, orderBy string, args ...interface{}) ([]*Address, error)

SelectWhere allows Addresses to be obtained from the table that match a 'where' clause. Any order, limit or offset clauses can be supplied in 'orderBy'. Use blank strings for the 'where' and/or 'orderBy' arguments if they are not needed.

It places a requirement, which may be nil, on the size of the expected results: for example require.AtLeastOne controls whether an error is generated when no result is found.

The args are for any placeholder parameters in the query.

func (AddressTable) SetPkColumn

func (tbl AddressTable) SetPkColumn(pk string) AddressTable

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 (AddressTable) SliceId

SliceId gets the id 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 (AddressTable) SlicePostcode

func (tbl AddressTable) SlicePostcode(req require.Requirement, wh where.Expression, qc where.QueryConstraint) ([]string, error)

SlicePostcode gets the postcode 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 (AddressTable) SliceTown

SliceTown gets the town 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 (AddressTable) Truncate

func (tbl AddressTable) Truncate(force bool) (err error)

Truncate drops every record from the table, if possible. It might fail if constraints exist that prevent some or all rows from being deleted; use the force option to override this.

When 'force' is set true, be aware of the following consequences. When using Mysql, foreign keys in other tables can be left dangling. When using Postgres, a cascade happens, so all 'adjacent' tables (i.e. linked by foreign keys) are also truncated.

func (AddressTable) Tx

func (tbl AddressTable) 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 (AddressTable) Update

func (tbl AddressTable) Update(req require.Requirement, vv ...*Address) (int64, error)

Update updates records, matching them by primary key. It returns the number of rows affected. The Address.PreUpdate(Execer) method will be called, if it exists.

func (AddressTable) UpdateFields

func (tbl AddressTable) UpdateFields(req require.Requirement, wh where.Expression, fields ...sql.NamedArg) (int64, error)

UpdateFields updates one or more columns, given a 'where' clause. Use a nil value for the 'wh' argument if it is not needed (very risky!).

func (AddressTable) Upsert

func (tbl AddressTable) Upsert(v *Address, wh where.Expression) error

Upsert inserts or updates a record, matching it using the expression supplied. This expression is used to search for an existing record based on some specified key column(s). It must match either zero or one existing record. If it matches none, a new record is inserted; otherwise the matching record is updated. An error results if these conditions are not met.

func (AddressTable) Using

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

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

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

WithConstraint returns a modified Table with added data consistency constraints.

func (AddressTable) WithContext

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

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 (AddressTable) WithPrefix

func (tbl AddressTable) WithPrefix(pfx string) AddressTable

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

type DbUserTable

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

DbUserTable 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 CopyTableAsDbUserTable

func CopyTableAsDbUserTable(origin pgxapi.Table) DbUserTable

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

It serves to provide methods appropriate for 'User'. 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 NewDbUserTable

func NewDbUserTable(name string, d pgxapi.Database) DbUserTable

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

func (DbUserTable) BeginTx

func (tbl DbUserTable) BeginTx(opts *pgx.TxOptions) (DbUserTable, error)

BeginTx starts a transaction using the table's context. This context is used until the transaction is committed or rolled back.

If this context is cancelled, the sql package will roll back the transaction. In this case, Tx.Commit will then return an error.

The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.

Panics if the Execer is not TxStarter.

func (DbUserTable) Constraints

func (tbl DbUserTable) Constraints() constraint.Constraints

Constraints returns the table's constraints.

func (DbUserTable) Count

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

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

func (DbUserTable) CountWhere

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

CountWhere counts Users 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 (DbUserTable) CreateEmailaddressIdxIndex

func (tbl DbUserTable) CreateEmailaddressIdxIndex(ifNotExist bool) error

CreateEmailaddressIdxIndex creates the emailaddress_idx index.

func (DbUserTable) CreateIndexes

func (tbl DbUserTable) CreateIndexes(ifNotExist bool) (err error)

CreateIndexes executes queries that create the indexes needed by the User table.

func (DbUserTable) CreateTable

func (tbl DbUserTable) CreateTable(ifNotExists bool) (int64, error)

CreateTable creates the table.

func (DbUserTable) CreateTableWithIndexes

func (tbl DbUserTable) CreateTableWithIndexes(ifNotExist bool) (err error)

CreateTableWithIndexes invokes CreateTable then CreateIndexes.

func (DbUserTable) CreateUserLoginIndex

func (tbl DbUserTable) CreateUserLoginIndex(ifNotExist bool) error

CreateUserLoginIndex creates the user_login index.

func (DbUserTable) Ctx

func (tbl DbUserTable) Ctx() context.Context

Ctx gets the current request context.

func (DbUserTable) DB

func (tbl DbUserTable) 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 (DbUserTable) Database

func (tbl DbUserTable) Database() pgxapi.Database

Database gets the shared database information.

func (DbUserTable) Delete

func (tbl DbUserTable) Delete(req require.Requirement, wh where.Expression) (int64, error)

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 (DbUserTable) DeleteUsers

func (tbl DbUserTable) DeleteUsers(req require.Requirement, id ...int64) (int64, error)

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

func (DbUserTable) Dialect

func (tbl DbUserTable) Dialect() dialect.Dialect

Dialect gets the database dialect.

func (DbUserTable) DropEmailaddressIdxIndex

func (tbl DbUserTable) DropEmailaddressIdxIndex(ifExists bool) error

DropEmailaddressIdxIndex drops the emailaddress_idx index.

func (DbUserTable) DropIndexes

func (tbl DbUserTable) DropIndexes(ifExist bool) (err error)

DropIndexes executes queries that drop the indexes on by the User table.

func (DbUserTable) DropTable

func (tbl DbUserTable) DropTable(ifExists bool) (int64, error)

DropTable drops the table, destroying all its data.

func (DbUserTable) DropUserLoginIndex

func (tbl DbUserTable) DropUserLoginIndex(ifExists bool) error

DropUserLoginIndex drops the user_login index.

func (DbUserTable) Exec

func (tbl DbUserTable) Exec(req require.Requirement, query string, args ...interface{}) (int64, error)

Exec executes a query without returning any rows. It returns the number of rows affected (if the database driver supports this).

The args are for any placeholder parameters in the query.

func (DbUserTable) Execer

func (tbl DbUserTable) Execer() pgxapi.Execer

Execer gets the wrapped database or transaction handle.

func (DbUserTable) Fetch

func (tbl DbUserTable) Fetch(req require.Requirement, query string, args ...interface{}) ([]*User, error)

Fetch fetches a list of User based on a supplied query. This is mostly used for join queries that map its result columns to the fields of User. Other queries might be better handled by GetXxx or Select methods.

func (DbUserTable) GetUserByEmailAddress

func (tbl DbUserTable) GetUserByEmailAddress(req require.Requirement, emailaddress string) (*User, error)

GetUserByEmailAddress gets the record with a given emailaddress value. If not found, *User will be nil.

func (DbUserTable) GetUserByName

func (tbl DbUserTable) GetUserByName(req require.Requirement, name string) (*User, error)

GetUserByName gets the record with a given name value. If not found, *User will be nil.

func (DbUserTable) GetUserByUid

func (tbl DbUserTable) GetUserByUid(req require.Requirement, id int64) (*User, error)

GetUserByUid gets the record with a given primary key value. If not found, *User will be nil.

func (DbUserTable) GetUsersByUid

func (tbl DbUserTable) GetUsersByUid(req require.Requirement, id ...int64) (list []*User, err error)

GetUsersByUid gets records from the table according to a list of primary keys. Although the list of ids can be arbitrarily long, there are practical limits; note that Oracle DB has a limit of 1000.

It places a requirement, which may be nil, on the size of the expected results: in particular, require.All controls whether an error is generated not all the ids produce a result.

func (DbUserTable) Insert

func (tbl DbUserTable) Insert(req require.Requirement, vv ...*User) error

Insert adds new records for the Users. The Users have their primary key fields set to the new record identifiers. The User.PreInsert() method will be called, if it exists.

func (DbUserTable) IsTx

func (tbl DbUserTable) IsTx() bool

IsTx tests whether this is within a transaction.

func (DbUserTable) Logger

func (tbl DbUserTable) Logger() pgxapi.Logger

Logger gets the trace logger.

func (DbUserTable) Name

func (tbl DbUserTable) Name() pgxapi.TableName

Name gets the table name.

func (DbUserTable) PkColumn

func (tbl DbUserTable) PkColumn() string

PkColumn gets the column name used as a primary key.

func (DbUserTable) Query

func (tbl DbUserTable) 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 (DbUserTable) QueryOneNullFloat64

func (tbl DbUserTable) 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 (DbUserTable) QueryOneNullInt64

func (tbl DbUserTable) 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 (DbUserTable) QueryOneNullString

func (tbl DbUserTable) 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 (DbUserTable) Select

Select allows Users to be obtained from the table that match a 'where' clause. 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.

It places a requirement, which may be nil, on the size of the expected results: for example require.AtLeastOne controls whether an error is generated when no result is found.

func (DbUserTable) SelectOne

SelectOne allows a single User to be obtained from the database. 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. If not found, *Example will be nil.

It places a requirement, which may be nil, on the size of the expected results: for example require.One controls whether an error is generated when no result is found.

func (DbUserTable) SelectOneWhere

func (tbl DbUserTable) SelectOneWhere(req require.Requirement, where, orderBy string, args ...interface{}) (*User, error)

SelectOneWhere allows a single Example to be obtained from the table that match a 'where' clause and some limit. Any order, limit or offset clauses can be supplied in 'orderBy'. Use blank strings for the 'where' and/or 'orderBy' arguments if they are not needed. If not found, *Example will be nil.

It places a requirement, which may be nil, on the size of the expected results: for example require.One controls whether an error is generated when no result is found.

The args are for any placeholder parameters in the query.

func (DbUserTable) SelectWhere

func (tbl DbUserTable) SelectWhere(req require.Requirement, where, orderBy string, args ...interface{}) ([]*User, error)

SelectWhere allows Users to be obtained from the table that match a 'where' clause. Any order, limit or offset clauses can be supplied in 'orderBy'. Use blank strings for the 'where' and/or 'orderBy' arguments if they are not needed.

It places a requirement, which may be nil, on the size of the expected results: for example require.AtLeastOne controls whether an error is generated when no result is found.

The args are for any placeholder parameters in the query.

func (DbUserTable) SetPkColumn

func (tbl DbUserTable) SetPkColumn(pk string) DbUserTable

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

func (DbUserTable) SliceAddressid

func (tbl DbUserTable) SliceAddressid(req require.Requirement, wh where.Expression, qc where.QueryConstraint) ([]int64, error)

SliceAddressid gets the addressid 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 (DbUserTable) SliceAvatar

func (tbl DbUserTable) SliceAvatar(req require.Requirement, wh where.Expression, qc where.QueryConstraint) ([]string, error)

SliceAvatar gets the avatar 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 (DbUserTable) SliceEmailaddress

func (tbl DbUserTable) SliceEmailaddress(req require.Requirement, wh where.Expression, qc where.QueryConstraint) ([]string, error)

SliceEmailaddress gets the emailaddress 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 (DbUserTable) SliceF32

SliceF32 gets the f32 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 (DbUserTable) SliceF64

SliceF64 gets the f64 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 (DbUserTable) SliceI16

SliceI16 gets the i16 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 (DbUserTable) SliceI32

SliceI32 gets the i32 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 (DbUserTable) SliceI64

SliceI64 gets the i64 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 (DbUserTable) SliceI8

SliceI8 gets the i8 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 (DbUserTable) SliceLastupdated

func (tbl DbUserTable) SliceLastupdated(req require.Requirement, wh where.Expression, qc where.QueryConstraint) ([]int64, error)

SliceLastupdated gets the lastupdated 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 (DbUserTable) SliceName

SliceName gets the name 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 (DbUserTable) SliceRole

func (tbl DbUserTable) SliceRole(req require.Requirement, wh where.Expression, qc where.QueryConstraint) ([]Role, error)

SliceRole gets the role 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 (DbUserTable) SliceU16

SliceU16 gets the u16 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 (DbUserTable) SliceU32

SliceU32 gets the u32 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 (DbUserTable) SliceU64

SliceU64 gets the u64 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 (DbUserTable) SliceU8

SliceU8 gets the u8 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 (DbUserTable) SliceUid

SliceUid gets the uid 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 (DbUserTable) Truncate

func (tbl DbUserTable) Truncate(force bool) (err error)

Truncate drops every record from the table, if possible. It might fail if constraints exist that prevent some or all rows from being deleted; use the force option to override this.

When 'force' is set true, be aware of the following consequences. When using Mysql, foreign keys in other tables can be left dangling. When using Postgres, a cascade happens, so all 'adjacent' tables (i.e. linked by foreign keys) are also truncated.

func (DbUserTable) Tx

func (tbl DbUserTable) 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 (DbUserTable) Update

func (tbl DbUserTable) Update(req require.Requirement, vv ...*User) (int64, error)

Update updates records, matching them by primary key. It returns the number of rows affected. The User.PreUpdate(Execer) method will be called, if it exists.

func (DbUserTable) UpdateFields

func (tbl DbUserTable) UpdateFields(req require.Requirement, wh where.Expression, fields ...sql.NamedArg) (int64, error)

UpdateFields updates one or more columns, given a 'where' clause. Use a nil value for the 'wh' argument if it is not needed (very risky!).

func (DbUserTable) Upsert

func (tbl DbUserTable) Upsert(v *User, wh where.Expression) error

Upsert inserts or updates a record, matching it using the expression supplied. This expression is used to search for an existing record based on some specified key column(s). It must match either zero or one existing record. If it matches none, a new record is inserted; otherwise the matching record is updated. An error results if these conditions are not met.

func (DbUserTable) Using

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

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

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

WithConstraint returns a modified Table with added data consistency constraints.

func (DbUserTable) WithContext

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

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 (DbUserTable) WithPrefix

func (tbl DbUserTable) WithPrefix(pfx string) DbUserTable

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

type Numbers

type Numbers struct {
	I8  int8    `sql:"default: -8"`
	U8  uint8   `sql:"default: 8"`
	I16 int16   `sql:"default: -16"`
	U16 uint16  `sql:"default: 16"`
	I32 int32   `sql:"default: -32"`
	U32 uint32  `sql:"default: 32"`
	I64 int64   `sql:"default: -64"`
	U64 uint64  `sql:"default: 64"`
	F32 float32 `sql:"default: 3.2"`
	F64 float64 `sql:"default: 6.4"`
}

type Role

type Role int8
const (
	Unknown Role = iota
	UserRole
	AdminRole
)

func (*Role) Parse

func (v *Role) Parse(s string) error

func (*Role) Scan

func (r *Role) Scan(value interface{}) error

func (Role) String

func (v Role) String() string

func (Role) Value

func (r Role) Value() (driver.Value, error)

type User

type User struct {
	Uid          int64  `sql:"pk: true, auto: true"`
	Name         string `sql:"unique: user_login"`
	EmailAddress string `sql:"nk: true"`
	AddressId    *int64 `sql:"fk: addresses.id, onupdate: restrict, ondelete: restrict"`
	Avatar       *string
	Role         *Role `sql:"type: text, size: 20"`
	Active       bool
	Admin        bool
	Fave         *big.Int `sql:"encode: json"`
	LastUpdated  int64

	// something just to aid test coverage
	Numbers Numbers
	// contains filtered or unexported fields
}

func (*User) PostGet

func (u *User) PostGet() error

func (*User) PreInsert

func (u *User) PreInsert() error

These hooks are just used here for testing, but you could put whatever you like in them.

func (*User) PreUpdate

func (u *User) PreUpdate() error

func (*User) SetActive

func (v *User) SetActive(x bool) *User

SetActive sets the Active field and returns the modified User.

func (*User) SetAddressId

func (v *User) SetAddressId(x int64) *User

SetAddressId sets the AddressId field and returns the modified User.

func (*User) SetAdmin

func (v *User) SetAdmin(x bool) *User

SetAdmin sets the Admin field and returns the modified User.

func (*User) SetAvatar

func (v *User) SetAvatar(x string) *User

SetAvatar sets the Avatar field and returns the modified User.

func (*User) SetEmailAddress

func (v *User) SetEmailAddress(x string) *User

SetEmailAddress sets the EmailAddress field and returns the modified User.

func (*User) SetF32

func (v *User) SetF32(x float32) *User

SetF32 sets the F32 field and returns the modified User.

func (*User) SetF64

func (v *User) SetF64(x float64) *User

SetF64 sets the F64 field and returns the modified User.

func (*User) SetFave

func (v *User) SetFave(x big.Int) *User

SetFave sets the Fave field and returns the modified User.

func (*User) SetI16

func (v *User) SetI16(x int16) *User

SetI16 sets the I16 field and returns the modified User.

func (*User) SetI32

func (v *User) SetI32(x int32) *User

SetI32 sets the I32 field and returns the modified User.

func (*User) SetI64

func (v *User) SetI64(x int64) *User

SetI64 sets the I64 field and returns the modified User.

func (*User) SetI8

func (v *User) SetI8(x int8) *User

SetI8 sets the I8 field and returns the modified User.

func (*User) SetLastUpdated

func (v *User) SetLastUpdated(x int64) *User

SetLastUpdated sets the LastUpdated field and returns the modified User.

func (*User) SetName

func (v *User) SetName(x string) *User

SetName sets the Name field and returns the modified User.

func (*User) SetRole

func (v *User) SetRole(x Role) *User

SetRole sets the Role field and returns the modified User.

func (*User) SetU16

func (v *User) SetU16(x uint16) *User

SetU16 sets the U16 field and returns the modified User.

func (*User) SetU32

func (v *User) SetU32(x uint32) *User

SetU32 sets the U32 field and returns the modified User.

func (*User) SetU64

func (v *User) SetU64(x uint64) *User

SetU64 sets the U64 field and returns the modified User.

func (*User) SetU8

func (v *User) SetU8(x uint8) *User

SetU8 sets the U8 field and returns the modified User.

func (*User) SetUid

func (v *User) SetUid(x int64) *User

SetUid sets the Uid field and returns the modified User.

func (*User) Setsecret

func (v *User) Setsecret(x string) *User

Setsecret sets the secret field and returns the modified User.

func (*User) Settoken

func (v *User) Settoken(x string) *User

Settoken sets the token field and returns the modified User.

Jump to

Keyboard shortcuts

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