model

package
v0.3.16 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package model contains Schema type and methods

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MoveItemTx

func MoveItemTx[I, D any](rqtx *my.Request, insertSchema *Schema[I], item *I, deleteSchema *Schema[D], deleteCondition qb.Condition) error

MoveItemTx inserts an item to the insertSchema and deletes the corresponding item from the deleteSchema, as part of a transaction

Types

type AutoItem

type AutoItem struct {
	IDField
	CreatedAtField
	IsActiveField
}

AutoItem combines IDField, CreatedAtField, IsActiveField

func (*AutoItem) Initialize

func (x *AutoItem) Initialize()

Initialize sets the ID, CreatedAt, IsActive to default values

type CodeField

type CodeField struct {
	Code string
}

CodeField is an embeddable Code property

func (CodeField) GetCode

func (x CodeField) GetCode() string

type CreatedAtField

type CreatedAtField struct {
	CreatedAt DateTime
}

CreatedAtField is an embeddable CreatedAt property

func (CreatedAtField) GetDateTime

func (x CreatedAtField) GetDateTime() DateTime

type Date

type Date = clock.Date

type DateTime

type DateTime = clock.DateTime

type GetOrCreateAndLockParams

type GetOrCreateAndLockParams[T any] struct {
	GetOrCreateParams[T]
	LockField       *bool
	LockConditionFn func(T) qb.Condition
}

type GetOrCreateParams

type GetOrCreateParams[T any] struct {
	Name          string
	Owner         string
	PreCondition  qb.Condition
	PostCondition qb.DualCondition[T]
	NewFn         func() T
	UpdateFn      func(*T, ID)
}

type ID

type ID = uint

type IDField

type IDField struct {
	ID ID `json:"-"`
}

IDField is an embeddable ID property

func (*IDField) GetID

func (x *IDField) GetID() ID

func (*IDField) SetID

func (x *IDField) SetID(id ID)

type Identity

type Identity struct {
	IDField
	CodeField
}

Identity combines IDField and CodeField

type IsActiveField

type IsActiveField struct {
	IsActive bool
}

IsActiveField is an embeddable IsActive property

func (*IsActiveField) GetIsActive

func (x *IsActiveField) GetIsActive() bool

func (*IsActiveField) SetIsActive

func (x *IsActiveField) SetIsActive(isActive bool)

type Item

type Item struct {
	AutoItem
	CodeField
}

Item combines IDField, CreatedAtField, IsActiveField, CodeField

func (*Item) Initialize

func (x *Item) Initialize()

Initialize sets the ID, CreatedAt, IsActive to default values

type Schema

type Schema[T any] struct {
	Name     string
	Ref      *T
	Table    string
	Reader   qb.RowReader[T]
	Instance *qb.Instance
}

func AddSchema

func AddSchema[T any](this *qb.Instance, structRef *T, table string, errs []error) *Schema[T]

AddSchema adds a new Schema and adds error to the error list if any

func AddSharedSchema

func AddSharedSchema[T any](this *qb.Instance, structRef *T, errs []error) *Schema[T]

AddSharedSchema adds a new shared Schema (no table) and adds error to the error list if any

func NewSchema

func NewSchema[T any](this *qb.Instance, structRef *T, table string) (*Schema[T], error)

NewSchema creates a new Schema and registers its type to qb

func NewSharedSchema

func NewSharedSchema[T any](this *qb.Instance, structRef *T) (*Schema[T], error)

NewSharedSchema creates a new shared Schema (no table)

func (*Schema[T]) Count

func (s *Schema[T]) Count(rq *my.Request, condition qb.Condition) (int, error)

Count performs a CountQuery at schema table

func (*Schema[T]) CountAt

func (s *Schema[T]) CountAt(rq *my.Request, condition qb.Condition, table string) (int, error)

CountAt performs a CountQuery at the given table

func (*Schema[T]) Delete

func (s *Schema[T]) Delete(rq *my.Request, condition qb.Condition) (int, error)

Delete performs a DeleteQuery on the schema table using the given condition

func (*Schema[T]) DeleteAt

func (s *Schema[T]) DeleteAt(rq *my.Request, condition qb.Condition, table string) (int, error)

DeleteAt performs a DeleteQuery on the given table using the given condition

func (*Schema[T]) DeleteTx

func (s *Schema[T]) DeleteTx(rqtx *my.Request, condition qb.Condition) (int, error)

DeleteTx performs a DeleteQuery as part of a transaction on the schema table using the given condition

func (*Schema[T]) DeleteTxAt

