Comments (6)
I think that I can't use wrapper because result data type is Vec:
let wrapper = db::RB .new_wrapper() .r#in("guid", &guids) .eq("source_id", 1) .check() .unwrap(); let exists: Vec<String> = db::RB.fetch_by_wrapper("", &wrapper).await.unwrap(); println!("{:?}", exists);
error[E0277]: the trait bound `std::string::String: rbatis::crud::CRUDEnable` is not satisfied --> src/main.rs:41:41 | 41 | let exists: Option<String> = db::RB.fetch_by_wrapper("", &wrapper).await.unwrap(); | ^^^^^^^^^^^^^^^^ the trait `rbatis::crud::CRUDEnable` is not implemented for `std::string::String` |
try use macro,Use macros for cleaner and cleaner generation
#[py_sql(rbatis, "select * from biz_activity where delete_flag = 0
AND id in
for item in ids:
#{item}")]
fn py_select_vec(rbatis:&Rbatis,ids: &Vec<String>) -> Vec<String> {
}
#[async_std::test]
pub async fn test_vec() {
fast_log::init_log("requests.log", 1000, log::Level::Info, true);
//use static ref
RB.link("mysql://root:123456@localhost:3306/test").await.unwrap();
let a = py_select_vec(&RB,&vec!["1".to_string(), "2".to_string()]).await.unwrap();
println!("{:?}", a);
}
2020-11-04T21:29:28.816277200+08:00 INFO rbatis::plugin::log - [rbatis] [] Query ==> select * from biz_activity where delete_flag = 0 AND id in ? ?
2020-11-04T21:29:28.816423800+08:00 INFO rbatis::plugin::log - [rbatis] [] Args ==> ["1","2"]
and .... if you use fetch_prepare method
the arg's length must equal to input arg's length
However, we do not recommend using concatenated raw strings and arguments directly。
for example :
RB.fetch_prepare(
"",
r#"
SELECT guid
FROM records
WHERE guid = ANY($1,$2,$3)
AND source_id = $2"#,
vec![json!(&guids[0]),json!(&guids[1]),json!(&guids[2]), json!(&1)]
)
from rbatis.
Hi!
I can't find a way to use an array in queries. Here is an example:#[tokio::main] async fn main() { db::RB .link("postgres://user:[email protected]:5432/db") .await .expect("can't initialize pool"); let guids = vec!["1", "2", "3"]; // absolutely the same result with `let guids = ("1", "2", "3")` let exists: Vec<String> = db::RB .fetch_prepare( "", r#" SELECT guid FROM records WHERE guid = ANY($1) AND source_id = $2"#, &vec![json!(&guids), json!(&1)], ) .await .unwrap(); }
Logs:
[2020-11-04T11:45:51Z INFO rbatis::plugin::log] [rbatis] [] Query ==> SELECT guid FROM records WHERE guid = ANY($1) AND source_id = $2 [2020-11-04T11:45:51Z INFO rbatis::plugin::log] [rbatis] [] Args ==> [["1","2","3"],1] [2020-11-04T11:45:51Z INFO sqlx::query] /* SQLx ping */; rows: 0, elapsed: 614.743µs [2020-11-04T11:45:51Z INFO sqlx::query] SELECT guid FROM records …; rows: 0, elapsed: 1.014ms SELECT guid FROM records WHERE guid = ANY($1) AND source_id = $2 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: E("error returned from database: op ANY/ALL (array) requires array on right side")', src/main.rs:48:10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
You should read doc website https://rbatis.github.io/rbatis.io/#/README_EN?id=wrapper
Here is how to use wrapper
from rbatis.
I think that I can't use wrapper because result data type is Vec:
let wrapper = db::RB
.new_wrapper()
.r#in("guid", &guids)
.eq("source_id", 1)
.check()
.unwrap();
let exists: Vec<String> = db::RB.fetch_by_wrapper("", &wrapper).await.unwrap();
println!("{:?}", exists);
error[E0277]: the trait bound `std::string::String: rbatis::crud::CRUDEnable` is not satisfied
--> src/main.rs:41:41
|
41 | let exists: Option<String> = db::RB.fetch_by_wrapper("", &wrapper).await.unwrap();
| ^^^^^^^^^^^^^^^^ the trait `rbatis::crud::CRUDEnable` is not implemented for `std::string::String`
|
from rbatis.
Finally, you can use fast_log to disable logs from SQLX。
for example:
use fast_log::fast_log::LogAppender;
use fast_log::plugin::file::FileAppender;
use fast_log::plugin::console::ConsoleAppender;
use fast_log::filter::ModuleFilter;
pub fn init_log() {
let mut appenders: Vec<Box<dyn LogAppender>> = vec![
Box::new(FileAppender::new("requests.log"))
];
if true {
appenders.push(Box::new(ConsoleAppender {}));
}
fast_log::init_custom_log(appenders, 1000, log::Level::Info, Box::new(
//NoFilter{}//not filter
//Module
ModuleFilter {
//contains
contains: None,
//exclude_contains
exclude_contains: Some(vec![
"sqlx".to_string()
]),
}
));
}
from rbatis.
So now I see that arrays as parameters not supported.
from rbatis.
So now I see that arrays as parameters not supported.
array param not support in prepare method。
maybe we need add fetch_prepare_wrapper method。
for now you can use rbatis-macro fix this
from rbatis.
Related Issues (20)
- htmlsql_select_page field is filtered problem HOT 2
- The json field of the database is returned as an escaped string HOT 2
- Setting result error using py_sql with single result HOT 1
- Is there any synchronized Chinese document? HOT 3
- Unable to update column to null.
- Prior code to get SQLite version using sqlite_version() works. Now broken. [Solved Manually. See comments] HOT 2
- test_decode_time_zone error
- Variable `recordsValue` should have snake_case name, e.g. `records_value` HOT 5
- Common field processing issues HOT 2
- The document needs to be updated HOT 2
- How to dynamically specify schema HOT 14
- add return primary key value in postgresql HOT 1
- How to use tracing log in rbatis-v4 version HOT 2
- field value with json string, return invalid type: map, expected String error HOT 2
- Setting the maximum connection pool doesn't work well HOT 3
- Hello, I encountered an issue with a plugin dynamically modifying SQL HOT 4
- MySQL keeps re-establishing connections HOT 5
- Does the latest version not support Option single result? HOT 4
- How to use rbatis to implement dynamic structure like Java return value map < string, Object > HOT 3
- rbatis::crud!(Book {},"t_book"); No effect HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rbatis.