models

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserIdFieldIndex       int = 0
	UserEmailFieldIndex    int = 1
	UserNicknameFieldIndex int = 2
	UserMaxFieldIndex      int = (3 - 1)
)

bit indicies for 'fieldMask' parameters

Variables

A field set saying that all fields in User should be updated. For use as a 'fieldMask' parameter

View Source
var UserAllIncludes *include.Spec = include.Must(include.Parse(
	`users`,
))

Functions

This section is empty.

Types

type ConnPGClient

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

func (*ConnPGClient) BulkDeleteUser

func (conn *ConnPGClient) BulkDeleteUser(
	ctx context.Context,
	ids []int64,
	opts ...pggen.DeleteOpt,
) error

func (*ConnPGClient) BulkInsertUser

func (conn *ConnPGClient) BulkInsertUser(
	ctx context.Context,
	values []User,
	opts ...pggen.InsertOpt,
) ([]int64, error)

Insert a list of User. Returns a list of the primary keys of the inserted rows.

func (*ConnPGClient) BulkUpsertUser

func (conn *ConnPGClient) BulkUpsertUser(
	ctx context.Context,
	values []User,
	constraintNames []string,
	fieldMask pggen.FieldSet,
	opts ...pggen.UpsertOpt,
) (ret []int64, err error)

Upsert a set of User values. If any of the given values conflict with existing rows in the database, use the provided values to update the rows which exist in the database rather than inserting them. Only the fields specified by 'fieldMask' are actually updated. All other fields are left as-is.

func (*ConnPGClient) Close

func (conn *ConnPGClient) Close() error

func (*ConnPGClient) DeleteUser

func (conn *ConnPGClient) DeleteUser(
	ctx context.Context,
	id int64,
	opts ...pggen.DeleteOpt,
) error

func (*ConnPGClient) GetUser

func (conn *ConnPGClient) GetUser(
	ctx context.Context,
	id int64,
	opts ...pggen.GetOpt,
) (*User, error)

func (*ConnPGClient) GetUsersByNullableNickname

func (conn *ConnPGClient) GetUsersByNullableNickname(
	ctx context.Context,
	arg1 *string,
) (ret []User, err error)

This query looks up users by their nickname, even if that nickname is NULL.

Note the funny `nickname = $1 OR (nickname IS NULL AND $1 IS NULL)` construct. This is a common pattern when querying based on possibly-null parameters. The reason for this has to do with SQL's trinary logic and null propigation. In the context of of most programming languages nulls mean something like "a reference to nothing", but in SQL it is better to think of NULL as meaning "unknown". What is `nickname = UNKNOWN`? Well, we don't know what is on the rhs, so the whole thing is `UNKNOWN`. What about `UNKNOWN OR true`? Well, all we need to know is that one side of the OR is true in order for the whole thing to be true, so the whole expression is `true`.

If we just wrote `WHERE nickname = $1` as would make sense in most programming languages, we would end up with `WHERE UNKNOWN` when `$1` is NULL, and SQL will only return queries where it knows for sure that the WHERE condition is true, so we would never be able to return any results when `$1` is NULL. If that was the case there would be no point in generating code for nullable arguments in the first place.

func (*ConnPGClient) GetUsersByNullableNicknameQuery

func (conn *ConnPGClient) GetUsersByNullableNicknameQuery(
	ctx context.Context,
	arg1 *string,
) (*sql.Rows, error)

This query looks up users by their nickname, even if that nickname is NULL.

Note the funny `nickname = $1 OR (nickname IS NULL AND $1 IS NULL)` construct. This is a common pattern when querying based on possibly-null parameters. The reason for this has to do with SQL's trinary logic and null propigation. In the context of of most programming languages nulls mean something like "a reference to nothing", but in SQL it is better to think of NULL as meaning "unknown". What is `nickname = UNKNOWN`? Well, we don't know what is on the rhs, so the whole thing is `UNKNOWN`. What about `UNKNOWN OR true`? Well, all we need to know is that one side of the OR is true in order for the whole thing to be true, so the whole expression is `true`.

