Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtbuilds committed Oct 17, 2024
1 parent 4f6086a commit ab49dc0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions macro/src/codegen/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use ormlite_attr::Type;
use proc_macro2::TokenStream;
use quote::quote;

pub fn impl_Model__insert(db: &dyn OrmliteCodegen, attr: &TableMeta, metadata_cache: &MetadataCache) -> TokenStream {
pub fn impl_Model__insert(db: &dyn OrmliteCodegen, attr: &ModelMeta, metadata_cache: &MetadataCache) -> TokenStream {
let box_future = crate::util::box_fut_ts();
let mut placeholder = db.placeholder();
let db = db.database_ts();
let table = &attr.name;
let params = attr.database_columns().map(|c| {
if c.has_database_default {
if attr.pkey.name == c.name {
placeholder.next().unwrap()
} else if c.has_database_default {
"DEFAULT".to_string()
} else {
placeholder.next().unwrap()
Expand All @@ -23,7 +25,7 @@ pub fn impl_Model__insert(db: &dyn OrmliteCodegen, attr: &TableMeta, metadata_ca

let query_bindings = attr
.database_columns()
.filter(|c| !c.has_database_default)
.filter(|c| attr.pkey.name == c.name || !c.has_database_default)
.map(|c| insertion_binding(c));

let insert_join = attr.many_to_one_joins().map(|c| insert_join(c));
Expand Down
2 changes: 1 addition & 1 deletion macro/src/codegen/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn impl_Model(db: &dyn OrmliteCodegen, attr: &ModelMeta, metadata_cache: &Me
let model = &attr.ident;
let partial_model = attr.builder_struct();

let impl_Model__insert = impl_Model__insert(db, &attr.table, metadata_cache);
let impl_Model__insert = impl_Model__insert(db, &attr, metadata_cache);
let impl_Model__update_all_fields = impl_Model__update_all_fields(db, attr);
let impl_Model__delete = impl_Model__delete(db, attr);
let impl_Model__fetch_one = impl_Model__fetch_one(db, attr);
Expand Down
2 changes: 1 addition & 1 deletion ormlite/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("{:?}", john);

println!("select");
let people = Person::select().where_("age > ?").bind(50).fetch_all(&mut conn).await?;
let people = Person::select().where_bind("age > ?", 50).fetch_all(&mut conn).await?;
println!("select query builder {:?}", people);

let r = sqlx::query_as::<_, Person>("select * from person where age > ?")
Expand Down

0 comments on commit ab49dc0

Please sign in to comment.