mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-25 02:21:37 +08:00
Make rusqlite-macros optional
This commit is contained in:
parent
f0670ccadd
commit
7594711721
@ -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
|
||||
|
@ -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"
|
||||
|
@ -17,7 +17,6 @@ pub fn __bind(input: TokenStream) -> TokenStream {
|
||||
type Result<T> = std::result::Result<T, String>;
|
||||
|
||||
fn try_bind(input: TokenStream) -> Result<TokenStream> {
|
||||
//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<TokenStream> {
|
||||
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<TokenStream> {
|
||||
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<TokenStream> {
|
||||
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!(
|
||||
|
@ -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) => {{
|
||||
|
Loading…
Reference in New Issue
Block a user