CLI Generate Entity for Postgres (#61)
* cli generate entity for Postgres * Fixup
This commit is contained in:
parent
1c73ab0759
commit
3701c86637
@ -20,8 +20,9 @@ clap = { version = "^2.33.3" }
|
|||||||
dotenv = { version = "^0.15" }
|
dotenv = { version = "^0.15" }
|
||||||
async-std = { version = "^1.9", features = [ "attributes" ] }
|
async-std = { version = "^1.9", features = [ "attributes" ] }
|
||||||
sea-orm-codegen = { path = "../sea-orm-codegen" }
|
sea-orm-codegen = { path = "../sea-orm-codegen" }
|
||||||
sea-schema = { version = "^0.2", default-features = false, features = [
|
sea-schema = { version = "^0.2", git = "https://github.com/SeaQL/sea-schema.git", branch = "pg-discovery-writer", default-features = false, features = [
|
||||||
"sqlx-mysql",
|
"sqlx-mysql",
|
||||||
|
"sqlx-postgres",
|
||||||
"discovery",
|
"discovery",
|
||||||
"writer",
|
"writer",
|
||||||
] }
|
] }
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use sea_orm_codegen::{EntityTransformer, OutputFile};
|
use sea_orm_codegen::{EntityTransformer, OutputFile};
|
||||||
use sea_schema::mysql::discovery::SchemaDiscovery;
|
|
||||||
use sqlx::MySqlPool;
|
|
||||||
use std::{error::Error, fmt::Display, fs, io::Write, path::Path, process::Command};
|
use std::{error::Error, fmt::Display, fs, io::Write, path::Path, process::Command};
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
@ -28,14 +26,33 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
|
|||||||
let schema = args.value_of("DATABASE_SCHEMA").unwrap();
|
let schema = args.value_of("DATABASE_SCHEMA").unwrap();
|
||||||
let output_dir = args.value_of("OUTPUT_DIR").unwrap();
|
let output_dir = args.value_of("OUTPUT_DIR").unwrap();
|
||||||
|
|
||||||
let connection = MySqlPool::connect(url).await?;
|
let table_stmts = if url.starts_with("mysql://") {
|
||||||
let schema_discovery = SchemaDiscovery::new(connection, schema);
|
use sea_schema::mysql::discovery::SchemaDiscovery;
|
||||||
let schema = schema_discovery.discover().await;
|
use sqlx::MySqlPool;
|
||||||
let table_stmts = schema
|
|
||||||
.tables
|
let connection = MySqlPool::connect(url).await?;
|
||||||
.into_iter()
|
let schema_discovery = SchemaDiscovery::new(connection, schema);
|
||||||
.map(|schema| schema.write())
|
let schema = schema_discovery.discover().await;
|
||||||
.collect();
|
schema
|
||||||
|
.tables
|
||||||
|
.into_iter()
|
||||||
|
.map(|schema| schema.write())
|
||||||
|
.collect()
|
||||||
|
} else if url.starts_with("postgres://") {
|
||||||
|
use sea_schema::postgres::discovery::SchemaDiscovery;
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
let connection = PgPool::connect(url).await?;
|
||||||
|
let schema_discovery = SchemaDiscovery::new(connection, schema);
|
||||||
|
let schema = schema_discovery.discover().await;
|
||||||
|
schema
|
||||||
|
.tables
|
||||||
|
.into_iter()
|
||||||
|
.map(|schema| schema.write())
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
panic!("This database is not supported ({})", url)
|
||||||
|
};
|
||||||
|
|
||||||
let output = EntityTransformer::transform(table_stmts)?.generate();
|
let output = EntityTransformer::transform(table_stmts)?.generate();
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ name = "sea_orm_codegen"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sea-query = { version = "~0.12.8" }
|
sea-query = { version = "~0.12.8", git = "https://github.com/SeaQL/sea-query.git" }
|
||||||
syn = { version = "^1", default-features = false, features = [
|
syn = { version = "^1", default-features = false, features = [
|
||||||
"derive",
|
"derive",
|
||||||
"parsing",
|
"parsing",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user