If we just wrote `WHERE nickname = $1` as would make sense in most programming languages, we would end up with `WHERE UNKNOWN` when `$1` is NULL, and SQL will only return queries where it knows for sure that the WHERE condition is true, so we would never be able to return any results when `$1` is NULL. If that was the case there would be no point in generating code for nullable arguments in the first place.

func (*ConnPGClient) Handle

func (conn *ConnPGClient) Handle() pggen.DBHandle

func (*ConnPGClient) InsertUser

func (conn *ConnPGClient) InsertUser(
	ctx context.Context,
	value *User,
	opts ...pggen.InsertOpt,
) (ret int64, err error)

Insert a User into the database. Returns the primary key of the inserted row.

func (*ConnPGClient) ListUser

func (conn *ConnPGClient) ListUser(
	ctx context.Context,
	ids []int64,
	opts ...pggen.ListOpt,
) (ret []User, err error)

func (*ConnPGClient) UpdateUser

func (conn *ConnPGClient) UpdateUser(
	ctx context.Context,
	value *User,
	fieldMask pggen.FieldSet,
	opts ...pggen.UpdateOpt,
) (ret int64, err error)

Update a User. 'value' must at the least have a primary key set. The 'fieldMask' field set indicates which fields should be updated in the database.

Returns the primary key of the updated row.

func (*ConnPGClient) UpsertUser

func (conn *ConnPGClient) UpsertUser(
	ctx context.Context,
	value *User,
	constraintNames []string,
	fieldMask pggen.FieldSet,
	opts ...pggen.UpsertOpt,
) (ret int64, err error)

Upsert a User value. If the given value conflicts with an existing row in the database, use the provided value to update that row rather than inserting it. Only the fields specified by 'fieldMask' are actually updated. All other fields are left as-is.

func (*ConnPGClient) UserBulkFillIncludes

func (conn *ConnPGClient) UserBulkFillIncludes(
	ctx context.Context,
	recs []*User,
	includes *include.Spec,
	opts ...pggen.IncludeOpt,
) error

func (*ConnPGClient) UserFillIncludes

func (conn *ConnPGClient) UserFillIncludes(
	ctx context.Context,
	rec *User,
	includes *include.Spec,
	opts ...pggen.IncludeOpt,
) error

type DBQueries

type DBQueries interface {

	// User methods
	GetUser(ctx context.Context, id int64, opts ...pggen.GetOpt) (*User, error)
	ListUser(ctx context.Context, ids []int64, opts ...pggen.ListOpt) ([]User, error)
	InsertUser(ctx context.Context, value *User, opts ...pggen.InsertOpt) (int64, error)
	BulkInsertUser(ctx context.Context, values []User, opts ...pggen.InsertOpt) ([]int64, error)
	UpdateUser(ctx context.Context, value *User, fieldMask pggen.FieldSet, opts ...pggen.UpdateOpt) (ret int64, err error)
	UpsertUser(ctx context.Context, value *User, constraintNames []string, fieldMask pggen.FieldSet, opts ...pggen.UpsertOpt) (int64, error)
	BulkUpsertUser(ctx context.Context, values []User, constraintNames []string, fieldMask pggen.FieldSet, opts ...pggen.UpsertOpt) ([]int64, error)
	DeleteUser(ctx context.Context, id int64, opts ...pggen.DeleteOpt) error
	BulkDeleteUser(ctx context.Context, ids []int64, opts ...pggen.DeleteOpt) error
	UserFillIncludes(ctx context.Context, rec *User, includes *include.Spec, opts ...pggen.IncludeOpt) error
	UserBulkFillIncludes(ctx context.Context, recs []*User, includes *include.Spec, opts ...pggen.IncludeOpt) error

	// GetUsersByNullableNickname query
	GetUsersByNullableNickname(
		ctx context.Context,
		arg1 *string,
	) ([]User, error)
	GetUsersByNullableNicknameQuery(
		ctx context.Context,
		arg1 string,
	) (*sql.Rows, error)
}

type PGClient

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

PGClient wraps either a 'sql.DB' or a 'sql.Tx'. All pggen-generated database access methods for this package are attached to it.

func NewPGClient

func NewPGClient(conn pggen.DBConn) *PGClient

NewPGClient creates a new PGClient out of a '*sql.DB' or a custom wrapper around a db connection.