func (s *Schema[T]) DeleteTxAt(rqtx *my.Request, condition qb.Condition, table string) (int, error)

DeleteTxAt performs a DeleteQuery as part of a transaction on the given table using the given condition

func (*Schema[T]) Get

func (s *Schema[T]) Get(rq *my.Request, condition qb.Condition) (T, error)

Get performs a SelectRowQuery at schema table

func (*Schema[T]) GetAllRows

func (s *Schema[T]) GetAllRows(rq *my.Request) ([]T, error)

GetAllRows performs a SelectRowsQuery without condition at schema table

func (*Schema[T]) GetAllRowsAt

func (s *Schema[T]) GetAllRowsAt(rq *my.Request, table string) ([]T, error)

GetAllRowsAt performs a SelectRowsQuery without condition at given table

func (*Schema[T]) GetAllRowsOnly

func (s *Schema[T]) GetAllRowsOnly(rq *my.Request, fieldNames ...string) ([]dict.Object, error)

GetAllRowsOnly performs a SelectRowsQuery without condition at schema table and prunes the items with given field names

func (*Schema[T]) GetAllRowsOnlyAt

func (s *Schema[T]) GetAllRowsOnlyAt(rq *my.Request, table string, fieldNames ...string) ([]dict.Object, error)

GetAllRowsOnlyAt performs a SelectRowsQuery without condition at given table and prunes the items with given field names

func (*Schema[T]) GetAndLockTx

func (s *Schema[T]) GetAndLockTx(rqtx *my.Request, lockField *bool, selectCondition qb.Condition, lockConditionFn func(T) qb.Condition) (T, error)

GetAndLockTx gets the item and locks it as part of a transaction Note: no need to include IsLocked = true/false in conditions, as this function adds it

func (*Schema[T]) GetAndLockTxItems

func (s *Schema[T]) GetAndLockTxItems(rqtx *my.Request, lockField *bool, selectCondition qb.Condition, lockConditionFn func([]T) qb.Condition, numItems int) ([]T, error)

GetAndLockTxItems gets a list of items and locks all of them as part of a transaction Note: no need to include IsLocked = true/false in conditions, as this function adds it

func (*Schema[T]) GetAt

func (s *Schema[T]) GetAt(rq *my.Request, condition qb.Condition, table string) (T, error)

GetAt performs a SelectRowQuery at given table

func (*Schema[T]) GetOnly

func (s *Schema[T]) GetOnly(rq *my.Request, condition qb.Condition, fieldNames ...string) (dict.Object, error)

GetOnly performs a SelectRowQuery at schema table and prunes the item with given field names

func (*Schema[T]) GetOnlyAt

func (s *Schema[T]) GetOnlyAt(rq *my.Request, condition qb.Condition, table string, fieldNames ...string) (dict.Object, error)

GetOnlyAt performs a SelectRowQuery at given table and prunes the item with given field names

func (*Schema[T]) GetOrCreate

func (s *Schema[T]) GetOrCreate(rq *my.Request, p *GetOrCreateParams[T]) (T, error)

GetOrCreate gets the item if it exists, otherwise creates and returns it

func (*Schema[T]) GetOrCreateAndLockTx

func (s *Schema[T]) GetOrCreateAndLockTx(rqtx *my.Request, p *GetOrCreateAndLockParams[T]) (T, error)

GetOrCreateAndLockTx runs GetOrCreate and locks the item as part of a transaction Note: no need to include IsLocked = true/false in conditions, as this function adds it

func (*Schema[T]) GetOrCreateTx

func (s *Schema[T]) GetOrCreateTx(rqtx *my.Request, p *GetOrCreateParams[T]) (T, error)

GetOrCreateTx gets the item if it exists, otherwise creates it as part of a transaction, and return the item

func (*Schema[T]) GetRows

func (s *Schema[T]) GetRows(rq *my.Request, condition qb.Condition) ([]T, error)

GetRows performs a SelectRowsQuery at schema table

func (*Schema[T]) GetRowsAt

func (s *Schema[T]) GetRowsAt(rq *my.Request, condition qb.Condition, table string) ([]T, error)

GetRowsAt performs a SelectRowsQuery at given table

func (*Schema[T]) GetRowsOnly

func (s *Schema[T]) GetRowsOnly(rq *my.Request, condition qb.Condition, fieldNames ...string) ([]dict.Object, error)

GetRowsOnly performs a SelectRowsQuery at schema table and prunes the items with given field names

func (*Schema[T]) GetRowsOnlyAt

