Skip to content

Commit

Permalink
Restructure dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Apr 11, 2021
1 parent 40f52b5 commit 8ee28f1
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 23 deletions.
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ categories = [ "database" ]
keywords = [ "database", "sql", "mysql", "postgres" ]

[package.metadata.docs.rs]
features = []
features = [ "discovery" ]
rustdoc-args = ["--cfg", "docsrs"]

[lib]
Expand All @@ -32,8 +32,14 @@ sqlx = { version = "0.5", optional = true }

[features]
debug_print = []
sqlx-mysql = [ "sqlx/mysql", "futures" ]
sqlx-postgres = [ "sqlx/postgres", "futures" ]
default = [ "discovery" ]
def = [ ]
discovery = [ "futures", "def", "parser", "query" ]
parser = [ "def", "query" ]
query = [ ]
sqlx-dep = [ "sqlx" ]
sqlx-mysql = [ "futures", "sqlx-dep", "sea-query/sqlx-mysql", "sqlx/mysql" ]
sqlx-postgres = [ "futures", "sqlx-dep", "sea-query/sqlx-postgres", "sqlx/postgres" ]
runtime-actix-native-tls = [ "sqlx/runtime-actix-native-tls" ]
runtime-async-std-native-tls = [ "sqlx/runtime-async-std-native-tls" ]
runtime-tokio-native-tls = [ "sqlx/runtime-tokio-native-tls" ]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod mysql;
pub(crate) mod sqlx_types;
pub mod name;
pub(crate) mod parser;
pub(crate) mod util;

// pub use mysql::*;
pub use name::*;
pub use parser::*;
pub use util::*;
30 changes: 30 additions & 0 deletions src/mysql/discovery/executor/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use sea_query::{MysqlQueryBuilder, SelectStatement};
use crate::sqlx_types::{MySqlPool, mysql::MySqlRow};

use crate::debug_print;

pub struct Executor {
pool: MySqlPool,
}

pub trait IntoExecutor {
fn into_executor(self) -> Executor;
}

impl IntoExecutor for MySqlPool {
fn into_executor(self) -> Executor {
Executor {
pool: self
}
}
}

impl Executor {
pub async fn fetch_all(&self, select: SelectStatement) -> Vec<MySqlRow> {
let (sql, values) = select.build(MysqlQueryBuilder);
debug_print!("{}, {:?}", sql, values);
debug_print!();

Vec::new()
}
}
9 changes: 9 additions & 0 deletions src/mysql/discovery/executor/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[cfg(feature="sqlx-mysql")]
mod real;
#[cfg(feature="sqlx-mysql")]
pub use real::*;

#[cfg(not(feature="sqlx-mysql"))]
mod mock;
#[cfg(not(feature="sqlx-mysql"))]
pub use mock::*;
File renamed without changes.
5 changes: 3 additions & 2 deletions src/mysql/discovery/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! To query & parse MySQL's INFORMATION_SCHEMA and construct a `Schema`
use std::rc::Rc;
use futures::future;
use sea_query::{Alias, Iden, IntoIden};
Expand All @@ -7,8 +9,7 @@ use crate::mysql::def::*;
use crate::debug_print;

mod executor;

use executor::*;
pub use executor::*;