If you provide your own wrapper around a '*sql.DB' for logging or custom tracing, you MUST forward all calls to an underlying '*sql.DB' member of your wrapper.

If the DBConn passed into NewPGClient implements an ErrorConverter method which returns a func(error) error, the result of calling the ErrorConverter method will be called on every error that the generated code returns right before the error is returned. If ErrorConverter returns nil or is not present, it will default to the identity function.

func (*PGClient) BeginTx

func (p *PGClient) BeginTx(ctx context.Context, opts *sql.TxOptions) (*TxPGClient, error)

func (*PGClient) BulkDeleteUser

func (p *PGClient) BulkDeleteUser(
	ctx context.Context,
	ids []int64,
	opts ...pggen.DeleteOpt,
) error

func (*PGClient) BulkInsertUser

func (p *PGClient) BulkInsertUser(
	ctx context.Context,
	values []User,
	opts ...pggen.InsertOpt,
) ([]int64, error)

Insert a list of User. Returns a list of the primary keys of the inserted rows.

func (*PGClient) BulkUpsertUser

func (p *PGClient) BulkUpsertUser(
	ctx context.Context,
	values []User,
	constraintNames []string,
	fieldMask pggen.FieldSet,
	opts ...pggen.UpsertOpt,
) (ret []int64, err error)

Upsert a set of User values. If any of the given values conflict with existing rows in the database, use the provided values to update the rows which exist in the database rather than inserting them. Only the fields specified by 'fieldMask' are actually updated. All other fields are left as-is.

func (*PGClient) Conn

func (p *PGClient) Conn(ctx context.Context) (*ConnPGClient, error)

func (*PGClient) DeleteUser

func (p *PGClient) DeleteUser(
	ctx context.Context,
	id int64,
	opts ...pggen.DeleteOpt,
) error

func (*PGClient) GetUser

func (p *PGClient) GetUser(
	ctx context.Context,
	id int64,
	opts ...pggen.GetOpt,
) (*User, error)

func (*PGClient) GetUsersByNullableNickname

func (p *PGClient) GetUsersByNullableNickname(
	ctx context.Context,
	arg1 *string,
) (ret []User, err error)

This query looks up users by their nickname, even if that nickname is NULL.

Note the funny `nickname = $1 OR (nickname IS NULL AND $1 IS NULL)` construct. This is a common pattern when querying based on possibly-null parameters. The reason for this has to do with SQL's trinary logic and null propigation. In the context of of most programming languages nulls mean something like "a reference to nothing", but in SQL it is better to think of NULL as meaning "unknown". What is `nickname = UNKNOWN`? Well, we don't know what is on the rhs, so the whole thing is `UNKNOWN`. What about `UNKNOWN OR true`? Well, all we need to know is that one side of the OR is true in order for the whole thing to be true, so the whole expression is `true`.

If we just wrote `WHERE nickname = $1` as would make sense in most programming languages, we would end up with `WHERE UNKNOWN` when `$1` is NULL, and SQL will only return queries where it knows for sure that the WHERE condition is true, so we would never be able to return any results when `$1` is NULL. If that was the case there would be no point in generating code for nullable arguments in the first place.

func (*PGClient) GetUsersByNullableNicknameQuery

func (p *PGClient) GetUsersByNullableNicknameQuery(
	ctx context.Context,
	arg1 *string,
) (*sql.Rows, error)

This query looks up users by their nickname, even if that nickname is NULL.

Note the funny `nickname = $1 OR (nickname IS NULL AND $1 IS NULL)` construct. This is a common pattern when querying based on possibly-null parameters. The reason for this has to do with SQL's trinary logic and null propigation. In the context of of most programming languages nulls mean something like "a reference to nothing", but in SQL it is better to think of NULL as meaning "unknown". What is `nickname = UNKNOWN`? Well, we don't know what is on the rhs, so the whole thing is `UNKNOWN`. What about `UNKNOWN OR true`? Well, all we need to know is that one side of the OR is true in order for the whole thing to be true, so the whole expression is `true`.

