Update fn update to be in the trait, instead of a freefloating function in the struct

This commit is contained in:
Gvidas Juknevičius 2025-09-15 21:51:47 +03:00
parent c2a7a01a7d
commit 962b8feae7
Signed by: MCorange
GPG Key ID: 5BE6B533CB76FE86
2 changed files with 2 additions and 4 deletions

View File

@ -86,10 +86,7 @@ pub fn derive_table_meta(input: TokenStream) -> TokenStream {
impl TableMeta for #ident { impl TableMeta for #ident {
type PrimaryKey = #key_t; type PrimaryKey = #key_t;
const TABLE: &'static str = #table_name; const TABLE: &'static str = #table_name;
} async fn update(&mut self, pool: &crate::db::CurrPool) -> anyhow::Result<Self> {
impl #ident {
pub async fn update(&mut self, pool: &crate::db::CurrPool) -> anyhow::Result<Self> {
#modified_at #modified_at
let session = sqlx::query_as!( let session = sqlx::query_as!(
#ident, #ident,

View File

@ -16,6 +16,7 @@ pub mod user;
pub trait TableMeta: for<'r> sqlx::FromRow<'r, PgRow> { pub trait TableMeta: for<'r> sqlx::FromRow<'r, PgRow> {
type PrimaryKey: Type<super::CurrDb> + Clone; type PrimaryKey: Type<super::CurrDb> + Clone;
const TABLE: &'static str; const TABLE: &'static str;
async fn update(&mut self, pool: &crate::db::CurrPool) -> anyhow::Result<Self>;
} }
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]