func (s *Schema[T]) GetRowsOnlyAt(rq *my.Request, condition qb.Condition, table string, fieldNames ...string) ([]dict.Object, error)

GetRowsOnlyAt performs a SelectRowsQuery at given table and prunes the items with given field names

func (*Schema[T]) Insert

func (s *Schema[T]) Insert(rq *my.Request, item *T) (ID, error)

Insert performs an InsertRowQuery at schema table

func (*Schema[T]) InsertAt

func (s *Schema[T]) InsertAt(rq *my.Request, item *T, table string) (ID, error)

InsertAt performs an InsertRowQuery at given table

func (*Schema[T]) InsertRows

func (s *Schema[T]) InsertRows(rq *my.Request, items []T) error

InsertRows performs an InsertRowsQuery at schema table

func (*Schema[T]) InsertRowsAt

func (s *Schema[T]) InsertRowsAt(rq *my.Request, items []T, table string) error

InsertRowsAt performs an InsertRowsQuery at given table

func (*Schema[T]) InsertTx

func (s *Schema[T]) InsertTx(rqtx *my.Request, item *T) (ID, error)

InsertTx performs an InsertRowQuery as part of a transaction at schema table

func (*Schema[T]) InsertTxAt

func (s *Schema[T]) InsertTxAt(rqtx *my.Request, item *T, table string) (ID, error)

InsertTxAt performs an InsertRowQuery as part of a transaction at given table

func (*Schema[T]) InsertTxRows

func (s *Schema[T]) InsertTxRows(rqtx *my.Request, items []T) error

InsertTxRows performs an InsertRowsQuery as part of a transaction at schema table

func (*Schema[T]) InsertTxRowsAt

func (s *Schema[T]) InsertTxRowsAt(rqtx *my.Request, items []T, table string) error

InsertTxRowsAt performs an InsertRowsQuery as part of a transaction at given table

func (*Schema[T]) SetFlag

func (s *Schema[T]) SetFlag(rq *my.Request, condition qb.Condition, field *bool, flag bool) error

SetFlag updates the booleanField = flag at schema table

func (*Schema[T]) SetFlagAt

func (s *Schema[T]) SetFlagAt(rq *my.Request, condition qb.Condition, field *bool, flag bool, table string) error

SetFlagAt updates the booleanField = flag at given table

func (*Schema[T]) SetFlags

func (s *Schema[T]) SetFlags(rq *my.Request, condition qb.Condition, field *bool, flag bool, numItems int) error

SetFlags updates the booleanField = flag at schema table affecting multiple rows

func (*Schema[T]) SetFlagsAt

func (s *Schema[T]) SetFlagsAt(rq *my.Request, condition qb.Condition, field *bool, flag bool, numItems int, table string) error

SetFlagsAt updates the booleanField = flag at given table affecting multiple rows

func (*Schema[T]) SetTxFlag

func (s *Schema[T]) SetTxFlag(rqtx *my.Request, condition qb.Condition, field *bool, flag bool) error

SetTxFlag updates the booleanField = flag as part of transaction at schema table

func (*Schema[T]) SetTxFlagAt

func (s *Schema[T]) SetTxFlagAt(rqtx *my.Request, condition qb.Condition, field *bool, flag bool, table string) error

SetTxFlagAt updates the booleanField = flag as part of transaction at given table

func (*Schema[T]) SetTxFlags

func (s *Schema[T]) SetTxFlags(rqtx *my.Request, condition qb.Condition, field *bool, flag bool, numItems int) error

SetTxFlags updates the booleanField = flag as part of transaction at schema table affecting multiple rows

func (*Schema[T]) SetTxFlagsAt

func (s *Schema[T]) SetTxFlagsAt(rqtx *my.Request, condition qb.Condition, field *bool, flag bool, numItems int, table string) error

SetTxFlagsAt updates the booleanField = flag as part of transaction at given table affecting multiple rows

func (*Schema[T]) Sum

func (s *Schema[T]) Sum(rq *my.Request, columns []string, reader qb.RowReader[T], condition qb.Condition) (T, error)

Sum performs a SumQuery at schema table

func (*Schema[T]) SumAt

func (s *Schema[T]) SumAt(rq *my.Request, columns []string, reader qb.RowReader[T], condition qb.Condition, table string) (T, error)

SumAt performs a SumQuery at the given table

func (*Schema[T]) ToggleCode

func (s *Schema[T]) ToggleCode(rq *my.Request, code string, isActive bool, Items *Schema[Item]) error

