Skip to content

Commit

Permalink
Project quality improvements
Browse files Browse the repository at this point in the history
* Move helper types from application into seaography

* Running cargo fmt on generated files

* Generate Cargo.toml from template

* Update SeaQL dependencies to latest version

* Specify Cargo authors

* create the root folder if not exists
  • Loading branch information
karatakis committed Sep 9, 2022
1 parent bc36f4c commit 3e0cf74
Show file tree
Hide file tree
Showing 31 changed files with 496 additions and 1,038 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
name = "seaography"
version = "0.1.0"
edition = "2021"
authors = ["Panagiotis Karatakis <panagiotiskaratakis@gmail.com>"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
seaography_generator = { path = "./generator" }
clap = { version = "3.2.6", features = ["derive"] }
seaography_derive = { path = "./derive" }
clap = { version = "3.2.20", features = ["derive"] }
async-std = { version = "1.12.0", features = [ "attributes", "tokio1" ] }
async-graphql = { version = "4.0.12", features = [ "decimal", "chrono", "dataloader" ] }
sea-orm = '0.9.2'

[workspace]
members = [
Expand Down
5 changes: 3 additions & 2 deletions derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
name = "seaography_derive"
version = "0.1.0"
edition = "2021"
authors = ["Panagiotis Karatakis <panagiotiskaratakis@gmail.com>"]

[lib]
proc-macro = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
quote = "1.0.18"
quote = "1.0.21"
syn = { version = "1.0.99" }
proc-macro2 = "1.0.37"
proc-macro2 = "1.0.43"
bae = "0.1.7"
heck = "0.4.0"
8 changes: 4 additions & 4 deletions derive/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn filter_struct(
|| type_literal.starts_with("Vec")
{
quote! {
crate::TypeFilter<#ty>
seaography::TypeFilter<#ty>
}
} else {
let ident = format_ident!("{}EnumFilter", type_literal);
Expand Down Expand Up @@ -128,7 +128,7 @@ pub fn order_by_struct(
.iter()
.map(|(ident, _)| {
quote! {
#ident: Option<crate::OrderByEnum>
#ident: Option<seaography::OrderByEnum>
}
})
.collect();
Expand Down Expand Up @@ -158,8 +158,8 @@ pub fn order_by_fn(fields: &Vec<IdentTypeTuple>) -> Result<TokenStream, crate::e
quote! {
let stmt = if let Some(order_by) = order_by_struct.#ident {
match order_by {
crate::OrderByEnum::Asc => stmt.order_by(Column::#column, sea_orm::query::Order::Asc),
crate::OrderByEnum::Desc => stmt.order_by(Column::#column, sea_orm::query::Order::Desc),
seaography::OrderByEnum::Asc => stmt.order_by(Column::#column, sea_orm::query::Order::Asc),
seaography::OrderByEnum::Desc => stmt.order_by(Column::#column, sea_orm::query::Order::Desc),
}
} else {
stmt
Expand Down
7 changes: 3 additions & 4 deletions discoverer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
name = "seaography_discoverer"
version = "0.1.0"
edition = "2021"
authors = ["Panagiotis Karatakis <panagiotiskaratakis@gmail.com>"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-std = { version = "1.12.0", features = [ "attributes", "tokio1" ] }
serde_json = "1.0.81"
serde = "1.0.137"
sea-schema = { version = "^0.9.3", default-features = false, features = ["sqlx-sqlite", "sqlx-mysql", "sqlx-postgres", "runtime-async-std-native-tls", "discovery", "writer" ] }
sqlx = { version = "0.6.0", features = [ "sqlite", "mysql", "postgres", "runtime-async-std-native-tls" ] }
sea-schema = { version = "0.9.3", default-features = false, features = ["sqlx-sqlite", "sqlx-mysql", "sqlx-postgres", "runtime-async-std-native-tls", "discovery", "writer" ] }
sqlx = { version = "0.6.1", features = [ "sqlite", "mysql", "postgres", "runtime-async-std-native-tls", "all-types" ] }
itertools = "0.10.3"
heck = "0.4.0"
url = "2.2.2"
7 changes: 0 additions & 7 deletions discoverer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pub enum Error {
SqlxError(sqlx::Error),
Error(String),
SerdeJson(serde_json::Error),
}

impl From<sqlx::Error> for Error {
Expand All @@ -17,10 +16,4 @@ impl From<&str> for Error {
}
}

impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Self {
Self::SerdeJson(err)
}
}

pub type Result<T> = std::result::Result<T, Error>;
63 changes: 16 additions & 47 deletions examples/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,22 @@
edition = '2021'
name = 'generated'
version = '0.1.0'
[dependencies.async-graphql]
version = '4.0.10'
features = [
'decimal',
'chrono',
'dataloader',
]

[dependencies.async-graphql-poem]
version = '4.0.10'

[dependencies.async-trait]
version = '0.1.53'

[dependencies.heck]
version = '0.4.0'

[dependencies.itertools]
version = '0.10.3'

[dependencies.poem]
version = '1.3.29'

[dependencies.sea-orm]
version = '0.7.0'
features = [
'sqlx-sqlite',
'runtime-async-std-native-tls',
]

[dependencies.seaography_derive]
path = '../../derive'

[dependencies.tokio]
version = '1.17.0'
features = [
'macros',
'rt-multi-thread',
]

[dependencies.tracing]
version = '0.1.34'

[dependencies.tracing-subscriber]
version = '0.3.11'
[dev-dependencies.serde_json]
version = '1.0.82'
[dependencies]
async-graphql = { version = "4.0.10", features = ["decimal", "chrono", "dataloader"] }
async-graphql-poem = { version = "4.0.10" }
async-trait = { version = "0.1.53" }
heck = { version = "0.4.0" }
itertools = { version = "0.10.3" }
poem = { version = "1.3.29" }
sea-orm = { version = "0.7.0", features = ["sqlx-sqlite", "runtime-async-std-native-tls"] }
seaography = { path = "../../" } # TODO before production place version here
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.34" }
tracing-subscriber = { version = "0.3.11" }

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

[workspace]
members = []
members = []
70 changes: 17 additions & 53 deletions examples/sqlite/src/entities/albums.rs
Original file line number Diff line number Diff line change
@@ -1,75 +1,39 @@
#![doc = " SeaORM Entity. Generated by sea-orm-codegen 0.9.1"]
#![doc = " SeaORM Entity. Generated by sea-orm-codegen 0.9.2"]
use sea_orm::entity::prelude::*;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"albums"
}
}
#[derive(
Clone,
Debug,
PartialEq,
DeriveModel,
DeriveActiveModel,
DeriveEntityModel,
async_graphql :: SimpleObject,
seaography_derive :: Filter,
seaography :: macros :: Filter,
)]
#[sea_orm(table_name = "albums")]
#[graphql(complex)]
#[graphql(name = "Albums")]
pub struct Model {
#[sea_orm(column_name = "AlbumId", primary_key)]
pub album_id: i32,
pub title: String,
pub artist_id: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
#[sea_orm(column_name = "AlbumId")]
AlbumId,
#[sea_orm(column_name = "Title")]
Title,
pub title: String,
#[sea_orm(column_name = "ArtistId")]
ArtistId,
}
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
AlbumId,
}
impl PrimaryKeyTrait for PrimaryKey {
type ValueType = i32;
fn auto_increment() -> bool {
true
}
pub artist_id: i32,
}
#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(
Copy, Clone, Debug, EnumIter, DeriveRelation, seaography :: macros :: RelationsCompact,
)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::artists::Entity",
from = "Column::ArtistId",
to = "super::artists::Column::ArtistId",
on_update = "NoAction",
on_delete = "NoAction"
)]
Artists,
#[sea_orm(has_many = "super::tracks::Entity")]
Tracks,
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::AlbumId => ColumnType::Integer.def(),
Self::Title => ColumnType::String(None).def(),
Self::ArtistId => ColumnType::Integer.def(),
}
}
}
#[seaography_derive::relation]
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Artists => Entity::belongs_to(super::artists::Entity)
.from(Column::ArtistId)
.to(super::artists::Column::ArtistId)
.into(),
Self::Tracks => Entity::has_many(super::tracks::Entity).into(),
}
}
}
impl Related<super::artists::Entity> for Entity {
fn to() -> RelationDef {
Relation::Artists.def()
Expand Down
55 changes: 9 additions & 46 deletions examples/sqlite/src/entities/artists.rs
Original file line number Diff line number Diff line change
@@ -1,66 +1,29 @@
#![doc = " SeaORM Entity. Generated by sea-orm-codegen 0.9.1"]
#![doc = " SeaORM Entity. Generated by sea-orm-codegen 0.9.2"]
use sea_orm::entity::prelude::*;
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;
impl EntityName for Entity {
fn table_name(&self) -> &str {
"artists"
}
}
#[derive(
Clone,
Debug,
PartialEq,
DeriveModel,
DeriveActiveModel,
DeriveEntityModel,
async_graphql :: SimpleObject,
seaography_derive :: Filter,
seaography :: macros :: Filter,
)]
#[sea_orm(table_name = "artists")]
#[graphql(complex)]
#[graphql(name = "Artists")]
pub struct Model {
#[sea_orm(column_name = "ArtistId", primary_key)]
pub artist_id: i32,
pub name: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
#[sea_orm(column_name = "ArtistId")]
ArtistId,
#[sea_orm(column_name = "Name")]
Name,
}
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
ArtistId,
}
impl PrimaryKeyTrait for PrimaryKey {
type ValueType = i32;
fn auto_increment() -> bool {
true
}
pub name: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(
Copy, Clone, Debug, EnumIter, DeriveRelation, seaography :: macros :: RelationsCompact,
)]
pub enum Relation {
#[sea_orm(has_many = "super::albums::Entity")]
Albums,
}
impl ColumnTrait for Column {
type EntityName = Entity;
fn def(&self) -> ColumnDef {
match self {
Self::ArtistId => ColumnType::Integer.def(),
Self::Name => ColumnType::String(None).def().null(),
}
}
}
#[seaography_derive::relation]
impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
match self {
Self::Albums => Entity::has_many(super::albums::Entity).into(),
}
}
}
impl Related<super::albums::Entity> for Entity {
fn to() -> RelationDef {
Relation::Albums.def()
Expand Down
Loading

0 comments on commit 3e0cf74

Please sign in to comment.