pub struct DcsTemplateRow {
pub id: i64,
pub origin: TemplateOrigin,
pub template: DcsTemplate,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Expand description
One row of dcs_templates: a DcsTemplate plus the database bookkeeping fields that
don’t belong on the pure domain type itself.
Fields§
§id: i64§origin: TemplateOrigin§template: DcsTemplate§created_at: DateTime<Utc>§updated_at: DateTime<Utc>Implementations§
Source§impl DcsTemplateRow
impl DcsTemplateRow
Sourcepub async fn insert(
pool: &SqlitePool,
template: &DcsTemplate,
origin: TemplateOrigin,
now: DateTime<Utc>,
) -> DbResult<DcsTemplateRow>
pub async fn insert( pool: &SqlitePool, template: &DcsTemplate, origin: TemplateOrigin, now: DateTime<Utc>, ) -> DbResult<DcsTemplateRow>
Inserts template, returning the persisted row (with its assigned id). now is
used for both created_at and updated_at; the caller supplies it rather than this
function reading the clock, keeping “who reads the clock” consistent with the rest of
bhtune’s architecture (see bhtune_core’s crate docs).
Sourcepub async fn get(pool: &SqlitePool, id: i64) -> DbResult<Option<DcsTemplateRow>>
pub async fn get(pool: &SqlitePool, id: i64) -> DbResult<Option<DcsTemplateRow>>
Fetches one row by id, or None if it doesn’t exist.
Sourcepub async fn get_by_name(
pool: &SqlitePool,
name: &str,
) -> DbResult<Option<DcsTemplateRow>>
pub async fn get_by_name( pool: &SqlitePool, name: &str, ) -> DbResult<Option<DcsTemplateRow>>
Fetches one row by its (unique) name, or None if it doesn’t exist. Used by
crate::seed::seed_templates to find any existing row before deciding whether to
insert or update.
Sourcepub async fn list(pool: &SqlitePool) -> DbResult<Vec<DcsTemplateRow>>
pub async fn list(pool: &SqlitePool) -> DbResult<Vec<DcsTemplateRow>>
Lists every row, ordered by name, for the loop-editor’s template picker.
Sourcepub async fn update(
pool: &SqlitePool,
id: i64,
template: &DcsTemplate,
now: DateTime<Utc>,
) -> DbResult<DcsTemplateRow>
pub async fn update( pool: &SqlitePool, id: i64, template: &DcsTemplate, now: DateTime<Utc>, ) -> DbResult<DcsTemplateRow>
Overwrites every template field of the row at id with template’s, bumping
updated_at to now. Deliberately does not touch name (the match key callers
already looked the row up by) or origin (ownership of a row never changes after
creation) — only Self::insert sets those.
Sourcepub async fn delete(pool: &SqlitePool, id: i64) -> DbResult<bool>
pub async fn delete(pool: &SqlitePool, id: i64) -> DbResult<bool>
Deletes the row at id. Returns Ok(true) if a row existed and was removed,
Ok(false) if no row with that id existed (not an error – deciding whether “nothing
to delete” should itself be an error is the caller’s call; bhtune-cli’s template delete already resolves id from a name via Self::get_by_name and produces its
own “no template named” error before ever calling this).
Fails with DbError::TemplateInUse if loops.dcs_template_id’s ON DELETE RESTRICT foreign key rejects the delete because a saved loop still references this
template. Classified as “any database-level error on this specific statement”,
rather than solely sqlx’s DatabaseError::is_foreign_key_violation() – confirmed
empirically that SQLite’s C implementation reports an immediate RESTRICT
violation like this one under the extended result code SQLITE_CONSTRAINT_TRIGGER
(its FK-action enforcement runs through the same internal machinery as a trigger
body), not SQLITE_CONSTRAINT_FOREIGNKEY – the latter is what sqlx-sqlite maps to
is_foreign_key_violation(), and it’s only what a deferred FK check reports at
commit time, which this crate never uses. This is safe to broaden to “any database
error” specifically because dcs_templates has exactly one foreign key pointing at
it (loops.dcs_template_id), no triggers exist anywhere in the schema, and a bare
DELETE can’t violate this table’s own CHECK constraints (they all apply to
column values, which a delete-by-id never touches) – so a database-level failure of
this exact statement structurally has only one possible cause.
Trait Implementations§
Source§impl Clone for DcsTemplateRow
impl Clone for DcsTemplateRow
Source§fn clone(&self) -> DcsTemplateRow
fn clone(&self) -> DcsTemplateRow
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DcsTemplateRow
impl Debug for DcsTemplateRow
Source§impl PartialEq for DcsTemplateRow
impl PartialEq for DcsTemplateRow
Source§fn eq(&self, other: &DcsTemplateRow) -> bool
fn eq(&self, other: &DcsTemplateRow) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for DcsTemplateRow
Auto Trait Implementations§
impl Freeze for DcsTemplateRow
impl RefUnwindSafe for DcsTemplateRow
impl Send for DcsTemplateRow
impl Sync for DcsTemplateRow
impl Unpin for DcsTemplateRow
impl UnsafeUnpin for DcsTemplateRow
impl UnwindSafe for DcsTemplateRow
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more