implement facade crate so macros can be used from same namespace

This commit is contained in:
Austin Bonander 2019-11-22 10:30:16 +00:00
parent fecd367e8d
commit fc07830639
122 changed files with 197 additions and 146 deletions

9
.gitignore vendored
View file

@ -12,3 +12,12 @@ Cargo.lock
# Environment
.env
#Added by cargo
#
#already existing elements are commented out
/target
**/*.rs.bk
#Cargo.lock

View file

@ -1,6 +1,8 @@
# This is the sqlx facade crate
[workspace]
members = [
".",
"sqlx-core",
"sqlx-macros",
"examples/tide"
]
@ -12,36 +14,26 @@ license = "MIT OR Apache-2.0"
description = "The Rust SQL Toolkit."
edition = "2018"
authors = [
"Ryan Leckey <leckey.ryan@gmail.com>"
"Ryan Leckey <leckey.ryan@gmail.com>",
"Austin Bonander <austin.bonander@gmail.com>"
]
[features]
default = []
unstable = []
postgres = []
mariadb = []
default = ["macros"]
unstable = ["sqlx-core/unstable"]
postgres = ["sqlx-core/postgres", "sqlx-macros/postgres"]
mariadb = ["sqlx-core/mariadb", "sqlx-macros/mariadb"]
macros = ["sqlx-macros", "proc-macro-hack"]
uuid = ["sqlx-core/uuid", "sqlx-macros/uuid"]
[dependencies]
async-std = { version = "1.1.0", features = ["attributes"] }
async-stream = "0.2.0"
async-trait = "0.1.18"
bitflags = "1.2.1"
byteorder = { version = "1.3.2", default-features = false }
bytes = "0.4.12"
crossbeam-queue = "0.2.0"
crossbeam-utils = { version = "0.7.0", default-features = false }
futures-channel = "0.3.1"
futures-core = "0.3.1"
futures-util = "0.3.1"
log = "0.4.8"
md-5 = "0.8.0"
memchr = "2.2.1"
url = "2.1.0"
uuid = { version = "0.8.1", optional = true }
sqlx-core = { version = "0.1.1-pre", path = "sqlx-core" }
sqlx-macros = { version = "0.1.0", path = "sqlx-macros", optional = true }
proc-macro-hack = { version = "0.5", optional = true }
[dev-dependencies]
async-std = { version = "1.1.0", features = ["attributes"] }
matches = "0.1.8"
sqlx-macros = { path = "sqlx-macros/", features = ["postgres", "mariadb", "uuid"] }
criterion = "0.3.0"
[profile.release]
@ -50,7 +42,7 @@ codegen-units = 1
[[test]]
name = "sql-macro-test"
required-features = ["uuid"]
required-features = ["postgres", "uuid", "macros"]
[[bench]]
name = "postgres_protocol"

41
sqlx-core/Cargo.toml Normal file
View file

@ -0,0 +1,41 @@
[package]
name = "sqlx-core"
version = "0.1.1-pre"
license = "MIT OR Apache-2.0"
description = "The Rust SQL Toolkit."
edition = "2018"
authors = [
"Ryan Leckey <leckey.ryan@gmail.com>",
"Austin Bonander <austin.bonander@gmail.com>"
]
[features]
default = []
unstable = []
postgres = []
mariadb = []
[dependencies]
async-std = { version = "1.1.0", features = ["attributes"] }
async-stream = "0.2.0"
async-trait = "0.1.18"
bitflags = "1.2.1"
byteorder = { version = "1.3.2", default-features = false }
bytes = "0.4.12"
crossbeam-queue = "0.2.0"
crossbeam-utils = { version = "0.7.0", default-features = false }
futures-channel = "0.3.1"
futures-core = "0.3.1"
futures-util = "0.3.1"
log = "0.4.8"
md-5 = "0.8.0"
memchr = "2.2.1"
url = "2.1.0"
uuid = { version = "0.8.1", optional = true }
[dev-dependencies]
matches = "0.1.8"
[profile.release]
lto = true
codegen-units = 1

116
sqlx-core/src/lib.rs Normal file
View file

@ -0,0 +1,116 @@
#[macro_use]
mod macros;
#[macro_use]
pub mod error;
#[cfg(any(feature = "postgres", feature = "mariadb"))]
#[macro_use]
mod io;
mod backend;
pub mod deserialize;
#[cfg(any(feature = "postgres", feature = "mariadb"))]
mod url;
#[macro_use]
mod row;
mod connection;
mod executor;
mod pool;
#[macro_use]
pub mod query;
pub mod serialize;
mod sql;
pub mod types;
mod describe;
mod compiled;
#[doc(inline)]
pub use self::{
backend::Backend,
compiled::CompiledSql,
connection::Connection,
deserialize::FromSql,
error::{Error, Result},
executor::Executor,
pool::Pool,
row::{FromSqlRow, Row},
serialize::ToSql,
sql::{query, SqlQuery},
types::HasSqlType,
};
#[doc(hidden)]
pub use types::HasTypeMetadata;
#[cfg(feature = "mariadb")]
pub mod mariadb;
#[cfg(feature = "mariadb")]
#[doc(inline)]
pub use mariadb::MariaDb;
#[cfg(feature = "postgres")]
pub mod postgres;
#[cfg(feature = "postgres")]
#[doc(inline)]
pub use self::postgres::Postgres;
use std::marker::PhantomData;
// These types allow the `sqlx_macros::sql!()` macro to polymorphically compare a
// given parameter's type to an expected parameter type even if the former
// is behind a reference or in `Option`
#[doc(hidden)]
pub struct TyCons<T>(PhantomData<T>);
impl<T> TyCons<T> {
pub fn new(_t: &T) -> TyCons<T> {
TyCons(PhantomData)
}
}
#[doc(hidden)]
pub trait TyConsExt: Sized {
type Cons;
fn ty_cons(self) -> Self::Cons {
panic!("should not be run, only for type resolution")
}
}
impl<T> TyCons<Option<&'_ T>> {
pub fn ty_cons(self) -> T {
panic!("should not be run, only for type resolution")
}
}
impl<T> TyConsExt for TyCons<&'_ T> {
type Cons = T;
}
impl<T> TyConsExt for TyCons<Option<T>> {
type Cons = T;
}
impl<T> TyConsExt for &'_ TyCons<T> {
type Cons = T;
}
#[test]
fn test_tycons_ext() {
if false {
let _: u64 = TyCons::new(&Some(5u64)).ty_cons();
let _: u64 = TyCons::new(&Some(&5u64)).ty_cons();
let _: u64 = TyCons::new(&&5u64).ty_cons();
let _: u64 = TyCons::new(&5u64).ty_cons();
}
}

Some files were not shown because too many files have changed in this diff Show more