If we just wrote `WHERE nickname = $1` as would make sense in most programming languages, we would end up with `WHERE UNKNOWN` when `$1` is NULL, and SQL will only return queries where it knows for sure that the WHERE condition is true, so we would never be able to return any results when `$1` is NULL. If that was the case there would be no point in generating code for nullable arguments in the first place.

func (*PGClient) Handle

func (p *PGClient) Handle() pggen.DBHandle

func (*PGClient) InsertUser

func (p *PGClient) InsertUser(
	ctx context.Context,
	value *User,
	opts ...pggen.InsertOpt,
) (ret int64, err error)

Insert a User into the database. Returns the primary key of the inserted row.

func (*PGClient) ListUser

func (p *PGClient) ListUser(
	ctx context.Context,
	ids []int64,
	opts ...pggen.ListOpt,
) (ret []User, err error)

func (*PGClient) UpdateUser

func (p *PGClient) UpdateUser(
	ctx context.Context,
	value *User,
	fieldMask pggen.FieldSet,
	opts ...pggen.UpdateOpt,
) (ret int64, err error)

Update a User. 'value' must at the least have a primary key set. The 'fieldMask' field set indicates which fields should be updated in the database.

Returns the primary key of the updated row.

func (*PGClient) UpsertUser

func (p *PGClient) UpsertUser(
	ctx context.Context,
	value *User,
	constraintNames []string,
	fieldMask pggen.FieldSet,
	opts ...pggen.UpsertOpt,
) (ret int64, err error)

Upsert a User value. If the given value conflicts with an existing row in the database, use the provided value to update that row rather than inserting it. Only the fields specified by 'fieldMask' are actually updated. All other fields are left as-is.

func (*PGClient) UserBulkFillIncludes

func (p *PGClient) UserBulkFillIncludes(
	ctx context.Context,
	recs []*User,
	includes *include.Spec,
	opts ...pggen.IncludeOpt,
) error

func (*PGClient) UserFillIncludes

func (p *PGClient) UserFillIncludes(
	ctx context.Context,
	rec *User,
	includes *include.Spec,
	opts ...pggen.IncludeOpt,
) error

type TxPGClient

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

A postgres client that operates within a transaction. Supports all the same generated methods that PGClient does.

func (*TxPGClient) BulkDeleteUser

func (tx *TxPGClient) BulkDeleteUser(
	ctx context.Context,
	ids []int64,
	opts ...pggen.DeleteOpt,
) error

func (*TxPGClient) BulkInsertUser

func (tx *TxPGClient) BulkInsertUser(
	ctx context.Context,
	values []User,
	opts ...pggen.InsertOpt,
) ([]int64, error)

Insert a list of User. Returns a list of the primary keys of the inserted rows.

func (*TxPGClient) BulkUpsertUser

func (tx *TxPGClient) BulkUpsertUser(
	ctx context.Context,
	values []User,
	constraintNames []string,
	fieldMask pggen.FieldSet,
	opts ...pggen.UpsertOpt,
) (ret []int64, err error)

Upsert a set of User values. If any of the given values conflict with existing rows in the database, use the provided values to update the rows which exist in the database rather than inserting them. Only the fields specified by 'fieldMask' are actually updated. All other fields are left as-is.

func (*TxPGClient) Commit

func (tx *TxPGClient) Commit() error

func (*TxPGClient) DeleteUser

func (tx *TxPGClient) DeleteUser(
	ctx context.Context,
	id int64,
	opts ...pggen.DeleteOpt,
) error

func (*TxPGClient) GetUser

func (tx *TxPGClient) GetUser(
	ctx context.Context,
	id int64,
	opts ...pggen.GetOpt,
) (*User, error)

func (*TxPGClient) GetUsersByNullableNickname

func (tx *TxPGClient) GetUsersByNullableNickname(
	ctx context.Context,
	arg1 *string,
) (ret []User, err error)

This query looks up users by their nickname, even if that nickname is NULL.

Note the funny `nickname = $1 OR (nickname IS NULL AND $1 IS NULL)` construct. This is a common pattern when querying based on possibly-null parameters. The reason for this has to do with SQL's trinary logic and null propigation. In the context of of most programming languages nulls mean something like "a reference to nothing", but in SQL it is better to think of NULL as meaning "unknown". What is `nickname = UNKNOWN`? Well, we don't know what is on the rhs, so the whole thing is `UNKNOWN`. What about `UNKNOWN OR true`? Well, all we need to know is that one side of the OR is true in order for the whole thing to be true, so the whole expression is `true`.

