models

package
v0.0.0-...-a8451c0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SelectWhere = Where[*dialect.SelectQuery]()
	InsertWhere = Where[*dialect.InsertQuery]()
	UpdateWhere = Where[*dialect.UpdateQuery]()
	DeleteWhere = Where[*dialect.DeleteQuery]()
)
View Source
var (
	SelectJoins = getJoins[*dialect.SelectQuery]()
	UpdateJoins = getJoins[*dialect.UpdateQuery]()
	DeleteJoins = getJoins[*dialect.DeleteQuery]()
)
View Source
var ColumnNames = struct {
	Users userColumnNames
}{
	Users: userColumnNames{
		ID:        "id",
		Name:      "name",
		CreatedAt: "created_at",
		UpdatedAt: "updated_at",
	},
}
View Source
var ErrUniqueConstraint = &UniqueConstraintError{s: ""}

ErrUniqueConstraint captures all unique constraint errors by explicitly leaving `s` empty.

View Source
var TableNames = struct {
	Users string
}{
	Users: "users",
}
View Source
var UserColumns = buildUserColumns("users")
View Source
var UserErrors = &userErrors{
	ErrUniqueUsersPkey: &UniqueConstraintError{s: "users_pkey"},
}
View Source
var Users = psql.NewTablex[*User, UserSlice, *UserSetter]("", "users")

Users contains methods to work with the users table

Functions

func UserExists

func UserExists(ctx context.Context, exec bob.Executor, IDPK uuid.UUID) (bool, error)

UserExists checks the presence of a single record by primary key

func Where

func Where[Q psql.Filterable]() struct {
	Users userWhere[Q]
}

Types

type UniqueConstraintError

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

func (*UniqueConstraintError) Error

func (e *UniqueConstraintError) Error() string

func (*UniqueConstraintError) Is

func (e *UniqueConstraintError) Is(target error) bool

type User

type User struct {
	ID        uuid.UUID `db:"id,pk" `
	Name      string    `db:"name" `
	CreatedAt time.Time `db:"created_at" `
	UpdatedAt time.Time `db:"updated_at" `
}

User is an object representing the database table.

func FindUser

func FindUser(ctx context.Context, exec bob.Executor, IDPK uuid.UUID, cols ...string) (*User, error)

FindUser retrieves a single record by primary key If cols is empty Find will return all columns.

func (*User) AfterQueryHook

func (o *User) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error

AfterQueryHook is called after User is retrieved from the database

func (*User) Delete

func (o *User) Delete(ctx context.Context, exec bob.Executor) error

Delete deletes a single User record with an executor

func (*User) PrimaryKeyVals

func (o *User) PrimaryKeyVals() bob.Expression

PrimaryKeyVals returns the primary key values of the User

func (*User) Reload

func (o *User) Reload(ctx context.Context, exec bob.Executor) error

Reload refreshes the User using the executor

func (*User) Update

func (o *User) Update(ctx context.Context, exec bob.Executor, s *UserSetter) error

Update uses an executor to update the User

type UserSetter

type UserSetter struct {
	ID        omit.Val[uuid.UUID] `db:"id,pk" `
	Name      omit.Val[string]    `db:"name" `
	CreatedAt omit.Val[time.Time] `db:"created_at" `
	UpdatedAt omit.Val[time.Time] `db:"updated_at" `
}

UserSetter is used for insert/upsert/update operations All values are optional, and do not have to be set Generated columns are not included

func (*UserSetter) Apply

func (s *UserSetter) Apply(q *dialect.InsertQuery)

func (UserSetter) Expressions

func (s UserSetter) Expressions(prefix ...string) []bob.Expression

func (UserSetter) Overwrite

func (s UserSetter) Overwrite(t *User)

func (UserSetter) SetColumns

func (s UserSetter) SetColumns() []string

func (UserSetter) UpdateMod

func (s UserSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery]

type UserSlice

type UserSlice []*User

UserSlice is an alias for a slice of pointers to User. This should almost always be used instead of []*User.

func (UserSlice) AfterQueryHook

func (o UserSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error

AfterQueryHook is called after UserSlice is retrieved from the database

func (UserSlice) DeleteAll

func (o UserSlice) DeleteAll(ctx context.Context, exec bob.Executor) error

func (UserSlice) DeleteMod

func (o UserSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery]

DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"

func (UserSlice) ReloadAll

func (o UserSlice) ReloadAll(ctx context.Context, exec bob.Executor) error

func (UserSlice) UpdateAll

func (o UserSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals UserSetter) error

func (UserSlice) UpdateMod

func (o UserSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery]

UpdateMod modifies an update query with "WHERE primary_key IN (o...)"

type UsersQuery

type UsersQuery = *psql.ViewQuery[*User, UserSlice]

UsersQuery is a query on the users table

Jump to

Keyboard shortcuts

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