Skip to main content

DcsTemplateRow

Struct DcsTemplateRow 

Source
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

Source

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).

Source

pub async fn get(pool: &SqlitePool, id: i64) -> DbResult<Option<DcsTemplateRow>>

Fetches one row by id, or None if it doesn’t exist.

Source

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.

Source

pub async fn list(pool: &SqlitePool) -> DbResult<Vec<DcsTemplateRow>>

Lists every row, ordered by name, for the loop-editor’s template picker.

Source

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.

Source

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

Source§

fn clone(&self) -> DcsTemplateRow

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DcsTemplateRow

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for DcsTemplateRow

Source§

fn eq(&self, other: &DcsTemplateRow) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for DcsTemplateRow

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more