If we just wrote `WHERE nickname = $1` as would make sense in most programming languages, we would end up with `WHERE UNKNOWN` when `$1` is NULL, and SQL will only return queries where it knows for sure that the WHERE condition is true, so we would never be able to return any results when `$1` is NULL. If that was the case there would be no point in generating code for nullable arguments in the first place.

func (*TxPGClient) GetUsersByNullableNicknameQuery

func (tx *TxPGClient) GetUsersByNullableNicknameQuery(
	ctx context.Context,
	arg1 *string,
) (*sql.Rows, error)

This query looks up users by their nickname, even if that nickname is NULL.

Note the funny `nickname = $1 OR (nickname IS NULL AND $1 IS NULL)` construct. This is a common pattern when querying based on possibly-null parameters. The reason for this has to do with SQL's trinary logic and null propigation. In the context of of most programming languages nulls mean something like "a reference to nothing", but in SQL it is better to think of NULL as meaning "unknown". What is `nickname = UNKNOWN`? Well, we don't know what is on the rhs, so the whole thing is `UNKNOWN`. What about `UNKNOWN OR true`? Well, all we need to know is that one side of the OR is true in order for the whole thing to be true, so the whole expression is `true`.

If we just wrote `WHERE nickname = $1` as would make sense in most programming languages, we would end up with `WHERE UNKNOWN` when `$1` is NULL, and SQL will only return queries where it knows for sure that the WHERE condition is true, so we would never be able to return any results when `$1` is NULL. If that was the case there would be no point in generating code for nullable arguments in the first place.

func (*TxPGClient) Handle

func (tx *TxPGClient) Handle() pggen.DBHandle

func (*TxPGClient) InsertUser

func (tx *TxPGClient) InsertUser(
	ctx context.Context,
	value *User,
	opts ...pggen.InsertOpt,
) (ret int64, err error)

Insert a User into the database. Returns the primary key of the inserted row.

func (*TxPGClient) ListUser

func (tx *TxPGClient) ListUser(
	ctx context.Context,
	ids []int64,
	opts ...pggen.ListOpt,
) (ret []User, err error)

func (*TxPGClient) Rollback

func (tx *TxPGClient) Rollback() error

func (*TxPGClient) UpdateUser

func (tx *TxPGClient) UpdateUser(
	ctx context.Context,
	value *User,
	fieldMask pggen.FieldSet,
	opts ...pggen.UpdateOpt,
) (ret int64, err error)

Update a User. 'value' must at the least have a primary key set. The 'fieldMask' field set indicates which fields should be updated in the database.

Returns the primary key of the updated row.

func (*TxPGClient) UpsertUser

func (tx *TxPGClient) UpsertUser(
	ctx context.Context,
	value *User,
	constraintNames []string,
	fieldMask pggen.FieldSet,
	opts ...pggen.UpsertOpt,
) (ret int64, err error)

Upsert a User value. If the given value conflicts with an existing row in the database, use the provided value to update that row rather than inserting it. Only the fields specified by 'fieldMask' are actually updated. All other fields are left as-is.

func (*TxPGClient) UserBulkFillIncludes

func (tx *TxPGClient) UserBulkFillIncludes(
	ctx context.Context,
	recs []*User,
	includes *include.Spec,
	opts ...pggen.IncludeOpt,
) error

func (*TxPGClient) UserFillIncludes

func (tx *TxPGClient) UserFillIncludes(
	ctx context.Context,
	rec *User,
	includes *include.Spec,
	opts ...pggen.IncludeOpt,
) error

type User

type User struct {
	Id       int64   `gorm:"column:id;is_primary"`
	Email    string  `gorm:"column:email"`
	Nickname *string `gorm:"column:nickname"`
}

func (*User) Scan

func (r *User) Scan(ctx context.Context, client *PGClient, rs *sql.Rows) error

Jump to

Keyboard shortcuts

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