pub struct SchemaDiscovery {
pub query: SchemaQueryBuilder,
Expand Down
5 changes: 4 additions & 1 deletion src/mysql/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#[cfg(feature="def")]
pub mod def;
#[cfg(feature="sqlx-mysql")]
#[cfg(feature="discovery")]
pub mod discovery;
#[cfg(feature="parser")]
pub mod parser;
#[cfg(feature="query")]
pub mod query;
12 changes: 9 additions & 3 deletions src/mysql/query/column.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::rc::Rc;
#[cfg(feature="sqlx-mysql")]
use sqlx::{Row, mysql::MySqlRow};
use sea_query::{Expr, Iden, Order, Query, SelectStatement};
use crate::sqlx_types::{Row, mysql::MySqlRow};
use super::{InformationSchema, SchemaQueryBuilder};

#[derive(Debug, sea_query::Iden)]
Expand Down Expand Up @@ -31,7 +30,7 @@ pub enum ColumnFields {
SrsId,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ColumnQueryResult {
pub column_name: String,
pub column_type: String,
Expand Down Expand Up @@ -79,3 +78,10 @@ impl From<&MySqlRow> for ColumnQueryResult {
}
}
}

#[cfg(not(feature="sqlx-mysql"))]
impl From<&MySqlRow> for ColumnQueryResult {
fn from(row: &MySqlRow) -> Self {
Self::default()
}
}
12 changes: 9 additions & 3 deletions src/mysql/query/constraint.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::rc::Rc;
#[cfg(feature="sqlx-mysql")]
use sqlx::{Row, mysql::MySqlRow};
use sea_query::{Expr, Iden, Order, Query, SelectStatement};
use crate::sqlx_types::{Row, mysql::MySqlRow};
use super::{InformationSchema, SchemaQueryBuilder};

#[derive(Debug, sea_query::Iden)]
Expand Down Expand Up @@ -32,7 +31,7 @@ pub enum ReferentialConstraintsFields {
ReferencedTableName,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct ConstraintQueryResult {
pub constraint_name: String,
pub column_name: String,
Expand Down Expand Up @@ -89,3 +88,10 @@ impl From<&MySqlRow> for ConstraintQueryResult {
}
}
}

#[cfg(not(feature="sqlx-mysql"))]
impl From<&MySqlRow> for ConstraintQueryResult {
fn from(row: &MySqlRow) -> Self {
Self::default()
}
}
12 changes: 9 additions & 3 deletions src/mysql/query/index.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::rc::Rc;
#[cfg(feature="sqlx-mysql")]
use sqlx::{Row, mysql::MySqlRow};
use sea_query::{Expr, Iden, Order, Query, Value, SelectStatement};
use crate::sqlx_types::{Row, mysql::MySqlRow};
use super::{InformationSchema, SchemaQueryBuilder};

#[derive(Debug, sea_query::Iden)]
Expand All @@ -27,7 +26,7 @@ pub enum StatisticsFields {
Expression,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct IndexQueryResult {
pub non_unique: i32,
pub index_name: String,
Expand Down Expand Up @@ -83,3 +82,10 @@ impl From<&MySqlRow> for IndexQueryResult {
}
}
}

#[cfg(not(feature="sqlx-mysql"))]
impl From<&MySqlRow> for IndexQueryResult {
fn from(row: &MySqlRow) -> Self {
Self::default()
}
}
12 changes: 9 additions & 3 deletions src/mysql/query/table.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::rc::Rc;
#[cfg(feature="sqlx-mysql")]
use sqlx::{Row, mysql::MySqlRow};
use sea_query::{Expr, Iden, Order, Query, SelectStatement};
use crate::sqlx_types::{Row, mysql::MySqlRow};
use super::{InformationSchema, SchemaQueryBuilder};

#[derive(Debug, sea_query::Iden)]
Expand Down Expand Up @@ -39,7 +38,7 @@ pub enum TableType {
SystemView,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct TableQueryResult {
pub table_name: String,
pub engine: String,
Expand Down Expand Up @@ -81,3 +80,10 @@ impl From<&MySqlRow> for TableQueryResult {
}
}
}

#[cfg(not(feature="sqlx-mysql"))]
impl From<&MySqlRow> for TableQueryResult {
fn from(row: &MySqlRow) -> Self {
Self::default()
}
}
12 changes: 9 additions & 3 deletions src/mysql/query/version.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#[cfg(feature="sqlx-mysql")]
use sqlx::{Row, mysql::MySqlRow};
use sea_query::{Func, Query, SelectStatement};
use crate::sqlx_types::{Row, mysql::MySqlRow};
use super::SchemaQueryBuilder;

#[derive(sea_query::Iden)]
enum MysqlFunc {
Version,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct VersionQueryResult {
pub version: String,
}
Expand All @@ -29,3 +28,10 @@ impl From<&MySqlRow> for VersionQueryResult {
}
}
}

#[cfg(not(feature="sqlx-mysql"))]
impl From<&MySqlRow> for VersionQueryResult {
fn from(row: &MySqlRow) -> Self {
Self::default()
}
}
7 changes: 7 additions & 0 deletions src/sqlx_types/mock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub struct MySqlPool;

pub mod mysql {
pub struct MySqlRow;
}

pub trait Row {}
9 changes: 9 additions & 0 deletions src/sqlx_types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[cfg(feature="sqlx-dep")]
mod real;
#[cfg(feature="sqlx-dep")]
pub use real::*;

#[cfg(not(feature="sqlx-dep"))]
mod mock;
#[cfg(not(feature="sqlx-dep"))]
pub use mock::*;
1 change: 1 addition & 0 deletions src/sqlx_types/real.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use sqlx::*;
2 changes: 1 addition & 1 deletion tests/mysql_sakila/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2018"
[dependencies]
async-std = "1.8"
sea-schema = { path = "../../", features = [ "sqlx-mysql", "runtime-async-std-native-tls" ] }
sea-query = { version = "*", features = [ "sqlx-mysql" ] }
sea-query = { version = "*", features = [ ] }
sqlx = { version = "*" }

0 comments on commit 8ee28f1

Please sign in to comment.