Skip to content

Commit

Permalink
OPTIMZE: doc
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyuedefeng committed Sep 5, 2023
1 parent be273c4 commit 75012dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ let uesrs: Vec<ArelUser> = User::query().r#where("id", vec![1, 2, 3]).fetch_all_
// update
let user: User = User::query().fetch_one_as().await?;
let mut active_user: ArelActiveUser = user.into();
active_user.name.set("n-1");
// active_user.name.set("n-1");
active_user.assign(&ArelActiveUser {
name: Set("n-1"),
..Default::default()
});
let ret = active_user.save().await?;
println!("{}", ret.rows_affected());

Expand Down
12 changes: 6 additions & 6 deletions src/statements/increment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{fmt::Debug, marker::PhantomData};
#[derive(Debug)]
pub struct Increment<M: Arel> {
field: String,
by: i32,
step: i32,
where_fields: Vec<String>,
where_values: Vec<crate::Value>,
_marker: PhantomData<M>,
Expand All @@ -16,10 +16,10 @@ impl<M: Arel> ArelStatement for Increment<M> {
let table_name = M::table_name();
let full_column_name = format!(r#""{}"."{}""#, table_name, self.field);
let mut final_sql = crate::Sql::new(format!(r#"UPDATE "{}" SET "{}" = COALESCE({}, 0)"#, table_name, self.field, full_column_name));
if self.by >= 0 {
final_sql.push_str(&format!(" + {}", self.by));
if self.step >= 0 {
final_sql.push_str(&format!(" + {}", self.step));
} else {
final_sql.push_str(&format!(" - {}", self.by.abs()));
final_sql.push_str(&format!(" - {}", self.step.abs()));
}

final_sql.push_str(" WHERE ");
Expand All @@ -39,10 +39,10 @@ impl<M: Arel> ArelStatement for Increment<M> {
}

impl<M: Arel> Increment<M> {
pub fn new<F: Into<String>, V: Into<crate::Value>>(field: String, by: i32, where_fields: Vec<F>, where_values: Vec<V>) -> Self {
pub fn new<F: Into<String>, V: Into<crate::Value>>(field: String, step: i32, where_fields: Vec<F>, where_values: Vec<V>) -> Self {
Self {
field,
by,
step,
where_fields: where_fields.into_iter().map(|f| f.into()).collect(),
where_values: where_values.into_iter().map(|v| v.into()).collect(),
_marker: PhantomData::<M>,
Expand Down

0 comments on commit 75012dc

Please sign in to comment.