Make rusqlite-macros optional

This commit is contained in:
gwenn 2023-06-10 12:05:55 +02:00
parent f0670ccadd
commit 7594711721
4 changed files with 9 additions and 12 deletions

View File

@ -122,6 +122,7 @@ fallible-iterator = "0.2"
fallible-streaming-iterator = "0.1" fallible-streaming-iterator = "0.1"
uuid = { version = "1.0", optional = true } uuid = { version = "1.0", optional = true }
smallvec = "1.6.1" smallvec = "1.6.1"
rusqlite-macros = { path = "rusqlite-macros", version = "0.1.0", optional = true }
[dev-dependencies] [dev-dependencies]
doc-comment = "0.3" doc-comment = "0.3"
@ -133,16 +134,12 @@ unicase = "2.6.0"
# Use `bencher` over criterion because it builds much faster and we don't have # Use `bencher` over criterion because it builds much faster and we don't have
# many benchmarks # many benchmarks
bencher = "0.1" bencher = "0.1"
rusqlite-macros = { path = "rusqlite-macros", version = "0.1.0" }
[dependencies.libsqlite3-sys] [dependencies.libsqlite3-sys]
path = "libsqlite3-sys" path = "libsqlite3-sys"
version = "0.26.0" version = "0.26.0"
# FIXME optional
[dependencies.rusqlite-macros]
path = "rusqlite-macros"
version = "0.1.0"
[[test]] [[test]]
name = "config_log" name = "config_log"
harness = false harness = false

View File

@ -12,5 +12,5 @@ categories = ["database"]
proc-macro = true proc-macro = true
[dependencies] [dependencies]
sqlite3-parser = { version = "0.7.0", default-features = false, features = ["YYNOERRORRECOVERY"] } sqlite3-parser = { version = "0.9", default-features = false, features = ["YYNOERRORRECOVERY"] }
fallible-iterator = "0.2" fallible-iterator = "0.3"

View File

@ -17,7 +17,6 @@ pub fn __bind(input: TokenStream) -> TokenStream {
type Result<T> = std::result::Result<T, String>; type Result<T> = std::result::Result<T, String>;
fn try_bind(input: TokenStream) -> Result<TokenStream> { fn try_bind(input: TokenStream) -> Result<TokenStream> {
//eprintln!("INPUT: {:#?}", input);
let (stmt, literal) = { let (stmt, literal) = {
let mut iter = input.clone().into_iter(); let mut iter = input.clone().into_iter();
let stmt = iter.next().unwrap(); let stmt = iter.next().unwrap();
@ -35,7 +34,6 @@ fn try_bind(input: TokenStream) -> Result<TokenStream> {
return Err("expected a plain string literal".to_string()); return Err("expected a plain string literal".to_string());
} }
let sql = strip_matches(&sql, "\""); let sql = strip_matches(&sql, "\"");
//eprintln!("SQL: {}", sql);
let mut parser = Parser::new(sql.as_bytes()); let mut parser = Parser::new(sql.as_bytes());
let ast = match parser.next() { let ast = match parser.next() {
@ -52,8 +50,6 @@ fn try_bind(input: TokenStream) -> Result<TokenStream> {
if info.count == 0 { if info.count == 0 {
return Ok(input); return Ok(input);
} }
//eprintln!("ParameterInfo.count: {:#?}", info.count);
//eprintln!("ParameterInfo.names: {:#?}", info.names);
if info.count as usize != info.names.len() { if info.count as usize != info.names.len() {
return Err("Mixing named and numbered parameters is not supported.".to_string()); return Err("Mixing named and numbered parameters is not supported.".to_string());
} }
@ -61,7 +57,6 @@ fn try_bind(input: TokenStream) -> Result<TokenStream> {
let call_site = literal.span(); let call_site = literal.span();
let mut res = TokenStream::new(); let mut res = TokenStream::new();
for (i, name) in info.names.iter().enumerate() { for (i, name) in info.names.iter().enumerate() {
//eprintln!("(i: {}, name: {})", i + 1, &name[1..]);
res.extend(Some(stmt.clone())); res.extend(Some(stmt.clone()));
res.extend(respan( res.extend(respan(
parse_ts(&format!( parse_ts(&format!(

View File

@ -85,6 +85,7 @@ pub use crate::statement::{Statement, StatementStatus};
pub use crate::transaction::{DropBehavior, Savepoint, Transaction, TransactionBehavior}; pub use crate::transaction::{DropBehavior, Savepoint, Transaction, TransactionBehavior};
pub use crate::types::ToSql; pub use crate::types::ToSql;
pub use crate::version::*; pub use crate::version::*;
#[cfg(feature = "rusqlite-macros")]
#[doc(hidden)] #[doc(hidden)]
pub use rusqlite_macros::__bind; pub use rusqlite_macros::__bind;
@ -232,6 +233,8 @@ macro_rules! named_params {
/// Ok(prepare_and_bind!(db, "SELECT $name, @age, :smart;")) /// Ok(prepare_and_bind!(db, "SELECT $name, @age, :smart;"))
/// } /// }
/// ``` /// ```
#[cfg(feature = "rusqlite-macros")]
#[cfg_attr(docsrs, doc(cfg(feature = "rusqlite-macros")))]
#[macro_export] #[macro_export]
macro_rules! prepare_and_bind { macro_rules! prepare_and_bind {
($conn:expr, $sql:literal) => {{ ($conn:expr, $sql:literal) => {{
@ -246,6 +249,8 @@ macro_rules! prepare_and_bind {
/// * only SQLite `$x` / `@x` / `:x` syntax works (Rust `&x` syntax does not /// * only SQLite `$x` / `@x` / `:x` syntax works (Rust `&x` syntax does not
/// work). /// work).
/// * `$x.y` expression does not work. /// * `$x.y` expression does not work.
#[cfg(feature = "rusqlite-macros")]
#[cfg_attr(docsrs, doc(cfg(feature = "rusqlite-macros")))]
#[macro_export] #[macro_export]
macro_rules! prepare_cached_and_bind { macro_rules! prepare_cached_and_bind {
($conn:expr, $sql:literal) => {{ ($conn:expr, $sql:literal) => {{