From 759471172194cd9952f338ef3a6eaac636700972 Mon Sep 17 00:00:00 2001 From: gwenn Date: Sat, 10 Jun 2023 12:05:55 +0200 Subject: [PATCH] Make rusqlite-macros optional --- Cargo.toml | 7 ++----- rusqlite-macros/Cargo.toml | 4 ++-- rusqlite-macros/src/lib.rs | 5 ----- src/lib.rs | 5 +++++ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8c163c9..eca3e34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -122,6 +122,7 @@ fallible-iterator = "0.2" fallible-streaming-iterator = "0.1" uuid = { version = "1.0", optional = true } smallvec = "1.6.1" +rusqlite-macros = { path = "rusqlite-macros", version = "0.1.0", optional = true } [dev-dependencies] 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 # many benchmarks bencher = "0.1" +rusqlite-macros = { path = "rusqlite-macros", version = "0.1.0" } [dependencies.libsqlite3-sys] path = "libsqlite3-sys" version = "0.26.0" -# FIXME optional -[dependencies.rusqlite-macros] -path = "rusqlite-macros" -version = "0.1.0" - [[test]] name = "config_log" harness = false diff --git a/rusqlite-macros/Cargo.toml b/rusqlite-macros/Cargo.toml index 5c5db10..3d40775 100644 --- a/rusqlite-macros/Cargo.toml +++ b/rusqlite-macros/Cargo.toml @@ -12,5 +12,5 @@ categories = ["database"] proc-macro = true [dependencies] -sqlite3-parser = { version = "0.7.0", default-features = false, features = ["YYNOERRORRECOVERY"] } -fallible-iterator = "0.2" +sqlite3-parser = { version = "0.9", default-features = false, features = ["YYNOERRORRECOVERY"] } +fallible-iterator = "0.3" diff --git a/rusqlite-macros/src/lib.rs b/rusqlite-macros/src/lib.rs index 7bfda9d..8dda22c 100644 --- a/rusqlite-macros/src/lib.rs +++ b/rusqlite-macros/src/lib.rs @@ -17,7 +17,6 @@ pub fn __bind(input: TokenStream) -> TokenStream { type Result = std::result::Result; fn try_bind(input: TokenStream) -> Result { - //eprintln!("INPUT: {:#?}", input); let (stmt, literal) = { let mut iter = input.clone().into_iter(); let stmt = iter.next().unwrap(); @@ -35,7 +34,6 @@ fn try_bind(input: TokenStream) -> Result { return Err("expected a plain string literal".to_string()); } let sql = strip_matches(&sql, "\""); - //eprintln!("SQL: {}", sql); let mut parser = Parser::new(sql.as_bytes()); let ast = match parser.next() { @@ -52,8 +50,6 @@ fn try_bind(input: TokenStream) -> Result { if info.count == 0 { return Ok(input); } - //eprintln!("ParameterInfo.count: {:#?}", info.count); - //eprintln!("ParameterInfo.names: {:#?}", info.names); if info.count as usize != info.names.len() { return Err("Mixing named and numbered parameters is not supported.".to_string()); } @@ -61,7 +57,6 @@ fn try_bind(input: TokenStream) -> Result { let call_site = literal.span(); let mut res = TokenStream::new(); for (i, name) in info.names.iter().enumerate() { - //eprintln!("(i: {}, name: {})", i + 1, &name[1..]); res.extend(Some(stmt.clone())); res.extend(respan( parse_ts(&format!( diff --git a/src/lib.rs b/src/lib.rs index 3f6f1c4..12a5d31 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,6 +85,7 @@ pub use crate::statement::{Statement, StatementStatus}; pub use crate::transaction::{DropBehavior, Savepoint, Transaction, TransactionBehavior}; pub use crate::types::ToSql; pub use crate::version::*; +#[cfg(feature = "rusqlite-macros")] #[doc(hidden)] pub use rusqlite_macros::__bind; @@ -232,6 +233,8 @@ macro_rules! named_params { /// Ok(prepare_and_bind!(db, "SELECT $name, @age, :smart;")) /// } /// ``` +#[cfg(feature = "rusqlite-macros")] +#[cfg_attr(docsrs, doc(cfg(feature = "rusqlite-macros")))] #[macro_export] macro_rules! prepare_and_bind { ($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 /// work). /// * `$x.y` expression does not work. +#[cfg(feature = "rusqlite-macros")] +#[cfg_attr(docsrs, doc(cfg(feature = "rusqlite-macros")))] #[macro_export] macro_rules! prepare_cached_and_bind { ($conn:expr, $sql:literal) => {{