models

package
v1.6.35 Latest Latest
Warning

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

Go to latest
Published: May 30, 2025 License: GPL-3.0 Imports: 16 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]
)
View Source
var ColumnNames = struct {
	Records recordColumnNames
}{
	Records: recordColumnNames{
		Key:        "key",
		Format:     "format",
		Value:      "value",
		Created:    "created",
		Modified:   "modified",
		Expires:    "expires",
		Deleted:    "deleted",
		Secret:     "secret",
		Crownjewel: "crownjewel",
	},
}
View Source
var ErrUniqueConstraint = &UniqueConstraintError{s: ""}

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

View Source
var RecordColumns = buildRecordColumns("records")
View Source
var Records = sqlite.NewTablex[*Record, RecordSlice, *RecordSetter]("", "records")

Records contains methods to work with the records table

View Source
var TableNames = struct {
	Records string
}{
	Records: "records",
}

Functions

func RecordExists

func RecordExists(ctx context.Context, exec bob.Executor, KeyPK string) (bool, error)

RecordExists checks the presence of a single record by primary key

func Where

func Where[Q sqlite.Filterable]() struct {
	Records recordWhere[Q]
}

Types

type Record

type Record struct {
	Key        string           `db:"key,pk" `
	Format     null.Val[int16]  `db:"format" `
	Value      null.Val[[]byte] `db:"value" `
	Created    int64            `db:"created" `
	Modified   int64            `db:"modified" `
	Expires    int64            `db:"expires" `
	Deleted    int64            `db:"deleted" `
	Secret     bool             `db:"secret" `
	Crownjewel bool             `db:"crownjewel" `
}

Record is an object representing the database table.

func FindRecord

func FindRecord(ctx context.Context, exec bob.Executor, KeyPK string, cols ...string) (*Record, error)

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

func (*Record) AfterQueryHook

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

AfterQueryHook is called after Record is retrieved from the database

func (*Record) Delete

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

Delete deletes a single Record record with an executor

func (*Record) PrimaryKeyVals

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

PrimaryKeyVals returns the primary key values of the Record

func (*Record) Reload

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

Reload refreshes the Record using the executor

func (*Record) Update

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

Update uses an executor to update the Record

type RecordSetter

type RecordSetter struct {
	Key        omit.Val[string]     `db:"key,pk" `
	Format     omitnull.Val[int16]  `db:"format" `
	Value      omitnull.Val[[]byte] `db:"value" `
	Created    omit.Val[int64]      `db:"created" `
	Modified   omit.Val[int64]      `db:"modified" `
	Expires    omit.Val[int64]      `db:"expires" `
	Deleted    omit.Val[int64]      `db:"deleted" `
	Secret     omit.Val[bool]       `db:"secret" `
	Crownjewel omit.Val[bool]       `db:"crownjewel" `
}

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

func (*RecordSetter) Apply

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

func (RecordSetter) Expressions

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

func (RecordSetter) Overwrite

func (s RecordSetter) Overwrite(t *Record)

func (RecordSetter) SetColumns

func (s RecordSetter) SetColumns() []string

func (RecordSetter) UpdateMod

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

type RecordSlice

type RecordSlice []*Record

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

func (RecordSlice) AfterQueryHook

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

AfterQueryHook is called after RecordSlice is retrieved from the database

func (RecordSlice) DeleteAll

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

func (RecordSlice) DeleteMod

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

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

func (RecordSlice) ReloadAll

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

func (RecordSlice) UpdateAll

func (o RecordSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals RecordSetter) error

func (RecordSlice) UpdateMod

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

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

type RecordsQuery

type RecordsQuery = *sqlite.ViewQuery[*Record, RecordSlice]

RecordsQuery is a query on the records table

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

Jump to

Keyboard shortcuts

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