Edit Metadata

Learn how to read who created and changed a row, and when, through magic columns like $createdBy and $createdAt.

You can select and filter on Jazz's magic columns just like other columns. They are omitted from select("*"), so opt in explicitly when you want them.

Edit metadata columns

  • $createdBy — the Jazz principal that created the row
  • $createdAt — when the row was first created
  • $updatedBy — the Jazz principal that last updated the row
  • $updatedAt — when the row was last updated

$createdBy and $updatedBy are a RowAuthor: { account, identity: { issuer, subject } }. account is the Jazz account; identity.subject is the userId your authenticate returned for a backend sign-in.

Anyone who can read a row can read its $createdBy and $updatedBy, including identity.subject, and so can anyone who can read its history. If your authenticate returns an email or another personal value as userId, every reader of the user's rows sees it. Return an opaque id (your auth's user id, not the email) when author identity is sensitive.

These are useful for showing authorship, when a row last changed, or building "my created items" views without storing duplicate ownership fields.

export async function readTodoEditMetadata(db: Db, author: RowAuthor, updatedSinceMs: number) {
return db.all(
app.todos
.where({
$createdBy: author,
$updatedAt: { gt: updatedSinceMs },
})
.select("title", "$createdBy", "$createdAt", "$updatedBy", "$updatedAt"),
);
}

See Declarative Permissions for policy examples using $createdBy and the other magic columns.

Deletion metadata columns

After .includeDeleted(), you can select, filter, and sort by $deletedAt and $deletedBy. They return the winning deletion's authored timestamp as a Date and author as a RowAuthor, or null for live and restored rows.

const deletedTasks = await db.all(
app.tasks
.includeDeleted()
.where({ $deletedAt: { isNull: false } })
.select("title", "$deletedAt", "$deletedBy"),
);

For history rows, every version shares the logical row's current deletion timestamp and author.