Documentation
¶
Index ¶
- Variables
- func AssertIsResolveError(t *testing.T, err error)
- func AssertRowValuesDeepEqual(t *testing.T, x []map[string]any, y []*Row)
- func AssertValuesDeepEqual(t *testing.T, x map[string]any, y Values)
- func ResolveCheck(ctx context.Context, data *Data, options ...ResolveOption) error
- func ResolveCheckCallback(ctx context.Context, resolveInfo ResolveInfo, values ValuesMutable) error
- func ValuesGet[T any](values Values, fieldName string) (val T, exists bool, isType bool)
- type Data
- func (d *Data) Add(tableID TableID, value ValuesMutable, options ...DataAddOption)
- func (d *Data) AddDependencies(tableID TableID, dependencies ...TableID)
- func (d *Data) AddValues(tableID TableID, values ...ValuesMutable)
- func (d *Data) AddWithID(tableID TableID, values ValuesMutable, options ...DataAddOption) InternalIDRef
- func (d *Data) Err() error
- func (d *Data) FindInternalIDRow(tableID TableID, internalID uuid.UUID) (*Row, error)
- func (d *Data) FindInternalIDValue(value ValueInternalIDData) (any, error)
- func (d *Data) FindRefIDRow(tableID TableID, refID RefID) (*Row, error)
- func (d *Data) FindRefIDRowValue(value ValueRefIDData) (any, error)
- func (d *Data) FindTableRow(tableID TableID, f func(*Row) (bool, error)) (*Row, error)
- func (d *Data) FindTableRowValue(tableID TableID, fieldName string, f func(*Row) (bool, error)) (any, error)
- func (d *Data) FindTableRows(tableID TableID, f func(*Row) (bool, error)) (ret []*Row, err error)
- func (d *Data) Update(query UpdateQuery, action UpdateAction)
- func (d *Data) UpdateAfter(afterRow QueryRow, query UpdateQuery, action UpdateAction)
- func (d *Data) WalkRows(f func(TableID, *Row) bool)
- func (d *Data) WalkTableRows(tableID TableID, f func(*Row) bool) error
- type DataAddOption
- type InternalIDRef
- type IsNotAValue
- type MapValues
- func (v MapValues) All(yield func(string, any) bool)
- func (v MapValues) Delete(fieldName ...string)
- func (v MapValues) Get(fieldName string) (val any, exists bool)
- func (v MapValues) GetDefault(fieldName string, def any) any
- func (v MapValues) GetOrNil(fieldName string) any
- func (v MapValues) Insert(seq iter.Seq2[string, any])
- func (v MapValues) Len() int
- func (v MapValues) Set(fieldName string, val any)
- type NotAValue
- type Process
- type QueryRow
- type QueryRowInternalID
- type QueryRowRefID
- type QueryRowResult
- type QueryRows
- type RefID
- type ResolveCallback
- type ResolveError
- type ResolveInfo
- type ResolveOption
- type ResolveType
- type ResolveValue
- type ResolveValueFunc
- type ResolveValueResolveData
- type ResolveValueTypeOption
- type ResolveValueUUIDData
- type ResolvedCallback
- type ResolvedData
- type Row
- type SetValueRefIDData
- type Table
- type TableID
- type TableName
- type TableNameID
- type Update
- type UpdateAction
- type UpdateActionSetValues
- type UpdateData
- type UpdateQuery
- type UpdateQueryQueryRow
- type UpdateQueryQueryRows
- type Value
- type ValueBaseTimeAddData
- type ValueBaseTimeAddDataOption
- func WithAddDate(days, hours, minutes, seconds int) ValueBaseTimeAddDataOption
- func WithAddDays(days int) ValueBaseTimeAddDataOption
- func WithAddHours(hours int) ValueBaseTimeAddDataOption
- func WithAddMinutes(minutes int) ValueBaseTimeAddDataOption
- func WithAddSeconds(seconds int) ValueBaseTimeAddDataOption
- func WithAddTime(hours, minutes, seconds int) ValueBaseTimeAddDataOption
- type ValueDefaultData
- type ValueDependencies
- type ValueErr
- type ValueFieldValueData
- type ValueFormatCallback
- type ValueFormatData
- type ValueFormatFuncData
- type ValueFunc
- type ValueGenUUIDData
- type ValueInternalIDData
- func (v ValueInternalIDData) QueryRow(data *Data) (QueryRowResult, error)
- func (v ValueInternalIDData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
- func (v ValueInternalIDData) TableDependencies() []TableID
- func (v ValueInternalIDData) UpdateQuery(keyFields []string) UpdateQuery
- type ValueMultiple
- type ValueMultipleErr
- type ValueMultipleFunc
- type ValueRefFieldValueData
- type ValueRefIDData
- func (v ValueRefIDData) QueryRow(data *Data) (QueryRowResult, error)
- func (v ValueRefIDData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
- func (v ValueRefIDData) TableDependencies() []TableID
- func (v ValueRefIDData) UpdateQuery(keyFields []string) UpdateQuery
- type ValueStaticData
- type ValueTemplateData
- type ValueUUIDData
- type Values
- type ValuesMutable
Constants ¶
This section is empty.
Variables ¶
var ( ResolveRowsStop = errors.New("stop resolve") ResolveNoRows = errors.New("no rows found") ResolveUnknownFieldName = errors.New("unknown field name") ResolveLater = errors.New("resolve later") )
var (
ErrNotFound = errors.New("not found")
)
Functions ¶
func AssertIsResolveError ¶
AssertIsResolveError assets that the error is a ResolveError.
func AssertRowValuesDeepEqual ¶
AssertRowValuesDeepEqual asserts that a slice of maps is deep-equal to a list of Row.
func AssertValuesDeepEqual ¶
AssertValuesDeepEqual asserts that a map is deep-equal to a Values.
func ResolveCheck ¶ added in v2.0.2
func ResolveCheck(ctx context.Context, data *Data, options ...ResolveOption) error
ResolveCheck checks if all dependencies between rows are resolvable.
func ResolveCheckCallback ¶ added in v2.0.2
func ResolveCheckCallback(ctx context.Context, resolveInfo ResolveInfo, values ValuesMutable) error
ResolveCheckCallback is the callback for the ResolveCheck function.
Types ¶
type Data ¶
type Data struct {
Tables map[string]*Table // map key is TableID.TableID()
Updates []Update // list of updates to be executed after all rows were added.
// contains filtered or unexported fields
}
Data contains a list of tables and their row values.
func (*Data) Add ¶
func (d *Data) Add(tableID TableID, value ValuesMutable, options ...DataAddOption)
Add adds a row to a table.
func (*Data) AddDependencies ¶
AddDependencies adds dependencies on other tables to the passed table.
func (*Data) AddValues ¶
func (d *Data) AddValues(tableID TableID, values ...ValuesMutable)
AddValues adds a list of row to a table.
func (*Data) AddWithID ¶
func (d *Data) AddWithID(tableID TableID, values ValuesMutable, options ...DataAddOption) InternalIDRef
AddWithID adds a row to a table, returning a reference to the added row.
func (*Data) FindInternalIDRow ¶
FindInternalIDRow returns a row of a table based on its internal id.
func (*Data) FindInternalIDValue ¶
func (d *Data) FindInternalIDValue(value ValueInternalIDData) (any, error)
FindInternalIDValue resolves a field value referenced in a ValueInternalID.
func (*Data) FindRefIDRow ¶
FindRefIDRow returns a row from a table using a RefID.
func (*Data) FindRefIDRowValue ¶
func (d *Data) FindRefIDRowValue(value ValueRefIDData) (any, error)
FindRefIDRowValue resolves a field value from a table using a RefID.
func (*Data) FindTableRow ¶
FindTableRow returns one row for a table where the callback returns true. If no rows where found, returns the error ResolveNoRows.
func (*Data) FindTableRowValue ¶
func (d *Data) FindTableRowValue(tableID TableID, fieldName string, f func(*Row) (bool, error)) (any, error)
FindTableRowValue uses FindTableRow to find a row, and returns one of its field's value. If no rows where found, returns the error ResolveNoRows.
func (*Data) FindTableRows ¶
FindTableRows returns a list of rows for a table where the callback returns true.
func (*Data) Update ¶
func (d *Data) Update(query UpdateQuery, action UpdateAction)
Update adds an update do be done after all records were added.
func (*Data) UpdateAfter ¶
func (d *Data) UpdateAfter(afterRow QueryRow, query UpdateQuery, action UpdateAction)
UpdateAfter will add an update to be done right after the "afterRow" record is added.
type DataAddOption ¶
type DataAddOption func(options *dataAddOptions)
DataAddOption are options for Data.Add and Data.AddWithID.
func WithDataAddResolvedCallback ¶
func WithDataAddResolvedCallback(f ResolvedCallback) DataAddOption
WithDataAddResolvedCallback adds a callback to be called when this row is resolved.
type InternalIDRef ¶
InternalIDRef is a reference to one table's row by internal id. It refers to an entire row instead of a specific field, so it don't implement Value. Use ValueForField to return a Value implementation for one of its fields. It implements QueryRow, and can return a UpdateQuery.
func NewInternalIDRef ¶
func NewInternalIDRef(tableID TableID, internalID uuid.UUID) InternalIDRef
func (InternalIDRef) QueryRow ¶
func (v InternalIDRef) QueryRow(data *Data) (QueryRowResult, error)
QueryRow is the implementation of the QueryRow interface.
func (InternalIDRef) UpdateQuery ¶
func (v InternalIDRef) UpdateQuery(keyFields []string) UpdateQuery
UpdateQuery returns an UpdateQuery targetting the referenced table row.
func (InternalIDRef) ValueForField ¶
func (v InternalIDRef) ValueForField(fieldName string) ValueInternalIDData
ValueForField returns a Value that resolves one specific field of the referenced table row.
type IsNotAValue ¶ added in v2.0.4
type IsNotAValue interface {
// contains filtered or unexported methods
}
IsNotAValue marks structs that may be confused with values to avoid using them as such.
type Process ¶
type Process interface {
Start(ctx context.Context) (context.Context, error)
Finish(ctx context.Context) error
}
Process define processes that can run alongside a Resolve operation, like a kind of plugin.
type QueryRow ¶
type QueryRow interface {
// QueryRow returns a single Row, or ErrNotFound if none found.
QueryRow(data *Data) (QueryRowResult, error)
}
type QueryRowInternalID ¶
QueryRowInternalID finds one row by a table and an internal id.
func NewQueryRowInternalID ¶
func NewQueryRowInternalID(tableID TableID, internalID uuid.UUID) QueryRowInternalID
func (QueryRowInternalID) Row ¶
func (u QueryRowInternalID) Row(data *Data) (QueryRowResult, error)
type QueryRowRefID ¶
QueryRowRefID finds one row by a table and a RefID.
func NewQueryRowRefID ¶
func NewQueryRowRefID(tableID TableID, refID RefID) QueryRowRefID
func (QueryRowRefID) Row ¶
func (u QueryRowRefID) Row(data *Data) (QueryRowResult, error)
type QueryRowResult ¶
QueryRowResult represents a row and its table.
type QueryRows ¶
type QueryRows interface {
// QueryRows returns a list of rows.
QueryRows(data *Data) ([]QueryRowResult, error)
}
type RefID ¶
type RefID string
RefID is a string value that uniquely identifies one row of one table. It is meant to be a meaningful string to be easy to reference.
type ResolveCallback ¶
type ResolveCallback func(ctx context.Context, resolveInfo ResolveInfo, values ValuesMutable) error
ResolveCallback is a callback used to resolve ResolveValue values.
type ResolveError ¶
type ResolveError struct {
Err error
}
ResolveError is the base of all returned errors.
func NewResolveError ¶
func NewResolveError(msg string) *ResolveError
func NewResolveErrorf ¶
func NewResolveErrorf(format string, args ...any) *ResolveError
func (*ResolveError) Error ¶
func (e *ResolveError) Error() string
func (*ResolveError) Unwrap ¶
func (e *ResolveError) Unwrap() error
type ResolveInfo ¶
type ResolveInfo struct {
Type ResolveType // type of the resolve (add, update).
TableID TableID // table being resolved.
UpdateKeyFields []string // if type is update, the names of the key fields to be used to update.
}
ResolveInfo is a context for resolve callbacks.
type ResolveOption ¶
type ResolveOption func(options *resolveOptions)
func WithResolveOptionProcess ¶
func WithResolveOptionProcess(process Process) ResolveOption
WithResolveOptionProcess adds a Process to the resolver.
type ResolveType ¶
type ResolveType int
const ( ResolveTypeAdd ResolveType = iota ResolveTypeUpdate )
type ResolveValue ¶
ResolveValue is a value that should be resolved by the user of the library in a callback. Usually this is used to return values generated by the database, like last insert id or created date.
type ResolveValueFunc ¶ added in v2.0.4
ResolveValueFunc is a functional implementation of ResolveValue.
func (ResolveValueFunc) ResolveValueParse ¶ added in v2.0.4
type ResolveValueResolveData ¶
type ResolveValueResolveData struct {
}
ResolveValueResolveData is a value to be resolved, without any parsing.
func ResolveValueResolve ¶
func ResolveValueResolve() ResolveValueResolveData
ResolveValueResolve is a value to be resolved, without any parsing.
func (ResolveValueResolveData) ResolveValueParse ¶ added in v2.0.4
type ResolveValueTypeOption ¶ added in v2.0.4
type ResolveValueTypeOption func(*resolveValueTypeOptions)
func WithResolveValueTypeAllowBlank ¶ added in v2.0.4
func WithResolveValueTypeAllowBlank(allowBlank bool) ResolveValueTypeOption
WithResolveValueTypeAllowBlank sets whether to allow blank values.
func WithResolveValueTypeAllowNull ¶ added in v2.0.4
func WithResolveValueTypeAllowNull(allowNull bool) ResolveValueTypeOption
WithResolveValueTypeAllowNull sets whether to allow null (nil) values.
type ResolveValueUUIDData ¶ added in v2.0.4
ResolveValueUUIDData parses the returned value as uuid.UUID if it isn't already.
func ResolveValueUUID ¶ added in v2.0.4
func ResolveValueUUID(options ...ResolveValueTypeOption) ResolveValueUUIDData
ResolveValueUUID parses the returned value as uuid.UUID if it isn't already.
func (ResolveValueUUIDData) ResolveValueParse ¶ added in v2.0.4
type ResolvedCallback ¶
type ResolvedCallback func(ctx context.Context, resolvedData *ResolvedData, resolveInfo ResolveInfo, resolvedRow *Row) error
ResolvedCallback is called for each resolved row.
type ResolvedData ¶
ResolvedData is Data after being resolved by the Resolve function.
func NewResolvedData ¶
func NewResolvedData() *ResolvedData
func Resolve ¶
func Resolve(ctx context.Context, data *Data, resolveFunc ResolveCallback, options ...ResolveOption) (*ResolvedData, error)
Resolve resolves Value and ValueMultiple field values for all rows in "data", using a dependency graph to make sure tables are resolved in dependency order.
func (*ResolvedData) ResolveArgs ¶
func (d *ResolvedData) ResolveArgs(ctx context.Context, values Values, args ...any) ([]any, bool, error)
ResolveArgs resolves a list of arguments. It is used by the ValueFormat value to create a string value from other values.
type Row ¶
type Row struct {
InternalID uuid.UUID // internal id that uniquely identifies this row in its table. It is randomly generated.
RefID RefID // RefID of the row, if set. Should not be duplicated in any other row of the same table.
Values ValuesMutable // the row field values.
Updates []Update // updates to be done after the row is resolved.
ResolvedCallbacks []ResolvedCallback // a callback called after the row is resolved.
}
Row represents a single row of one table.
type SetValueRefIDData ¶
type SetValueRefIDData struct {
RefID RefID
}
SetValueRefIDData is a special ValueMultiple which sets the RefID for the current row. The field containing it is not added to the row.
func SetValueRefID ¶
func SetValueRefID(refID RefID) SetValueRefIDData
SetValueRefID is a special ValueMultiple which sets the RefID for the current row. The field containing it is not added to the row.
func (SetValueRefIDData) Resolve ¶
func (v SetValueRefIDData) Resolve(ctx context.Context, resolvedData *ResolvedData, tableID TableID, fieldName string, values ValuesMutable) error
type Table ¶
Table represents a table, its dependencies, and list of rows.
func (*Table) AddDependencies ¶
AddDependencies adds dependencies on another tables.
type TableID ¶
TableID is a table identification, usually a table name. Users of the library may want to add more fields, like a database name.
type TableNameID ¶
type TableNameID struct {
// contains filtered or unexported fields
}
TableNameID implement TableID with separate id and table name values.
func NewTableNameID ¶
func NewTableNameID(id string, tableName string) TableNameID
NewTableNameID implement TableID with separate id and table name values.
func (TableNameID) TableID ¶
func (t TableNameID) TableID() string
func (TableNameID) TableName ¶
func (t TableNameID) TableName() string
type Update ¶
type Update struct {
Query UpdateQuery
Action UpdateAction
}
Update is an updated query and its corresponding action.
type UpdateAction ¶
type UpdateAction interface {
UpdateRow(ctx context.Context, resolvedData *ResolvedData, tableID TableID, row *Row) error
}
UpdateAction do an update on a row returned by UpdateQuery.
type UpdateActionSetValues ¶
type UpdateActionSetValues struct {
Values Values
}
UpdateActionSetValues is an update action which sets the field values in Values to the row being updated.
func (UpdateActionSetValues) UpdateRow ¶
func (u UpdateActionSetValues) UpdateRow(ctx context.Context, resolvedData *ResolvedData, tableID TableID, row *Row) error
type UpdateData ¶
UpdateData represents one row of one table to be updated.
type UpdateQuery ¶
type UpdateQuery interface {
Rows(ctx context.Context, resolvedData *ResolvedData) ([]UpdateData, error)
}
UpdateQuery returns the list of rows that should be updated.
type UpdateQueryQueryRow ¶
UpdateQueryQueryRow wraps a QueryRow in an UpdateQuery.
func UpdateQueryRow ¶
func UpdateQueryRow(queryRow QueryRow, keyFields []string) *UpdateQueryQueryRow
UpdateQueryRow wraps a QueryRow in an UpdateQuery.
func (UpdateQueryQueryRow) Rows ¶
func (u UpdateQueryQueryRow) Rows(ctx context.Context, resolvedData *ResolvedData) ([]UpdateData, error)
type UpdateQueryQueryRows ¶
UpdateQueryQueryRows wraps a QueryRows in an UpdateQuery.
func UpdateQueryRows ¶
func UpdateQueryRows(queryRows QueryRows, keyFields []string) *UpdateQueryQueryRows
UpdateQueryRows wraps a QueryRows in an UpdateQuery.
func (UpdateQueryQueryRows) Rows ¶
func (u UpdateQueryQueryRows) Rows(ctx context.Context, resolvedData *ResolvedData) ([]UpdateData, error)
type Value ¶
type Value interface {
ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
}
Value represents a field value for a row that can be loaded at resolve time. It can use the current row values, or load any previously loaded rows.
type ValueBaseTimeAddData ¶
ValueBaseTimeAddData is a Value that calculates a date based on the Data base time.
func ValueBaseTimeAdd ¶
func ValueBaseTimeAdd(options ...ValueBaseTimeAddDataOption) ValueBaseTimeAddData
ValueBaseTimeAdd is a Value that calculates a date based on the Data base time.
func (ValueBaseTimeAddData) ResolveValue ¶
func (v ValueBaseTimeAddData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
type ValueBaseTimeAddDataOption ¶
type ValueBaseTimeAddDataOption func(*ValueBaseTimeAddData)
func WithAddDate ¶
func WithAddDate(days, hours, minutes, seconds int) ValueBaseTimeAddDataOption
func WithAddDays ¶
func WithAddDays(days int) ValueBaseTimeAddDataOption
func WithAddHours ¶
func WithAddHours(hours int) ValueBaseTimeAddDataOption
func WithAddMinutes ¶
func WithAddMinutes(minutes int) ValueBaseTimeAddDataOption
func WithAddSeconds ¶
func WithAddSeconds(seconds int) ValueBaseTimeAddDataOption
func WithAddTime ¶
func WithAddTime(hours, minutes, seconds int) ValueBaseTimeAddDataOption
type ValueDefaultData ¶
ValueDefaultData returns the DefaultValue if the other Value don't return a valid value (returns "false" for the 2nd result value).
func ValueDefault ¶
func ValueDefault(value Value, defaultValue any) ValueDefaultData
ValueDefault returns the DefaultValue if the other Value don't return a valid value (returns "false" for the 2nd result value).
func (ValueDefaultData) ResolveValue ¶
func (d ValueDefaultData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
func (ValueDefaultData) TableDependencies ¶
func (d ValueDefaultData) TableDependencies() []TableID
type ValueDependencies ¶
type ValueDependencies interface {
TableDependencies() []TableID
}
ValueDependencies lists value dependencies on other tables, allowing a dependency graph to be built to ensure inserts are done in the corrector table order.
type ValueErr ¶
type ValueErr struct {
Err error
}
ValueErr is an implementation of Value which always returns the passed error.
func (ValueErr) ResolveValue ¶
type ValueFieldValueData ¶
type ValueFieldValueData struct {
FieldName string
}
ValueFieldValueData is a Value which returns the value of a field of the current row.
func ValueFieldValue ¶
func ValueFieldValue(fieldName string) ValueFieldValueData
func (ValueFieldValueData) ResolveValue ¶
func (d ValueFieldValueData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
type ValueFormatCallback ¶ added in v2.0.4
type ValueFormatData ¶
ValueFormatData is a Value that formats a string based on other field's values.
func ValueFormat ¶
func ValueFormat(format string, args ...any) ValueFormatData
ValueFormat is a Value that formats a string based on other field's values.
func (ValueFormatData) ResolveValue ¶
func (v ValueFormatData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
func (ValueFormatData) TableDependencies ¶
func (v ValueFormatData) TableDependencies() []TableID
type ValueFormatFuncData ¶
type ValueFormatFuncData struct {
Value Value
FormatFunc ValueFormatCallback
}
ValueFormatFuncData resolves Value, and allows it to be changed on a callback formatting function.
func ValueFormatFunc ¶
func ValueFormatFunc(value Value, formatFunc ValueFormatCallback) ValueFormatFuncData
ValueFormatFunc resolves Value, and allows it to be changed on a callback formatting function.
func (ValueFormatFuncData) ResolveValue ¶
func (d ValueFormatFuncData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
func (ValueFormatFuncData) TableDependencies ¶
func (d ValueFormatFuncData) TableDependencies() []TableID
type ValueFunc ¶
type ValueFunc func(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
ValueFunc is a functional implementation of Value.
func (ValueFunc) ResolveValue ¶
type ValueGenUUIDData ¶
type ValueGenUUIDData struct {
}
ValueGenUUIDData returns a new random uuid.UUID value every time it is resolved.
func ValueGenUUID ¶
func ValueGenUUID() ValueGenUUIDData
ValueGenUUID returns a new random uuid.UUID value every time it is resolved.
func (ValueGenUUIDData) ResolveValue ¶
func (u ValueGenUUIDData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
type ValueInternalIDData ¶
ValueInternalIDData represents a field value from a table row by internal id. It implements Value, QueryRow, and can return a UpdateQuery.
func ValueInternalID ¶
func ValueInternalID(tableID TableID, internalID uuid.UUID, fieldName string) ValueInternalIDData
ValueInternalID represents a field value from a table row by internal id. It implements Value, QueryRow, and can return a UpdateQuery.
func (ValueInternalIDData) QueryRow ¶
func (v ValueInternalIDData) QueryRow(data *Data) (QueryRowResult, error)
func (ValueInternalIDData) ResolveValue ¶
func (v ValueInternalIDData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
func (ValueInternalIDData) TableDependencies ¶
func (v ValueInternalIDData) TableDependencies() []TableID
func (ValueInternalIDData) UpdateQuery ¶
func (v ValueInternalIDData) UpdateQuery(keyFields []string) UpdateQuery
type ValueMultiple ¶
type ValueMultiple interface {
Resolve(ctx context.Context, resolvedData *ResolvedData, tableID TableID, fieldName string, values ValuesMutable) error
}
ValueMultiple can set any amount of row field values (even none) at resolve time. It can use the current row values, or load any previously loaded rows.
type ValueMultipleErr ¶
type ValueMultipleErr struct {
Err error
}
ValueMultipleErr is an implementation of ValueMultiple which always returns the passed error.
func (ValueMultipleErr) Resolve ¶
func (v ValueMultipleErr) Resolve(ctx context.Context, resolvedData *ResolvedData, tableID TableID, fieldName string, values ValuesMutable) error
type ValueMultipleFunc ¶
type ValueMultipleFunc func(ctx context.Context, resolvedData *ResolvedData, fieldName string, values ValuesMutable) error
ValueMultipleFunc is a functional implementation of ValueMultiple.
func (ValueMultipleFunc) Resolve ¶
func (f ValueMultipleFunc) Resolve(ctx context.Context, resolvedData *ResolvedData, fieldName string, values ValuesMutable) error
type ValueRefFieldValueData ¶
type ValueRefFieldValueData struct {
SourceFieldName string // the field name of the current row to compare for equality.
TableID TableID // the table ID of the other table.
CompareFieldName string // the field name of the other table row (from TableID) to compare for equality.
ReturnFieldName string // the field name of the other table row to have its value returned.
}
ValueRefFieldValueData is a Value which returns the value of a field of a row of the passed table where one of the other row's field value is equal to one of the current row's field value.
func ValueRefFieldValue ¶
func ValueRefFieldValue(sourceFieldName string, tableID TableID, compareFieldName string, returnFieldName string) ValueRefFieldValueData
ValueRefFieldValue is a Value which returns the value of a field of a row of the passed table where one of the other row's field value is equal to one of the current row's field value.
func (ValueRefFieldValueData) ResolveValue ¶
func (d ValueRefFieldValueData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
func (ValueRefFieldValueData) TableDependencies ¶
func (d ValueRefFieldValueData) TableDependencies() []TableID
type ValueRefIDData ¶
ValueRefIDData represents a field value from a table row by its RefID. It implements Value, QueryRow, and can return a UpdateQuery.
func ValueRefID ¶
func ValueRefID(tableID TableID, refID RefID, fieldName string) ValueRefIDData
ValueRefID represents a field value from a table row by its RefID. It implements Value, QueryRow, and can return a UpdateQuery.
func (ValueRefIDData) QueryRow ¶
func (v ValueRefIDData) QueryRow(data *Data) (QueryRowResult, error)
func (ValueRefIDData) ResolveValue ¶
func (v ValueRefIDData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
func (ValueRefIDData) TableDependencies ¶
func (v ValueRefIDData) TableDependencies() []TableID
func (ValueRefIDData) UpdateQuery ¶
func (v ValueRefIDData) UpdateQuery(keyFields []string) UpdateQuery
type ValueStaticData ¶
type ValueStaticData[T any] struct { Value T }
ValueStaticData returns the passed static value every time it is resolved.
func ValueStatic ¶
func ValueStatic[T any](value T) ValueStaticData[T]
ValueStatic returns the passed static value every time it is resolved.
func (ValueStaticData[T]) ResolveValue ¶
func (u ValueStaticData[T]) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
type ValueTemplateData ¶ added in v2.0.6
ValueTemplateData is a Value that formats a string based on other field's values using "text/template".
func ValueTemplate ¶ added in v2.0.6
func ValueTemplate(template string, args map[string]any) ValueTemplateData
ValueTemplate is a Value that formats a string based on other field's values using "text/template".
func (ValueTemplateData) ResolveValue ¶ added in v2.0.6
func (v ValueTemplateData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
func (ValueTemplateData) TableDependencies ¶ added in v2.0.6
func (v ValueTemplateData) TableDependencies() []TableID
type ValueUUIDData ¶
ValueUUIDData returns a fixed uuid.UUID value.
func ValueUUID ¶
func ValueUUID(value uuid.UUID) ValueUUIDData
ValueUUID returns a fixed uuid.UUID value.
func ValueUUIDRandom ¶
func ValueUUIDRandom() ValueUUIDData
ValueUUIDRandom returns a fixed uuid.UUID value that was randomly generated on initialization.
func (ValueUUIDData) ResolveValue ¶
func (u ValueUUIDData) ResolveValue(ctx context.Context, resolvedData *ResolvedData, values Values) (any, bool, error)
type Values ¶
type Values interface {
Get(fieldName string) (val any, exists bool) // gets the value of a field, returning whether the field exists.
GetOrNil(fieldName string) any // gets the value of a field, or nil if the field don't exist.
GetDefault(fieldName string, def any) any // gets the value of a field, or a default value if the field don't exist.
All(yield func(string, any) bool) // iterator of all the field values.
Len() int // returns the amount of field values.
}
Values represents a list of the row fields and values, similar to a map[string]any.
type ValuesMutable ¶
type ValuesMutable interface {
Values
Set(fieldName string, val any) // sets a field value.
Insert(seq iter.Seq2[string, any]) // insert a list of field values.
Delete(fieldName ...string) // delete field values.
}
ValuesMutable is a Values that can be mutated.
func NewValues ¶
func NewValues(val map[string]any) ValuesMutable
NewValues creates a new ValuesMutable.
