Skip to content

Commit

Permalink
Merge pull request #20 from wslongchen/develop
Browse files Browse the repository at this point in the history
Fixed some bugs.
  • Loading branch information
wslongchen authored Dec 13, 2021
2 parents 7a35169 + c28974b commit dbab83f
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 88 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akita"
version = "0.3.3"
version = "0.3.4"
authors = ["mrpan <[email protected]>"]
edition = "2018"
description = "Akita - Mini orm for rust."
Expand All @@ -14,7 +14,7 @@ license = "MIT"

[dependencies]
akita_derive = {version = "0.3.0", path = "./akita_derive"}
akita_core = {path = "./akita_core"}
akita_core = {version = "0.3.0", path = "./akita_core"}
mysql = {version = "20.1.0", optional = true}
rusqlite = {version = "0.21.0", optional = true}
bigdecimal = "0.3.0"
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ fn main() {
.page::<User>(1, 10).unwrap();

// ...

// Transaction
entity_manager.start_transaction().and_then(|mut transaction| {
let list: Vec<User> = transaction.list(Wrapper::new().eq("name", "Jack"))?;
let insert_id: Option<i32> = transaction.save(&User::default())?;
transaction.commit()
}).unwrap();
}
```

Expand Down
18 changes: 6 additions & 12 deletions akita_core/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ impl From<Vec<Value>> for Params {
}
}

impl <T: ToValue> From<T> for Params {
fn from(x: T) -> Params {
Params::Vector(vec![x.to_value()])
}
}

impl<'a> From<&'a [&'a dyn ToValue]> for Params {
fn from(x: &'a [&'a dyn ToValue]) -> Params {
let values = x.iter().map(|p| p.to_value()).collect::<Vec<Value>>();
Expand Down Expand Up @@ -52,12 +58,6 @@ impl From<Value> for Params {
}
}

impl From<String> for Params {
fn from(x: String) -> Params {
Params::Vector(vec![x.into()])
}
}

impl <'a> From<&'a dyn ToValue> for Params {
fn from(x: &'a dyn ToValue) -> Params {
Params::Vector(vec![x.to_value().to_owned()])
Expand All @@ -77,12 +77,6 @@ macro_rules! into_params_impl {
);
}

impl<'a, T: Into<Params> + Clone> From<&'a T> for Params {
fn from(x: &'a T) -> Params {
x.clone().into()
}
}

into_params_impl!([A, a]);
into_params_impl!([A, a], [B, b]);
into_params_impl!([A, a], [B, b], [C, c]);
Expand Down
5 changes: 3 additions & 2 deletions src/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use akita_core::Table;

use crate::segment::ISegment;
use crate::{AkitaError, AkitaMapper, IPage, Pool, Wrapper, database::DatabasePlatform};
use crate::{cfg_if, Params, TableName, DatabaseName, SchemaContent, TableDef, Rows, FromValue, Value, ToValue, GetFields};
pub struct Akita {
Expand Down Expand Up @@ -481,7 +482,7 @@ impl Akita {

/// build an update clause
pub fn build_update_clause(&mut self) -> Result<String, AkitaError> {
let set_fields = &self.wrapper.fields_set;
let set_fields = &mut self.wrapper.fields_set;
let mut sql = String::new();
sql += &format!("update {} ", &self.table);
if self.db.is_none() {
Expand All @@ -493,7 +494,7 @@ impl Akita {
sql += &format!(
"set {}",
set_fields
.iter()
.iter_mut()
.enumerate()
.map(|(x, (col, value))| {
#[allow(unreachable_patterns)]
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@
//! .table("t_system_user")
//! .wrapper(Wrapper::new().eq("name", "Jack"))
//! .page::<User>(1, 10).unwrap();
//!
//!
//! // Transaction
//! let result = entity_manager.start_transaction().and_then(|mut transaction| {
//! let list: Vec<User> = transaction.list(Wrapper::new().eq("name", "Jack"))?;
//! let insert_id: Option<i32> = transaction.save(&User::default())?;
//! transaction.commit()
//! }).unwrap();
//!
//!
//! }
//! ```
//! ## API Documentation
Expand Down
6 changes: 3 additions & 3 deletions src/manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AkitaError, IPage, Wrapper, database::{Database, DatabasePlatform}, mapper::AkitaMapper, GetFields, GetTableName, FromValue, ToValue, Rows, TableName, DatabaseName, FieldName, Params, Value, FieldType, TableDef};
use crate::{AkitaError, IPage, Wrapper, database::{Database, DatabasePlatform}, mapper::AkitaMapper, GetFields, GetTableName, FromValue, ToValue, Rows, TableName, DatabaseName, FieldName, Params, Value, FieldType, TableDef, segment::ISegment};
/// an interface executing sql statement and getting the results as generic Akita values
/// without any further conversion.
#[allow(unused)]
Expand Down Expand Up @@ -386,7 +386,7 @@ impl AkitaEntityManager{
let table = T::table_name();
let columns = T::fields();
let columns_len = columns.len();
let set_fields = &wrapper.fields_set;
let set_fields = &mut wrapper.fields_set;
let mut sql = String::new();
sql += &format!("update {} ", table.complete_name());

Expand Down Expand Up @@ -415,7 +415,7 @@ impl AkitaEntityManager{
sql += &format!(
"set {}",
set_fields
.iter()
.iter_mut()
.enumerate()
.map(|(x, (col, value))| {
#[allow(unreachable_patterns)]
Expand Down
3 changes: 2 additions & 1 deletion src/platform/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ use std::fmt;
use std::path::{Path, PathBuf};
use std::result::Result;


cfg_if! {if #[cfg(feature = "akita-auth")]{
use crate::auth::{GrantUserPrivilege, Role, UserInfo, DataBaseUser};
}}

use crate::{AkitaConfig, Params, ToValue};
use crate::database::Database;
use crate::pool::LogLevel;
use crate::{comm::{extract_datatype_with_capacity, maybe_trim_parenthesis}, Rows, Value, SqlType, cfg_if, Capacity, ColumnConstraint, ForeignKey, Key, Literal, TableKey, AkitaError, ColumnDef, FieldName, ColumnSpecification, DatabaseName, TableDef, TableName, SchemaContent};
use crate::{self as akita, comm::{extract_datatype_with_capacity, maybe_trim_parenthesis}, Rows, Value, SqlType, cfg_if, Capacity, ColumnConstraint, ForeignKey, Key, Literal, TableKey, AkitaError, ColumnDef, FieldName, ColumnSpecification, DatabaseName, TableDef, TableName, SchemaContent};
type R2d2Pool = Pool<SqliteConnectionManager>;

pub struct SqliteDatabase(r2d2::PooledConnection<SqliteConnectionManager>, AkitaConfig);
Expand Down
Loading

0 comments on commit dbab83f

Please sign in to comment.