ToggleCode toggles a row on/off using the given Code at the schema table

func (*Schema[T]) ToggleCodeAt

func (s *Schema[T]) ToggleCodeAt(rq *my.Request, code string, isActive bool, table string, Items *Schema[Item]) error

ToggleCodeAt toggles a row on/off using the given Code at the given table

func (*Schema[T]) ToggleID

func (s *Schema[T]) ToggleID(rq *my.Request, id ID, isActive bool, Items *Schema[Item]) error

ToggleID toggles a row on/off using the given ID at the schema table

func (*Schema[T]) ToggleIDAt

func (s *Schema[T]) ToggleIDAt(rq *my.Request, id ID, isActive bool, table string, Items *Schema[Item]) error

ToggleIDAt toggles a row on/off using the given ID at the given table

func (*Schema[T]) ToggleTxCode

func (s *Schema[T]) ToggleTxCode(rqtx *my.Request, code string, isActive bool, Items *Schema[Item]) error

ToggleTxCode toggles a row on/off as part of a transaction using the given Code at the schema table

func (*Schema[T]) ToggleTxCodeAt

func (s *Schema[T]) ToggleTxCodeAt(rqtx *my.Request, code string, isActive bool, table string, Items *Schema[Item]) error

ToggleTxCodeAt toggles a row on/off as part of a transaction using the given Code at the given table

func (*Schema[T]) ToggleTxID

func (s *Schema[T]) ToggleTxID(rqtx *my.Request, id ID, isActive bool, Items *Schema[Item]) error

ToggleTxID toggles a row on/off as part of a transaction using the given ID at the schema table

func (*Schema[T]) ToggleTxIDAt

func (s *Schema[T]) ToggleTxIDAt(rqtx *my.Request, id ID, isActive bool, table string, Items *Schema[Item]) error

ToggleTxIDAt toggles a row on/off as part of a transaction using the given ID at the given table

func (*Schema[T]) Update

func (s *Schema[T]) Update(rq *my.Request, updateFn UpdateFn[T], condition qb.Condition) error

Update performs an UpdateQuery using UpdateFn at schema table

func (*Schema[T]) UpdateAndGetTx

func (s *Schema[T]) UpdateAndGetTx(rqtx *my.Request, updateFn UpdateFn[T], updateCondition, selectCondition qb.Condition) (T, error)

UpdateAndGetTx updates one time and gets it as part of a transaction

func (*Schema[T]) UpdateAt

func (s *Schema[T]) UpdateAt(rq *my.Request, updateFn UpdateFn[T], condition qb.Condition, table string) error

UpdateAt performs an UpdateQuery using UpdateFn at given table

func (*Schema[T]) UpdateFields

func (s *Schema[T]) UpdateFields(rq *my.Request, updates qb.FieldUpdates, condition qb.Condition) error

UpdateFields performs an UpdateQuery using FieldUpdates at schema table

func (*Schema[T]) UpdateFieldsAt

func (s *Schema[T]) UpdateFieldsAt(rq *my.Request, updates qb.FieldUpdates, condition qb.Condition, table string) error

UpdateFieldsAt performs an UpdateQuery using FieldUpdates at given table

func (*Schema[T]) UpdateTx

func (s *Schema[T]) UpdateTx(rqtx *my.Request, updateFn UpdateFn[T], condition qb.Condition) error

UpdateTx performs an UpdateQuery using UpdateFn as part of a transaction at schema table

func (*Schema[T]) UpdateTxAt

func (s *Schema[T]) UpdateTxAt(rqtx *my.Request, updateFn UpdateFn[T], condition qb.Condition, table string) error

UpdateTxAt performs an UpdateQuery using UpdateFn as part of a transaction at given table

func (*Schema[T]) UpdateTxFields

func (s *Schema[T]) UpdateTxFields(rqtx *my.Request, updates qb.FieldUpdates, condition qb.Condition) error

UpdateTxFields performs an UpdateQuery as part of a transaction using FieldUpdates at schema table

func (*Schema[T]) UpdateTxFieldsAt

func (s *Schema[T]) UpdateTxFieldsAt(rqtx *my.Request, updates qb.FieldUpdates, condition qb.Condition, table string) error

UpdateTxFieldsAt performs an UpdateQuery as part of a transaction using FieldUpdates at given table

type UpdateFn

type UpdateFn[T any] = func(*qb.Instance, *qb.UpdateQuery[T])

UpdateFn is a function that decorates the UpdateQuery with necessary updates

Jump to

Keyboard shortcuts

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