Skip to content

Commit

Permalink
^ model - added DbBMC::TIMESTAMPED to for entity tables to not have c…
Browse files Browse the repository at this point in the history
…id, ctime, ...
  • Loading branch information
jeremychone committed Dec 31, 2023
1 parent 968a6d3 commit 391a0b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions crates/libs/lib-core/src/model/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub enum TimestampIden {

pub trait DbBmc {
const TABLE: &'static str;
/// Specifies that the table for this Bmc has timestamps (cid, ctime, mid, mtime) columns.
/// This will allow the code to update those as needed.
const TIMESTAMPED: bool;

fn table_ref() -> TableRef {
TableRef::Table(SIden(Self::TABLE).into_iden())
Expand Down Expand Up @@ -74,7 +77,9 @@ where

// -- Extract fields (name / sea-query value expression)
let mut fields = data.not_none_fields();
add_timestamps_for_create(&mut fields, ctx.user_id());
if MC::TIMESTAMPED {
add_timestamps_for_create(&mut fields, ctx.user_id());
}
let (columns, sea_values) = fields.for_sea_insert();

// -- Build query
Expand Down Expand Up @@ -172,7 +177,9 @@ where
let db = mm.db();

let mut fields = data.not_none_fields();
add_timestamps_for_update(&mut fields, ctx.user_id());
if MC::TIMESTAMPED {
add_timestamps_for_update(&mut fields, ctx.user_id());
}
let fields = fields.for_sea_update();

// -- Build query
Expand Down
1 change: 1 addition & 0 deletions crates/libs/lib-core/src/model/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct ProjectBmc;

impl DbBmc for ProjectBmc {
const TABLE: &'static str = "project";
const TIMESTAMPED: bool = true;
}

impl ProjectBmc {
Expand Down
1 change: 1 addition & 0 deletions crates/libs/lib-core/src/model/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub struct TaskBmc;

impl DbBmc for TaskBmc {
const TABLE: &'static str = "task";
const TIMESTAMPED: bool = true;
}

impl TaskBmc {
Expand Down
5 changes: 4 additions & 1 deletion crates/libs/lib-core/src/model/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub struct UserBmc;

impl DbBmc for UserBmc {
const TABLE: &'static str = "user";
const TIMESTAMPED: bool = true;
}

impl UserBmc {
Expand Down Expand Up @@ -126,7 +127,9 @@ impl UserBmc {

// -- Prep the data
let mut fields = Fields::new(vec![Field::new(UserIden::Pwd, pwd.into())]);
add_timestamps_for_update(&mut fields, ctx.user_id());
if Self::TIMESTAMPED {
add_timestamps_for_update(&mut fields, ctx.user_id());
}

// -- Build query
let fields = fields.for_sea_update();
Expand Down

0 comments on commit 391a0b6

Please sign in to comment.