note
Reads and writes rows of the
notes table, the comments attached to tasks, artifacts and iterations.const SELECT_COLUMNS
const SELECT_COLUMNS: &str = "id, entity_id, entity_type, author_id, body, created_at, updated_at";The columns of notes, in the order that Model::try_from(Row) reads them.
fn create
pub async fn create(
conn: &Connection,
entity_type: EntityType,
entity_id: &Id,
new: &New,
) -> Result<Model, Error>Create a new note on an entity.
The note gets a fresh id, and both timestamps are set to now.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
entity_type |
EntityType | the kind of entity the note is attached to |
entity_id |
&Id | the full id of that entity |
new |
&New | the note’s body and optional author |
| returns | Result<Model, Error> | The note as read back from the database after the insert, or an error when the insert fails or the row cannot be read back. |
fn delete
pub async fn delete(conn: &Connection, id: &Id) -> Result<bool, Error>Delete a note by its ID. Returns true if the note was deleted.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
id |
&Id | the full id of the note |
| returns | Result<bool, Error> | false when no note had that id. |
fn find_by_id
pub async fn find_by_id(conn: &Connection, id: impl Into<Id>) -> Result<Option<Model>, Error>Find a note by its Id.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
id |
impl Into<Id> | the full id of the note |
| returns | Result<Option<Model>, Error> | The note, or None when no note has that id. |
fn find_required_by_id
pub async fn find_required_by_id(conn: &Connection, id: impl Into<Id>) -> Result<Model, Error>Find a note by its Id, returning Error::NotFound when no row matches.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
id |
impl Into<Id> | the full id of the note |
| returns | Result<Model, Error> | The note, or a database error. The Error::NotFound names the note’s short id. |
fn for_entities
pub async fn for_entities(
conn: &Connection,
entity_type: EntityType,
entity_ids: &[Id],
) -> Result<HashMap<Id, Vec<Model>>, Error>Return all notes for each of the given entities in a single query.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
entity_type |
EntityType | the kind of entity every id in entity_ids refers to |
entity_ids |
&[Id] | the full ids of the entities whose notes to load |
| returns | Result<HashMap<Id, Vec<Model>>, Error> | Entities with no notes are absent from the returned map. Within each entry the notes are ordered by created_at descending. Passing an empty entity_ids slice returns an empty map without issuing a query. |
fn for_entity
pub async fn for_entity(
conn: &Connection,
entity_type: EntityType,
entity_id: &Id,
) -> Result<Vec<Model>, Error>Return all notes for a specific entity, newest first.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
entity_type |
EntityType | the kind of entity |
entity_id |
&Id | the full id of the entity |
| returns | Result<Vec<Model>, Error> | The notes; empty when the entity has none. |
fn update
pub async fn update(conn: &Connection, id: &Id, patch: &Patch) -> Result<Model, Error>Update an existing note with the given patch.
updated_at is always set to now, and body changes only when the patch sets it.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
id |
&Id | the full id of the note |
patch |
&Patch | the fields to change |
| returns | Result<Model, Error> | The updated note, or Error::NotFound when no note has that id. |