Skip to content

Commit

Permalink
Re-export internal dependency instead of leaking it into user package
Browse files Browse the repository at this point in the history
* Re-export internal dependency instead of leaking it into user package

* Write seaography version dynamically

* CI generated examples depends on local seaography
  • Loading branch information
billy1624 authored Oct 8, 2022
1 parent a4209f8 commit 57da29c
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ jobs:
args: >
--package seaography-cli --
sqlite://sakila.db seaography-sqlite-example ./examples/sqlite
- name: Depends on local seaography
run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/sqlite/Cargo.toml
- name: Integration tests
working-directory: ./examples/sqlite
run: cargo test
Expand Down Expand Up @@ -145,6 +147,8 @@ jobs:
args: >
--package seaography-cli --
mysql://sea:[email protected]/sakila seaography-mysql-example ./examples/mysql
- name: Depends on local seaography
run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/mysql/Cargo.toml
- name: Integration tests
working-directory: ./examples/mysql
run: cargo test
Expand Down Expand Up @@ -192,6 +196,8 @@ jobs:
args: >
--package seaography-cli --
postgres://sea:[email protected]/sakila?currentSchema=public seaography-postgres-example ./examples/postgres
- name: Depends on local seaography
run: sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"' ./examples/postgres/Cargo.toml
- name: Integration tests
working-directory: ./examples/postgres
run: cargo test
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ categories = ["database"]
async-graphql = { version = "4.0.12", default-features = false }
seaography-derive = { version = "^0.1", path = "./derive" }
sea-orm = { version = "^0.9", default-features = false }
itertools = { version = "0.10.3" }
heck = { version = "0.4.0" }

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion derive/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub fn filter_struct(
// let type_name = quote!{
// impl async_graphql::TypeName for Filter {
// fn type_name() -> ::std::borrow::Cow<'static, str> {
// use heck::ToUpperCamelCase;
// use seaography::heck::ToUpperCamelCase;

// let filter_name = format!("{}Filter", Entity::default().table_name().to_string().to_upper_camel_case());

Expand Down
6 changes: 3 additions & 3 deletions derive/src/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn relation_fn(
let (return_type, extra_imports, map_method) = if has_many.is_some() {
(
quote! { Vec<#target_model> },
quote! { use itertools::Itertools; },
quote! { use seaography::itertools::Itertools; },
quote! { .into_group_map() },
)
} else if belongs_to.is_some() {
Expand Down Expand Up @@ -270,7 +270,7 @@ pub fn relation_fn(
&self,
keys: &[#foreign_key_name],
) -> Result<std::collections::HashMap<#foreign_key_name, Self::Value>, Self::Error> {
use heck::ToSnakeCase;
use seaography::heck::ToSnakeCase;
use ::std::str::FromStr;

let key_values: Vec<_> = keys
Expand Down Expand Up @@ -313,7 +313,7 @@ pub fn relation_fn(
&self,
ctx: &async_graphql::Context<'a>,
) -> Option<#return_type> {
use heck::ToSnakeCase;
use seaography::heck::ToSnakeCase;
use ::std::str::FromStr;

let data_loader = ctx
Expand Down
8 changes: 5 additions & 3 deletions examples/mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ async-graphql = { version = "4.0.10", features = ["decimal", "chrono", "dataload
async-graphql-poem = { version = "4.0.10" }
async-trait = { version = "0.1.53" }
dotenv = "0.15.0"
heck = { version = "0.4.0" }
itertools = { version = "0.10.3" }
poem = { version = "1.3.29" }
sea-orm = { version = "^0.9", features = ["sqlx-mysql", "runtime-async-std-native-tls"] }
seaography = { version = "^0.1", features = [ "with-decimal", "with-chrono" ] }
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.34" }
tracing-subscriber = { version = "0.3.11" }

[dependencies.seaography]
path = "../../" # remove this line in your own project
version = "^0.1" # seaography version
features = ["with-decimal", "with-chrono"]

[dev-dependencies]
serde_json = { version = '1.0.82' }

Expand Down
8 changes: 5 additions & 3 deletions examples/postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ async-graphql = { version = "4.0.10", features = ["decimal", "chrono", "dataload
async-graphql-poem = { version = "4.0.10" }
async-trait = { version = "0.1.53" }
dotenv = "0.15.0"
heck = { version = "0.4.0" }
itertools = { version = "0.10.3" }
poem = { version = "1.3.29" }
sea-orm = { version = "^0.9", features = ["sqlx-postgres", "runtime-async-std-native-tls"] }
seaography = { version = "^0.1", features = [ "with-decimal", "with-chrono" ] }
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.34" }
tracing-subscriber = { version = "0.3.11" }

[dependencies.seaography]
path = "../../" # remove this line in your own project
version = "^0.1" # seaography version
features = ["with-decimal", "with-chrono"]

[dev-dependencies]
serde_json = { version = '1.0.82' }

Expand Down
8 changes: 5 additions & 3 deletions examples/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ async-graphql = { version = "4.0.10", features = ["decimal", "chrono", "dataload
async-graphql-poem = { version = "4.0.10" }
async-trait = { version = "0.1.53" }
dotenv = "0.15.0"
heck = { version = "0.4.0" }
itertools = { version = "0.10.3" }
poem = { version = "1.3.29" }
sea-orm = { version = "^0.9", features = ["sqlx-sqlite", "runtime-async-std-native-tls"] }
seaography = { version = "^0.1", features = [ "with-decimal", "with-chrono" ] }
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.34" }
tracing-subscriber = { version = "0.3.11" }

[dependencies.seaography]
path = "../../" # remove this line in your own project
version = "^0.1" # seaography version
features = ["with-decimal", "with-chrono"]

[dev-dependencies]
serde_json = { version = '1.0.82' }

Expand Down
7 changes: 4 additions & 3 deletions generator/src/_Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ async-graphql = { version = "4.0.10", features = ["decimal", "chrono", "dataload
async-graphql-poem = { version = "4.0.10" }
async-trait = { version = "0.1.53" }
dotenv = "0.15.0"
heck = { version = "0.4.0" }
itertools = { version = "0.10.3" }
poem = { version = "1.3.29" }
sea-orm = { version = "^0.9", features = ["<seaography-sql-library>", "runtime-async-std-native-tls"] }
seaography = { version = "^0.1", features = [ "with-decimal", "with-chrono" ] }
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.34" }
tracing-subscriber = { version = "0.3.11" }

[dependencies.seaography]
version = "<seaography-version>" # seaography version
features = ["with-decimal", "with-chrono"]

[dev-dependencies]
serde_json = { version = '1.0.82' }

Expand Down
15 changes: 10 additions & 5 deletions generator/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ pub fn write_cargo_toml<P: AsRef<std::path::Path>>(
) -> std::io::Result<()> {
let file_path = path.as_ref().join("Cargo.toml");

let content = include_str!("_Cargo.toml");

let content = content.replace("<seaography-package-name>", crate_name);

let content = content.replace("<seaography-sql-library>", sql_library);
let ver = format!(
"^{}.{}.0",
env!("CARGO_PKG_VERSION_MAJOR"),
env!("CARGO_PKG_VERSION_MINOR")
);

let content = include_str!("_Cargo.toml")
.replace("<seaography-package-name>", crate_name)
.replace("<seaography-sql-library>", sql_library)
.replace("<seaography-version>", &ver);

std::fs::write(file_path, content.as_bytes())?;

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
//!
//! Seaography is a community driven project. We welcome you to participate, contribute and together build for Rust's future.

pub use heck;
pub use itertools;
pub use seaography_derive as macros;

#[derive(Debug, Clone, Copy, PartialEq, Eq, async_graphql::Enum)]
Expand Down

0 comments on commit 57da29c

Please sign in to comment.