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

Added ColumnType::Blob #168

Merged
merged 13 commits into from
May 3, 2024
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
52 changes: 6 additions & 46 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
toolchain: stable
components: clippy
- run: cargo clippy --all -- -D warnings
integration-sqlite-poem:
integration-sqlite:
name: SQLite integration tests
runs-on: ubuntu-latest
needs:
Expand All @@ -77,47 +77,7 @@ jobs:
uses: baptiste0928/cargo-install@v2
with:
crate: sea-orm-cli
git: https://github.com/SeaQL/sea-orm
- name: Remove generated folder
run: rm -rf ./examples/sqlite/src
- name: Copy sample database
run: cp ./examples/sqlite/sakila.db .
- name: Generate entities
run: >-
sea-orm-cli generate entity -o examples/sqlite/src/entities -u
sqlite://sakila.db --seaography
- name: Generate Seaography project
uses: actions-rs/cargo@v1
with:
command: run
args: >
--package seaography-cli -- ./examples/sqlite
./examples/sqlite/src/entities sqlite://sakila.db
seaography-sqlite-example -f poem
- name: Depends on local seaography
run: >-
sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"'
./examples/sqlite/Cargo.toml
- name: Build example
working-directory: ./examples/sqlite
run: cargo build
- name: Integration tests
working-directory: ./examples/sqlite
run: cargo test
integration-sqlite-actix:
name: SQLite integration tests actix
runs-on: ubuntu-latest
needs:
- check
- test
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Install sea-orm-cli
uses: baptiste0928/cargo-install@v2
with:
crate: sea-orm-cli
git: https://github.com/SeaQL/sea-orm
version: 1.0.0-rc.4
- name: Remove generated folder
run: rm -rf ./examples/sqlite/src
- name: Copy sample database
Expand Down Expand Up @@ -172,7 +132,7 @@ jobs:
uses: baptiste0928/cargo-install@v2
with:
crate: sea-orm-cli
git: https://github.com/SeaQL/sea-orm
version: 1.0.0-rc.4
- name: Remove generated folder
run: rm -rf ./examples/mysql/src
- name: Create DB
Expand All @@ -198,7 +158,7 @@ jobs:
args: >
--package seaography-cli -- ./examples/mysql
./examples/mysql/src/entities mysql://sea:[email protected]/sakila
seaography-mysql-example
seaography-mysql-example -f axum
- name: Depends on local seaography
run: >-
sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"'
Expand Down Expand Up @@ -236,7 +196,7 @@ jobs:
uses: baptiste0928/cargo-install@v2
with:
crate: sea-orm-cli
git: https://github.com/SeaQL/sea-orm
version: 1.0.0-rc.4
- name: Remove generated folder
run: rm -rf ./examples/postgres/src
- name: Create DB
Expand All @@ -261,7 +221,7 @@ jobs:
--package seaography-cli -- ./examples/postgres
./examples/postgres/src/entities
postgres://sea:[email protected]/sakila?currentSchema=public
seaography-postgres-example
seaography-postgres-example -f poem
- name: Depends on local seaography
run: >-
sed -i '/^\[dependencies.seaography\]$/a \path = "..\/..\/"'
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ with-decimal = ["sea-orm/with-rust_decimal", "async-graphql/decimal"]
with-bigdecimal = ["sea-orm/with-bigdecimal", "async-graphql/bigdecimal"]
with-postgres-array = ["sea-orm/postgres-array"]
# with-ipnetwork = ["sea-orm/with-ipnetwork"]
# with-mac_address = ["sea-orm/with-mac_address"]
# with-mac_address = ["sea-orm/with-mac_address"]
2 changes: 2 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ async fn main() {
pub enum WebFrameworkEnum {
Actix,
Poem,
Axum,
}

impl From<WebFrameworkEnum> for seaography_generator::WebFrameworkEnum {
fn from(framework: WebFrameworkEnum) -> Self {
match framework {
WebFrameworkEnum::Actix => seaography_generator::WebFrameworkEnum::Actix,
WebFrameworkEnum::Poem => seaography_generator::WebFrameworkEnum::Poem,
WebFrameworkEnum::Axum => seaography_generator::WebFrameworkEnum::Axum,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ name = "seaography-mysql-example"
version = "1.0.0-rc.3"

[dependencies]
poem = { version = "3.0" }
async-graphql-poem = { version = "7.0" }
axum = { version = "0.7" }
async-graphql-axum = { version = "7.0" }
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
dotenv = "0.15.0"
sea-orm = { version = "1.0.0-rc", features = ["sqlx-mysql", "runtime-async-std-native-tls", "seaography"] }
Expand All @@ -23,4 +23,4 @@ features = ["with-decimal", "with-chrono"]
serde_json = { version = "1.0.103" }

[workspace]
members = []
members = []
26 changes: 13 additions & 13 deletions examples/mysql/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql_poem::GraphQL;
use async_graphql_axum::GraphQL;
use axum::{
response::{self, IntoResponse},
routing::get,
Router,
};
use dotenv::dotenv;
use lazy_static::lazy_static;
use poem::{get, handler, listener::TcpListener, web::Html, IntoResponse, Route, Server};
use sea_orm::Database;
use std::env;
use tokio::net::TcpListener;

lazy_static! {
static ref URL: String = env::var("URL").unwrap_or("0.0.0.0:8000".into());
static ref URL: String = env::var("URL").unwrap_or("localhost:8000".into());
static ref ENDPOINT: String = env::var("ENDPOINT").unwrap_or("/".into());
static ref DATABASE_URL: String =
env::var("DATABASE_URL").expect("DATABASE_URL environment variable not set");
Expand All @@ -20,9 +25,8 @@ lazy_static! {
});
}

#[handler]
async fn graphql_playground() -> impl IntoResponse {
Html(playground_source(GraphQLPlaygroundConfig::new(&ENDPOINT)))
async fn graphiql() -> impl IntoResponse {
response::Html(playground_source(GraphQLPlaygroundConfig::new(&*ENDPOINT)))
}

#[tokio::main]
Expand All @@ -38,13 +42,9 @@ async fn main() {
let schema =
seaography_mysql_example::query_root::schema(database, *DEPTH_LIMIT, *COMPLEXITY_LIMIT)
.unwrap();
let app = Route::new().at(
&*ENDPOINT,
get(graphql_playground).post(GraphQL::new(schema)),
);
let app = Router::new().route("/", get(graphiql).post_service(GraphQL::new(schema)));
println!("Visit GraphQL Playground at http://{}", *URL);
Server::new(TcpListener::bind(&*URL))
.run(app)
axum::serve(TcpListener::bind(&*URL).await.unwrap(), app)
.await
.expect("Fail to start web server");
.unwrap();
}
2 changes: 1 addition & 1 deletion examples/postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ features = ["with-decimal", "with-chrono", "with-postgres-array"]
serde_json = { version = "1.0.103" }

[workspace]
members = []
members = []
2 changes: 1 addition & 1 deletion examples/postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use sea_orm::Database;
use std::env;

lazy_static! {
static ref URL: String = env::var("URL").unwrap_or("0.0.0.0:8000".into());
static ref URL: String = env::var("URL").unwrap_or("localhost:8000".into());
static ref ENDPOINT: String = env::var("ENDPOINT").unwrap_or("/".into());
static ref DATABASE_URL: String =
env::var("DATABASE_URL").expect("DATABASE_URL environment variable not set");
Expand Down
8 changes: 4 additions & 4 deletions examples/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ name = "seaography-sqlite-example"
version = "1.0.0-rc.3"

[dependencies]
poem = { version = "3.0" }
async-graphql-poem = { version = "7.0" }
actix-web = { version = "4.5", default-features = false, features = ["macros"] }
async-graphql-actix-web = { version = "7.0" }
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
dotenv = "0.15.0"
sea-orm = { version = "1.0.0-rc", features = ["sqlx-sqlite", "runtime-async-std-native-tls", "seaography"] }
sea-orm = { version = "1.0.0-rc", features = ["sqlx-sqlite", "runtime-async-std-rustls", "seaography"] }
tokio = { version = "1.29.1", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.37" }
tracing-subscriber = { version = "0.3.17" }
Expand All @@ -23,4 +23,4 @@ features = ["with-decimal", "with-chrono"]
serde_json = { version = "1.0.103" }

[workspace]
members = []
members = []
47 changes: 30 additions & 17 deletions examples/sqlite/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql_poem::GraphQL;
use actix_web::{guard, web, web::Data, App, HttpResponse, HttpServer, Result};
use async_graphql::{
dynamic::*,
http::{playground_source, GraphQLPlaygroundConfig},
};
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse};
use dotenv::dotenv;
use lazy_static::lazy_static;
use poem::{get, handler, listener::TcpListener, web::Html, IntoResponse, Route, Server};
use sea_orm::Database;
use std::env;

lazy_static! {
static ref URL: String = env::var("URL").unwrap_or("0.0.0.0:8000".into());
static ref URL: String = env::var("URL").unwrap_or("localhost:8000".into());
static ref ENDPOINT: String = env::var("ENDPOINT").unwrap_or("/".into());
static ref DATABASE_URL: String =
env::var("DATABASE_URL").expect("DATABASE_URL environment variable not set");
Expand All @@ -20,13 +23,18 @@ lazy_static! {
});
}

#[handler]
async fn graphql_playground() -> impl IntoResponse {
Html(playground_source(GraphQLPlaygroundConfig::new(&ENDPOINT)))
async fn index(schema: web::Data<Schema>, req: GraphQLRequest) -> GraphQLResponse {
schema.execute(req.into_inner()).await.into()
}

#[tokio::main]
async fn main() {
async fn graphql_playground() -> Result<HttpResponse> {
Ok(HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(playground_source(GraphQLPlaygroundConfig::new(&*ENDPOINT))))
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenv().ok();
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
Expand All @@ -38,13 +46,18 @@ async fn main() {
let schema =
seaography_sqlite_example::query_root::schema(database, *DEPTH_LIMIT, *COMPLEXITY_LIMIT)
.unwrap();
let app = Route::new().at(
&*ENDPOINT,
get(graphql_playground).post(GraphQL::new(schema)),
);
println!("Visit GraphQL Playground at http://{}", *URL);
Server::new(TcpListener::bind(&*URL))
.run(app)
.await
.expect("Fail to start web server");
HttpServer::new(move || {
App::new()
.app_data(Data::new(schema.clone()))
.service(web::resource("/").guard(guard::Post()).to(index))
.service(
web::resource("/")
.guard(guard::Get())
.to(graphql_playground),
)
})
.bind("127.0.0.1:8000")?
.run()
.await
}
2 changes: 1 addition & 1 deletion generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ proc-macro2 = "1.0.66"
syn = { version = "2.0.27", features = ["full"] }
heck = "0.4.1"
itertools = "0.11.0"
sea-query = { version = "0.30.0", default-features = false }
sea-query = { version = "0.31.0-rc", default-features = false }
thiserror = "1.0.44"
2 changes: 2 additions & 0 deletions generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod util;
pub enum WebFrameworkEnum {
Actix,
Poem,
Axum,
}

#[allow(clippy::too_many_arguments)]
Expand All @@ -33,6 +34,7 @@ pub async fn write_project<P: AsRef<std::path::Path>, T: AsRef<std::path::Path>>
match framework {
WebFrameworkEnum::Actix => crate::templates::actix::write_main(src_path, crate_name)?,
WebFrameworkEnum::Poem => crate::templates::poem::write_main(src_path, crate_name)?,
WebFrameworkEnum::Axum => crate::templates::axum::write_main(src_path, crate_name)?,
}

writer::write_env(&root_path.as_ref(), db_url, depth_limit, complexity_limit)?;
Expand Down
12 changes: 3 additions & 9 deletions generator/src/templates/actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub fn generate_main(crate_name: &str) -> TokenStream {
quote! {
use actix_web::{guard, web, web::Data, App, HttpResponse, HttpServer, Result};
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig},
dynamic::*,
http::{playground_source, GraphQLPlaygroundConfig},
};
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse};
use dotenv::dotenv;
Expand All @@ -22,7 +22,7 @@ pub fn generate_main(crate_name: &str) -> TokenStream {
use std::env;

lazy_static! {
static ref URL: String = env::var("URL").unwrap_or("0.0.0.0:8000".into());
static ref URL: String = env::var("URL").unwrap_or("localhost:8000".into());
static ref ENDPOINT: String = env::var("ENDPOINT").unwrap_or("/".into());
static ref DATABASE_URL: String =
env::var("DATABASE_URL").expect("DATABASE_URL environment variable not set");
Expand All @@ -42,9 +42,7 @@ pub fn generate_main(crate_name: &str) -> TokenStream {
async fn graphql_playground() -> Result<HttpResponse> {
Ok(HttpResponse::Ok()
.content_type("text/html; charset=utf-8")
.body(
playground_source(GraphQLPlaygroundConfig::new("http://localhost:8000"))
))
.body(playground_source(GraphQLPlaygroundConfig::new(&*ENDPOINT))))
}

#[actix_web::main]
Expand All @@ -54,15 +52,11 @@ pub fn generate_main(crate_name: &str) -> TokenStream {
.with_max_level(tracing::Level::INFO)
.with_test_writer()
.init();

let database = Database::connect(&*DATABASE_URL)
.await
.expect("Fail to initialize database connection");

let schema = #crate_name_token::query_root::schema(database, *DEPTH_LIMIT, *COMPLEXITY_LIMIT).unwrap();

println!("Visit GraphQL Playground at http://{}", *URL);

HttpServer::new(move || {
App::new()
.app_data(Data::new(schema.clone()))
Expand Down
6 changes: 3 additions & 3 deletions generator/src/templates/actix_cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
edition = "2021"
name = "<seaography-package-name>"
version = "0.3.0"
version = "0.1.0"

[dependencies]
actix-web = { version = "4.3.1", default-features = false, features = ["macros"] }
actix-web = { version = "4.5", default-features = false, features = ["macros"] }
async-graphql-actix-web = { version = "7.0" }
async-graphql = { version = "7.0", features = ["decimal", "chrono", "dataloader", "dynamic-schema"] }
dotenv = "0.15.0"
Expand All @@ -22,4 +22,4 @@ features = ["with-decimal", "with-chrono"]
serde_json = { version = "1.0.103" }

[workspace]
members = []
members = []
Loading
Loading