Documentation ¶
Index ¶
- func Bool(m json.RawMessage) bool
- func DeleteEntity(changes wire.Changes, typeName string)
- func DeleteFields(changes wire.Changes, typeName string, fieldName ...string)
- func IP(m json.RawMessage) net.IP
- func Int(m json.RawMessage) int
- func Marshal(v any) json.RawMessage
- func RenameEntity(changes wire.Changes, typeNameOld, typeNameNew string)
- func RenameField(changes wire.Changes, typeName string, fieldNameOld, fieldNameNew string)
- func RenameFields(changes wire.Changes, typeName string, mapping map[string]string)
- func ReplaceStringValue(changes wire.Changes, typeName, fieldName, oldValue, newValue string)
- func ReplaceStringValues(changes wire.Changes, typeName, fieldName string, mapping map[string]string)
- func String(m json.RawMessage) string
- func Time(m json.RawMessage) time.Time
- type Transformation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteEntity ¶
DeleteEntity deletes an entity type by its DB name (name=... in limestone.Meta definitions)
func DeleteFields ¶
DeleteFields deletes the given fields from an entity type
func Marshal ¶
func Marshal(v any) json.RawMessage
Marshal returns its argument encoded as json.RawMessage
func RenameEntity ¶
RenameEntity changes the DB name of an entity type (name=... in limestone.Meta definitions)
func RenameField ¶
RenameField renames the given field in an entity type
func RenameFields ¶
RenameFields renames fields in an entity type by given mapping between old and new field names
func ReplaceStringValue ¶
ReplaceStringValue replaces the given string value of the given field in an entity type
Types ¶
type Transformation ¶
type Transformation func(logger *zap.Logger, source <-chan wire.Transaction, dest chan<- wire.Transaction)
Transformation is a database upgrade or other cleanup procedure that takes a sequence of transactions as input and produces a sequence of transactions as output. The function should read all transactions from source until the end of stream and write the converted stream into dest. Do not close dest.
The transformation may pass transactions without change, modify them, introduce novel transactions, drop, join, split and reorder transactions.
All transactions written into dest must have their TS field set, and these must be in a strictly ascending order.
Panic to fail the transformation.
func ForEach ¶
func ForEach(conv func(logger *zap.Logger, txn *wire.Transaction)) Transformation
ForEach is a shorthand for writing a typical stateless upgrade transformation.
It returns an upgrade transformation that takes a stateless conversion and applies it to each transaction in the stream. Transactions that end up empty after the conversion are omitted from the output.
Example:
var Transform = xform.ForEach(func(logger *zap.Logger, txn *wire.Transaction) { xform.DeleteEntity(txn.Changes, "old_entity") xform.DeleteFields(txn.Changes, "another_entity", "Field1", "Field2") })
func ForEachWithState ¶
func ForEachWithState(kinds convertdb.KindList, conv func(logger *zap.Logger, txn convertdb.Transaction) bool) Transformation
ForEachWithState is a shorthand for writing a typical stateful upgrade transformation.
It returns an upgrade transformation that takes a stateful conversion and applies it to each transaction in the stream. Transactions that end up empty after the conversion are omitted from the output. If true is returned by the conversion, txn.Source will be cleared so that the transaction can bypass producer checking. Read the doc of convertdb in limestone/converter/convertdb/doc.go
Example:
type foo struct { ufoo.Common ufoo.New } var ( indexFleetID = limestone.Index("FleetID") kindForwarder = convertdb.KindOf(forwarder{}, indexFleetID) kinds = convertdb.KindList{kindForwarder} ) var Transform = xform.ForEachWithState(func(logger *zap.Logger, txn convertdb.Transaction) bool { xform.DeleteEntity(txn.Other, "old_entity") xform.DeleteFields(txn.Other, "another_entity", "Field1", "Field2") var clearProducer bool for fooID, diff := range txn.Raw.Changes["foo"] { if diff["Field1"] != nil { var f foo limestone.MustGet(fooID, &f) f.Field2 = f.Field1 + f.Field3 txn.Set(f) // Field1 is owned by service1 but Field2 is owned by service2, so producer has to be cleared clearProducer = true } } return clearProducer })