You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
π Add docstrings to fix/templates-created-at-schema
Docstrings generation was requested by @dmfilipenko.
* #1600 (comment)
The following files were modified:
* `crates/db-user/src/lib.rs`
* `crates/db-user/src/templates_ops.rs`
* `crates/db-user/src/templates_types.rs`
Copy file name to clipboardExpand all lines: crates/db-user/src/templates_ops.rs
+68-3Lines changed: 68 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,22 @@ impl UserDatabase {
19
19
Ok(items)
20
20
}
21
21
22
+
/// Inserts a new template or updates an existing one identified by its `id`, then returns the stored template.
23
+
///
24
+
/// If a row with the same `id` already exists, this operation updates its `title`, `description`, `sections`, `tags`, and `context_option` and returns the resulting row; otherwise it inserts a new row and returns it. Errors are propagated for database or row-conversion failures.
Copy file name to clipboardExpand all lines: crates/db-user/src/templates_types.rs
+26-1Lines changed: 26 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ user_common_derives! {
9
9
pub sections:Vec<TemplateSection>,
10
10
pub tags:Vec<String>,
11
11
pub context_option:Option<String>,
12
+
pub created_at:String,
12
13
}
13
14
}
14
15
@@ -20,6 +21,27 @@ user_common_derives! {
20
21
}
21
22
22
23
implTemplate{
24
+
/// Constructs a `Template` from a database row.
25
+
///
26
+
/// Maps columns to `Template` fields as follows:
27
+
/// - column 0 β `id` (panics if missing),
28
+
/// - column 1 β `user_id` (panics if missing),
29
+
/// - column 2 β `title` (panics if missing),
30
+
/// - column 3 β `description` (panics if missing),
31
+
/// - column 4 β `sections` (expects JSON string; defaults to empty `Vec` if absent),
32
+
/// - column 5 β `tags` (expects JSON string; defaults to empty `Vec` if absent),
33
+
/// - column 6 β `context_option` (set to `None` if missing or unreadable),
34
+
/// - column 7 β `created_at` (falls back to current UTC time in RFC3339 seconds precision if unavailable).
35
+
///
36
+
/// Note: JSON deserialization for `sections` and `tags` is unwrapped and will panic on invalid JSON. Required primitive columns (id, user_id, title, description) use `expect` and will panic if absent.
37
+
///
38
+
/// # Examples
39
+
///
40
+
/// ```ignore
41
+
/// // `row` must be obtained from libsql query results.
42
+
/// let template = Template::from_row(&row).expect("valid row");
0 commit comments