Documentation ¶
Index ¶
- Variables
- func Commit[T database.Record](lastErr *error, v T)
- func CompareBigInt(u, v *big.Int) int
- func CompareBool(u, v bool) int
- func CompareBytes(u, v []byte) int
- func CompareDuration(u, v time.Duration) int
- func CompareFloat(u, v float64) int
- func CompareHash(u, v [32]byte) int
- func CompareInt(u, v int64) int
- func CompareString(u, v string) int
- func CompareTime(u, v time.Time) int
- func CompareTxid(u, v *url.TxID) int
- func CompareUint(u, v uint64) int
- func CompareUrl(u, v *url.URL) int
- func GetOrCreate[Container any, Record any](c Container, ptr *Record, create func(Container) Record) Record
- func GetOrCreateMap[Container any, Record any, Key keyType[MapKey], MapKey comparable](c Container, ptr *map[MapKey]Record, key Key, ...) Record
- func IsDirty[T database.Record](v T) bool
- func MapKeyBytes(v []byte) [32]byte
- func MapKeyUrl(v *url.URL) [32]byte
- func ParseString(s string) (string, error)
- func Resolve[T any](r database.Record, key *database.Key) (T, error)
- func Struct[T any, PT ptrBinaryValue[T]]() encodableValue[PT]
- func Union[T encoding.BinaryValue](unmarshal func([]byte) (T, error)) encodableValue[T]
- func UnionFactory[T encoding.BinaryValue](unmarshal func([]byte) (T, error)) func() encodableValue[T]
- func Walk[T database.Record](lastErr *error, v T, opts database.WalkOptions, fn database.WalkFunc)
- func WalkComposite[T database.Record](v T, opts database.WalkOptions, fn database.WalkFunc) (skip bool, err error)
- func WalkField[T database.Record](lastErr *error, v T, make func() T, opts database.WalkOptions, ...)
- func WalkMap[Record database.Record, Key keyType[MapKey], MapKey comparable](lastErr *error, m map[MapKey]Record, make func(Key) Record, ...)
- func Wrapped[T any](funcs *wrapperFuncs[T]) encodableValue[T]
- func WrappedFactory[T any](funcs *wrapperFuncs[T]) func() encodableValue[T]
- type Counted
- type List
- type RecordStore
- type Set
- type Value
Constants ¶
This section is empty.
Variables ¶
var BoolWrapper = &wrapperFuncs[bool]{ copy: copyValue[bool], marshal: func(value bool) ([]byte, error) { if value { return []byte{1}, nil } return []byte{0}, nil }, unmarshal: func(data []byte) (bool, error) { if len(data) < 1 { return false, encoding.ErrNotEnoughData } return data[0] == 1, nil }, }
BoolWrapper defines un/marshalling functions for boolean fields.
var BytesWrapper = &wrapperFuncs[[]byte]{ copy: func(v []byte) []byte { u := make([]byte, len(v)); copy(u, v); return u }, marshal: oldMarshal(encoding.MarshalBytes), unmarshal: encoding.UnmarshalBytes, }
BytesWrapper defines un/marshalling functions for byte slice fields.
var ErrNotEnoughData = errors.BadRequest.With("not enough data")
var ErrOverflow = errors.BadRequest.With("overflow")
var HashWrapper = &wrapperFuncs[[32]byte]{ copy: copyValue[[32]byte], marshal: oldMarshalPtr(encoding.MarshalHash), unmarshal: encoding.UnmarshalHash, }
HashWrapper defines un/marshalling functions for hash fields.
var IntWrapper = &wrapperFuncs[int64]{ copy: copyValue[int64], marshal: oldMarshal(encoding.MarshalInt), unmarshal: encoding.UnmarshalInt, }
IntWrapper defines un/marshalling functions for int fields.
var RawWrapper = &wrapperFuncs[[]byte]{ copy: func(v []byte) []byte { u := make([]byte, len(v)); copy(u, v); return u }, marshal: func(value []byte) ([]byte, error) { return value, nil }, unmarshal: func(data []byte) ([]byte, error) { return data, nil }, }
RawWrapper defines un/marshalling functions for raw byte slice fields.
var StringWrapper = &wrapperFuncs[string]{ copy: copyValue[string], marshal: oldMarshal(encoding.MarshalString), unmarshal: encoding.UnmarshalString, }
StringWrapper defines un/marshalling functions for string fields.
var TxidWrapper = &wrapperFuncs[*url.TxID]{ copy: copyValue[*url.TxID], marshal: marshalAsString[*url.TxID], unmarshal: unmarshalFromString(url.ParseTxID), }
TxidWrapper defines un/marshalling functions for txid fields.
var UintWrapper = &wrapperFuncs[uint64]{ copy: copyValue[uint64], marshal: oldMarshal(encoding.MarshalUint), unmarshal: encoding.UnmarshalUint, }
UintWrapper defines un/marshalling functions for uint fields.
var UrlWrapper = &wrapperFuncs[*url.URL]{ copy: copyValue[*url.URL], marshal: marshalAsString[*url.URL], unmarshal: unmarshalFromString(url.Parse), }
UrlWrapper defines un/marshalling functions for url fields.
Functions ¶
func CompareBigInt ¶ added in v1.3.0
func CompareBool ¶ added in v1.3.0
func CompareBytes ¶ added in v1.3.0
func CompareDuration ¶ added in v1.3.0
func CompareFloat ¶ added in v1.3.0
func CompareHash ¶
func CompareInt ¶ added in v1.3.0
func CompareString ¶ added in v1.2.0
func CompareTime ¶ added in v1.3.0
func CompareTxid ¶
func CompareUint ¶
func CompareUrl ¶
func GetOrCreate ¶
func GetOrCreate[Container any, Record any](c Container, ptr *Record, create func(Container) Record) Record
GetOrCreate retrieves an existing record or creates, records, and assigns a new record to the field.
func GetOrCreateMap ¶
func GetOrCreateMap[Container any, Record any, Key keyType[MapKey], MapKey comparable](c Container, ptr *map[MapKey]Record, key Key, create func(Container, Key) Record) Record
GetOrCreateMap retrieves an existing record or creates, records, and assigns a new record to the map.
func MapKeyBytes ¶
func ParseString ¶
func Struct ¶
func Struct[T any, PT ptrBinaryValue[T]]() encodableValue[PT]
Struct returns an encodable value for the given encodable struct-type.
func Union ¶
func Union[T encoding.BinaryValue](unmarshal func([]byte) (T, error)) encodableValue[T]
Union returns an encodable value for the given encodable union type.
func UnionFactory ¶
func UnionFactory[T encoding.BinaryValue](unmarshal func([]byte) (T, error)) func() encodableValue[T]
UnionFactory curries Union.
func Walk ¶
Walk walks the record if it is non-nil, unless opts.Modified is set and the record is unmodified.
func WalkComposite ¶
func WalkField ¶
func WalkField[T database.Record](lastErr *error, v T, make func() T, opts database.WalkOptions, fn database.WalkFunc)
WalkField walks an attribute. If opts.Modified is set, WalkField walks the record if it is non-nil and modified. Otherwise, WalkField will walk the existing record or create (but not retain) a new record and walk that.
func WalkMap ¶
func WalkMap[Record database.Record, Key keyType[MapKey], MapKey comparable](lastErr *error, m map[MapKey]Record, make func(Key) Record, getKeys func() ([]Key, error), opts database.WalkOptions, fn database.WalkFunc)
WalkField walks a parameterized attribute. If opts.Modified is set, WalkField iterates over the existing records, walking any that are modified. If opts.Modified is not set and getKeys is nil, WalkField does nothing. Otherwise, WalkField calls getKeys, iterates over the result, and walks all the corresponding records. If a record exists in the map, WalkField uses that; otherwise it creates (but does not retain) a new record and walks that.
func Wrapped ¶
func Wrapped[T any](funcs *wrapperFuncs[T]) encodableValue[T]
Wrapped returns an encodable value for the given type using the given wrapper functions.
func WrappedFactory ¶
func WrappedFactory[T any](funcs *wrapperFuncs[T]) func() encodableValue[T]
WrappedFactory curries Wrapped.
Types ¶
type Counted ¶
type Counted[T any] interface { database.Record Get(int) (T, error) Put(T) error Count() (int, error) GetAll() ([]T, error) Last() (int, T, error) Overwrite([]T) error }
Counted records an insertion-ordered list of values as separate records plus a record for the count.
type RecordStore ¶
RecordStore implements database.Store using a database.Record.
func (RecordStore) Unwrap ¶
func (s RecordStore) Unwrap() database.Record