Ephemeral (Symbol) Fields
const $MESSAGE = Symbol("$MESSAGE");
const schemaComments = new PgSchema(
"comments",
{
id: { type: ID, autoInsert: "nextval('comments_id_seq')" },
topic_id: { type: ID },
// This becomes a required and non-nullable ephemeral field.
[$MESSAGE]: { type: String },
},
[]
);
export class EntComment extends BaseEnt(cluster, schema) {
static override configure() {
return new this.Configuration({
...
beforeMutation: [
async (vc, { op, newOrOldRow }) => {
if (op !== "DELETE") {
const text = await encrypt(newOrOldRow[$MESSAGE]);
await EntText.upsertReturning(
vc,
{ id: newOrOldRow.id, text },
);
}
},
],
afterDelete: [
async (vc, { oldRow }) => {
const text = await EntText.loadNullable(vc, oldRow.id);
await text?.deleteOriginal();
}
],
});
}
}
...
const comment = await EntComment.insertReturning(vc, {
topic_id: "123",
[$MESSAGE]: "Hello", // required property!
});Last updated