mirror of
https://github.com/trailbaseio/trailbase.git
synced 2026-05-17 14:58:43 -05:00
Add a generic cargo feature flag for generic SQL connection.
This commit is contained in:
@@ -21,6 +21,7 @@ harness = false
|
||||
|
||||
[features]
|
||||
default = ["pg"]
|
||||
generic = ["pg"]
|
||||
pg = ["dep:postgres", "dep:bytes", "dep:pgrow2serde", "dep:regex"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
pub use crate::sqlite::connection::{ArcLockGuard, Connection, LockError, LockGuard, Options};
|
||||
pub use crate::sqlite::sync::SyncConnection;
|
||||
pub use crate::traits::SyncConnection as SyncConnectionTrait;
|
||||
@@ -54,6 +54,21 @@ impl Connection {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn open_in_memory() -> Result<Self, Error> {
|
||||
return Self::new(|| -> Result<_, Error> {
|
||||
let exec = crate::sqlite::executor::Executor::new(
|
||||
rusqlite::Connection::open_in_memory,
|
||||
crate::sqlite::executor::Options {
|
||||
num_threads: Some(1),
|
||||
..Default::default()
|
||||
},
|
||||
)?;
|
||||
assert_eq!(1, exec.threads());
|
||||
|
||||
return Ok(Executor::Sqlite(exec));
|
||||
});
|
||||
}
|
||||
|
||||
pub fn id(&self) -> usize {
|
||||
return self.id;
|
||||
}
|
||||
|
||||
@@ -10,11 +10,9 @@
|
||||
clippy::needless_continue
|
||||
)]
|
||||
|
||||
mod connection;
|
||||
mod database;
|
||||
mod error;
|
||||
pub mod from_sql;
|
||||
mod generic;
|
||||
mod params;
|
||||
mod rows;
|
||||
pub mod sqlite;
|
||||
@@ -23,18 +21,32 @@ pub mod to_sql;
|
||||
pub mod traits;
|
||||
mod value;
|
||||
|
||||
#[cfg(feature = "pg")]
|
||||
mod generic;
|
||||
#[cfg(feature = "pg")]
|
||||
mod pg;
|
||||
|
||||
pub use connection::{
|
||||
ArcLockGuard, Connection, LockError, LockGuard, Options, SyncConnection, SyncConnectionTrait,
|
||||
};
|
||||
#[cfg(not(feature = "generic"))]
|
||||
mod connection_imports {
|
||||
pub use super::sqlite::connection::{ArcLockGuard, Connection, LockError, LockGuard, Options};
|
||||
pub use super::sqlite::sync::SyncConnection;
|
||||
}
|
||||
|
||||
#[cfg(feature = "generic")]
|
||||
mod connection_imports {
|
||||
pub use super::generic::{Connection, SyncConnection};
|
||||
pub use super::sqlite::connection::{ArcLockGuard, LockError, LockGuard, Options};
|
||||
}
|
||||
|
||||
pub use connection_imports::*;
|
||||
|
||||
pub use database::Database;
|
||||
pub use error::Error;
|
||||
pub use params::{NamedParamRef, NamedParams, NamedParamsRef, Params};
|
||||
pub use rows::{Row, Rows, ValueType};
|
||||
pub use sqlite::transaction::Transaction;
|
||||
pub use statement::Statement;
|
||||
pub use traits::SyncConnection as SyncConnectionTrait;
|
||||
pub use value::{Value, ValueRef};
|
||||
|
||||
#[macro_export]
|
||||
|
||||
@@ -2,9 +2,9 @@ use rusqlite::fallible_iterator::FallibleIterator;
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::util::{columns, from_row};
|
||||
use crate::connection::Connection;
|
||||
use crate::error::Error;
|
||||
use crate::rows::{Column, Rows};
|
||||
use crate::sqlite::connection::Connection;
|
||||
|
||||
/// Batch execute SQL statements and return rows of last statement.
|
||||
///
|
||||
|
||||
@@ -4,7 +4,7 @@ use rusqlite::{ErrorCode, ffi};
|
||||
use serde::Deserialize;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::connection::{Connection, Options};
|
||||
use crate::sqlite::connection::{Connection, Options};
|
||||
use crate::sqlite::extract_row_id;
|
||||
use crate::{Database, Error, SyncConnectionTrait, Value, ValueType};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user