libsql
libsql copied to clipboard
execute params argument isn't compatible with rusqlite
Porting from the example provided by rusqlite in its documentation:
use rusqlite::{Connection, Result};
#[derive(Debug)]
struct Person {
id: i32,
name: String,
data: Option<Vec<u8>>,
}
let me = Person {
id: 0,
name: "Steven".to_string(),
data: None,
};
conn.execute(
"INSERT INTO person (name, data) VALUES (?1, ?2)",
(&me.name, &me.data),
)?;
When ported verbatim to libsql changing only the crate:
use libsql::{Database, Connection, Result};
The following error results:
error[E0277]: the trait bound `libsql::Params: From<(&String, &Option<std::vec::Vec<u8>>)>` is not satisfied
--> src/libsql/mod.rs:29:9
|
27 | conn.execute(
| ------- required by a bound introduced by this call
28 | "INSERT INTO person (name, data) VALUES (?1, ?2)",
29 | (&me.name, &me.data),
| ^^^^^^^^^^^^^^^^^^^^ the trait `From<(&String, &Option<std::vec::Vec<u8>>)>` is not implemented for `libsql::Params`
|
= help: the following other types implement trait `From<T>`:
<libsql::Params as From<()>>
<libsql::Params as From<std::vec::Vec<(String, libsql::Value)>>>
<libsql::Params as From<std::vec::Vec<libsql::Value>>>
= note: required for `(&String, &Option<std::vec::Vec<u8>>)` to implement `Into<libsql::Params>`
note: required by a bound in `libsql::Connection::execute`
--> /Users/doug/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libsql-0.1.6/src/connection.rs:74:12
|
74 | P: Into<Params>,
| ^^^^^^^^^^^^ required by this bound in `Connection::execute`
As someone inexperienced in Rust, the only way I can easily see to make this particular example compile is not straightforward to me:
params![&*me.name]
Also note also that libsql does not seem to accept Option parameters like me.name. Apparently rusqlite takes None to mean SQL NULL that libsql should also take?