Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite schema discovery #34

Merged
merged 17 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,42 @@ jobs:
--manifest-path tests/${{ matrix.project }}/postgres/Cargo.toml
--no-run

compile-sqlite:
name: Compile SQLite
runs-on: ubuntu-20.04
strategy:
matrix:
project: [live, discovery, writer]
steps:
- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
Cargo.lock
target
key: ${{ github.sha }}-${{ github.run_id }}-${{ runner.os }}-sqlite-${{ matrix.project }}

- uses: actions-rs/cargo@v1
with:
command: build
args: >
--manifest-path tests/${{ matrix.project }}/sqlite/Cargo.toml

- uses: actions-rs/cargo@v1
with:
command: test
args: >
--manifest-path tests/${{ matrix.project }}/sqlite/Cargo.toml
--no-run
mysql:
name: MySQL
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -330,3 +366,41 @@ jobs:
command: test
args: >
--manifest-path tests/${{ matrix.project }}/postgres/Cargo.toml

sqlite:
name: SQLite
needs: compile-sqlite
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
project: [live, discovery, writer]
steps:
- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
Cargo.lock
target
key: ${{ github.sha }}-${{ github.run_id }}-${{ runner.os }}-sqlite-${{ matrix.project }}

- uses: actions-rs/cargo@v1
with:
command: run
args: >
--manifest-path tests/${{ matrix.project }}/sqlite/Cargo.toml

- uses: actions-rs/cargo@v1
with:
command: test
args: >
--manifest-path tests/${{ matrix.project }}/sqlite/Cargo.toml
61 changes: 42 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ members = [
".",
"tests/discovery/mysql",
"tests/discovery/postgres",
"tests/discovery/sqlite",
"tests/writer/mysql",
"tests/writer/postgres",
"tests/writer/sqlite",
"tests/live/mysql",
"tests/live/postgres",
"tests/live/sqlite",
]

[package]
Expand All @@ -18,11 +21,11 @@ description = "🌿 SQL schema definition and discovery"
license = "MIT OR Apache-2.0"
documentation = "https://docs.rs/sea-schema"
repository = "https://github.com/SeaQL/sea-schema"
categories = [ "database" ]
keywords = [ "database", "sql", "mysql", "postgres" ]
categories = ["database"]
keywords = ["database", "sql", "mysql", "postgres"]

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

[lib]
Expand All @@ -38,22 +41,42 @@ sqlx = { version = "^0", optional = true }
log = { version = "^0.4", optional = true }

[features]
debug-print = [ "log" ]
default = [ "mysql", "postgres", "discovery", "writer" ]
debug-print = ["log"]
default = ["mysql", "postgres", "discovery", "writer"]
mysql = []
postgres = []
sqlite = []
def = []
discovery = [ "futures", "parser" ]
parser = [ "query" ]
query = [ "def" ]
writer = [ "def" ]
sqlx-dep = [ "sqlx" ]
sqlx-mysql = [ "mysql", "futures", "sqlx-dep", "sea-query/sqlx-mysql", "sqlx/mysql" ]
sqlx-postgres = [ "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" ]
runtime-actix-rustls = [ "sqlx/runtime-actix-rustls" ]
runtime-async-std-rustls = [ "sqlx/runtime-async-std-rustls" ]
runtime-tokio-rustls = [ "sqlx/runtime-tokio-rustls" ]
with-serde = [ "serde" ]
discovery = ["futures", "parser"]
parser = ["query"]
query = ["def"]
writer = ["def"]
sqlx-dep = ["sqlx"]
sqlx-mysql = [
"mysql",
"futures",
"sqlx-dep",
"sea-query/sqlx-mysql",
"sqlx/mysql",
]
sqlx-postgres = [
"postgres",
"futures",
"sqlx-dep",
"sea-query/sqlx-postgres",
"sqlx/postgres",
]
sqlx-sqlite = [
"sqlite",
"futures",
"sqlx-dep",
"sea-query/sqlx-sqlite",
"sqlx/sqlite",
]
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"]
runtime-actix-rustls = ["sqlx/runtime-actix-rustls"]
runtime-async-std-rustls = ["sqlx/runtime-async-std-rustls"]
runtime-tokio-rustls = ["sqlx/runtime-tokio-rustls"]
with-serde = ["serde"]
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ pub mod mysql;
#[cfg_attr(docsrs, doc(cfg(feature = "postgres")))]
pub mod postgres;

#[cfg(feature = "sqlite")]
#[cfg_attr(docsrs, doc(cfg(feature = "sqlite")))]
pub mod sqlite;

pub use sea_query;

pub(crate) mod parser;
Expand Down
10 changes: 3 additions & 7 deletions src/mysql/writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ pub use table::*;
pub use types::*;

use super::def::Schema;
use sea_query::SchemaStatement;
use sea_query::TableCreateStatement;

impl Schema {
pub fn write(&self) -> Vec<SchemaStatement> {
let mut statements = Vec::new();
for table in self.tables.iter() {
statements.push(SchemaStatement::TableStatement(table.write()));
}
statements
pub fn write(&self) -> Vec<TableCreateStatement> {
self.tables.iter().map(|table| table.write()).collect()
}
}
6 changes: 3 additions & 3 deletions src/mysql/writer/table.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::mysql::def::TableDef;
use sea_query::{Alias, Iden, Table, TableStatement};
use sea_query::{Alias, Iden, Table, TableCreateStatement};

impl TableDef {
pub fn write(&self) -> TableStatement {
pub fn write(&self) -> TableCreateStatement {
let mut table = Table::create();
table.table(Alias::new(self.info.name.as_ref()));
for col in self.columns.iter() {
Expand All @@ -17,7 +17,7 @@ impl TableDef {
for key in self.foreign_keys.iter() {
table.foreign_key(&mut key.write());
}
TableStatement::Create(table)
table
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/postgres/writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ pub use table::*;
pub use types::*;

use super::def::Schema;
use sea_query::SchemaStatement;
use sea_query::TableCreateStatement;

impl Schema {
pub fn write(&self) -> Vec<SchemaStatement> {
let mut statements = Vec::new();
for table in self.tables.iter() {
statements.push(SchemaStatement::TableStatement(table.write()));
}
statements
pub fn write(&self) -> Vec<TableCreateStatement> {
self.tables.iter().map(|table| table.write()).collect()
}
}
6 changes: 3 additions & 3 deletions src/postgres/writer/table.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::postgres::def::TableDef;
use sea_query::{Alias, Table, TableStatement};
use sea_query::{Alias, Table, TableCreateStatement};

impl TableDef {
pub fn write(&self) -> TableStatement {
pub fn write(&self) -> TableCreateStatement {
let mut table = Table::create();
table.table(Alias::new(self.info.name.as_ref()));
for col in self.columns.iter() {
Expand All @@ -17,6 +17,6 @@ impl TableDef {
for reference in self.reference_constraints.iter() {
table.foreign_key(&mut reference.write());
}
TableStatement::Create(table)
table
}
}
Loading