Records
Status: Draft
The following functions are useful abstractions utilizing record types definitions.
They're designed in a way that you can fully influence the function calls resulting in the created record, so what it does is as follows:
- finds the record type based on id
- processes record:write hooks
- creates record + event documents
- writes record + event (optional) to the database of the associated storage adapter
- gives you back the created records
this is what you would do otherwise yourself, except this function abstracts those steps away.
if you want to do those steps manually yourself, you always can. that's what is important compared to most encapsulated libraries out there who try to magically fix everything but don't give you control over what happens inside.
CRUD examples:
- insertMany
- insertOne
- upsertMany (future)
- upsertOne (future)
- updateMany
- updateOne
- deleteMany (future)
- deleteOne (future)
insertMany
import insertMany from "@/lib/record/insertMany"
const [record1, record2] = await insertMany(ctx, {
recordTypeId: 'post',
records: [
{
field_a: 'lorem',
field_b: 123,
},
{
field_a: 'lorem',
field_b: 123,
},
],
})
insertOne
Single version of insertMany:
import insertOne from "@/lib/record/insertOne"
const record = await insertOne(ctx, {
recordTypeId: 'post',
record: {
field_a: 'lorem',
field_b: 123,
}
})
updateMany
import updateMany from "@/lib/record/updateMany"
const record = await updateMany(ctx, {
recordTypeId: 'post',
records: [
{
id: 'post:123',
field_a: 'lorem',
field_b: 123,
},
{
id: 'post:456',
field_a: 'ipsum',
field_b: 456,
}
]
})
updateOne
import updateOne from "@/lib/record/updateOne"
const record = await updateOne(ctx, {
recordTypeId: 'post',
record: {
id: 'post:123',
field_a: 'lorem',
field_b: 123,
}
})