The database
Every table the app keeps, and every statement it runs on them.
Written by charter from db/schema.sql and db/queries.sql, the one place a table and a statement are written down: it is what the app has now, and changes when that does.
Tables
notes
| Column | Type | ||
|---|---|---|---|
id | INTEGER | the key | |
body | TEXT | ||
author_id | TEXT | default '' | Who wrote it: their id, empty for a program with one of the Worker's own tokens |
author | TEXT | default '' | What they call themselves |
created_at | TEXT | default CURRENT_TIMESTAMP |
activity
| Column | Type | ||
|---|---|---|---|
id | INTEGER | the key | |
kind | TEXT | ||
note_id | INTEGER | default 0 | |
author | TEXT | default '' | |
notes | INTEGER | default 0 | |
created_at | TEXT | default CURRENT_TIMESTAMP |
attachments
| Column | Type | ||
|---|---|---|---|
id | INTEGER | the key | |
object | TEXT | ||
name | TEXT | ||
type | TEXT | ||
size | INTEGER | ||
note_id | INTEGER | default 0 | |
author_id | TEXT | ||
author | TEXT | ||
created_at | TEXT | default CURRENT_TIMESTAMP |
users
| Column | Type | ||
|---|---|---|---|
id | TEXT | the key | |
name | TEXT | ||
role | TEXT | ||
created_at | TEXT | default CURRENT_TIMESTAMP | |
email | TEXT | may be empty (NULL) |
passkeys
| Column | Type | ||
|---|---|---|---|
id | TEXT | the key | |
user_id | TEXT | ||
credential | TEXT | ||
created_at | TEXT | default CURRENT_TIMESTAMP | |
name | TEXT | default '' | |
used_at | TEXT | may be empty (NULL) |
tokens
| Column | Type | ||
|---|---|---|---|
id | INTEGER | the key | |
hash | TEXT | ||
user_id | TEXT | ||
kind | TEXT | ||
name | TEXT | default '' | |
scopes | TEXT | ||
expires_at | TEXT | may be empty (NULL) | |
created_at | TEXT | default CURRENT_TIMESTAMP |
ceremonies
| Column | Type | ||
|---|---|---|---|
id | TEXT | the key | |
data | TEXT | ||
expires_at | TEXT |
Statements
Each is a function of the package db, with its arguments and its rows typed against the tables above. No statement is written anywhere else.
| Function | It gives | What it does |
|---|---|---|
db.CreateNote | one row, or no such row | INSERT INTO notes (body, author_id, author) VALUES (?, ?, ?) RETURNING * |
db.RemoveNote | one row, or no such row | RemoveNote takes a note away, and says which it was. |
db.RemoveNotesBy | rows | RemoveNotesBy takes away everything someone wrote, and says which notes those were. |
db.Note | one row, or no such row | Note is one note, by its id. |
db.NotesBefore | rows | NotesBefore is a page of notes, newest first, before a note id. |
db.NotesAfter | rows | NotesAfter is the notes after a note id, oldest first: the log a stream follows. |
db.NewestNote | one row, or no such row | NewestNote is the id of the newest note, 0 if there is none. |
db.NotesBy | rows | NotesBy is someone's notes, newest first: what they may attach a file to. |
db.NotesReport | one row, or no such row | NotesReport is how many notes there are, and by how many people. |
db.NotesSince | one row, or no such row | NotesSince is how many notes were written after a time. |
db.RecordActivity | one row, or no such row | INSERT INTO activity (kind, note_id, author, notes) VALUES (?, ?, ?, ?) RETURNING * |
db.ForgetNote | nothing | ForgetNote takes away what was recorded of a note: it goes with the note. |
db.ActivityBefore | rows | ActivityBefore is what happened before a position, newest first. |
db.ActivityAfter | rows | ActivityAfter is what happened after a position, oldest first: the log its feed follows. |
db.NewestActivity | one row, or no such row | SELECT CAST(COALESCE(MAX(id), 0) AS INTEGER) AS id FROM activity |
db.AddAttachment | one row, or no such row | INSERT INTO attachments (object, name, type, size, note_id, author_id, author) VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING * |
db.Attachments | rows | Attachments is the files attached, newest first. |
db.AttachmentsBy | rows | AttachmentsBy is the files someone attached. |
db.Attachment | one row, or no such row | SELECT * FROM attachments WHERE id = ? |
db.RemoveAttachment | one row, or no such row | DELETE FROM attachments WHERE id = ? RETURNING * |