interface
DataTransaction
Transaction-bound content operations available to a compiled migration callback.
Example
posts, err := tx.Collection("posts")
if err != nil {
return err
}
_, err = tx.Update(ctx, migration.UpdateRequest{
Request: store.Request{Collection: posts, ID: "hello"},
Values: store.Values{"summary": store.String("Hello")},
})
return errProperties
| Property | Type | Description |
|---|---|---|
Collection | func(slug string) (schema.Collection, | Returns the collection as this migration leaves it, or as it was before when the migration removes it. Pass it to every request so the transform keeps replaying after later migrations change the collection. |
Global | func(slug string) (schema.Collection, | Returns the global with this slug, resolved like Collection. |
Create | func(context.Context, | Creates a document with the given ID and values. |
Find | func(context.Context, | Reads one stored document by ID. |
List | func(context.Context, | Reads a page of stored documents. Loop while HasNextPage is true to visit every match. |
Update | func(context.Context, | Locks the stored document and patches its values, or replaces them when ReplaceValues is set. |
Trash | func(context.Context, | Moves a document to the trash. |
Restore | func(context.Context, | Restores a trashed document. |
Delete | func(context.Context, | Deletes a document and the framework state it owns, such as its versions, sessions and preferences. |
How it works
Every request runs inside the migration's transaction, so the schema change and the content change commit or roll back together.
A transform can't change a versioned collection or global; backfill those in an earlier, data-only migration.
Full signature
type DataTransaction interface {
// Collection returns the collection with this slug as the running
// migration leaves it, or as it was before when the migration removes it.
// Every request must use a shape from the migration itself, so a
// transform keeps replaying after later migrations change the collection.
Collection(slug string) (schema.Collection, error)
// Global returns the global with this slug, resolved like Collection.
Global(slug string) (schema.Collection, error)
Create(context.Context, store.CreateRequest) (store.Document, error)
Find(context.Context, store.Request) (store.Document, error)
List(context.Context, store.Request) (store.Page, error)
Update(context.Context, UpdateRequest) (store.Document, error)
Trash(context.Context, store.Request) (store.Document, error)
Restore(context.Context, store.Request) (store.Document, error)
Delete(context.Context, store.Request) (store.Document, error)
}