Skip to content

Commit b608d5d

Browse files
committed
Fixed features
1 parent fa0dcd6 commit b608d5d

5 files changed

Lines changed: 32 additions & 9 deletions

File tree

Cargo.toml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ path = "src/main.rs"
2222
[dependencies]
2323
# Internal dependencies
2424
rorm-declaration = { version = "~0.3", path = "../rorm-declaration" }
25-
rorm-sql = { version = "~0.7", path = "../rorm-sql", features = ["sqlite", "mysql", "postgres"] }
25+
rorm-sql = { version = "~0.7", path = "../rorm-sql" }
2626
rorm-db = { version = "0.8.1", path = "../rorm-db" }
2727

2828
# CLI parsing tool
@@ -58,9 +58,28 @@ temp-dir = { version = "~0.1" }
5858
[features]
5959
default = [
6060
"tokio",
61+
"sqlite",
62+
"mysql",
63+
"postgres",
6164
]
6265

6366
tokio = [
6467
"dep:tokio",
6568
"rorm-db/tokio",
69+
]
70+
71+
sqlite = [
72+
"rorm-db/sqlite",
73+
"rorm-declaration/sqlite",
74+
"rorm-sql/sqlite",
75+
]
76+
mysql = [
77+
"rorm-db/mysql",
78+
"rorm-declaration/mysql",
79+
"rorm-sql/mysql",
80+
]
81+
postgres = [
82+
"rorm-db/postgres",
83+
"rorm-declaration/postgres",
84+
"rorm-sql/postgres",
6685
]

src/entry.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ use crate::squash_migrations::squash_migrations;
77

88
#[derive(Subcommand)]
99
pub enum InitDriver {
10+
#[cfg(feature = "sqlite")]
1011
#[clap(about = "Initialize a sqlite configuration")]
1112
Sqlite {
1213
#[clap(long = "filename")]
1314
#[clap(default_value_t = String::from("db.sqlite3"))]
1415
#[clap(help = "Name of the sqlite file.")]
1516
filename: String,
1617
},
18+
#[cfg(feature = "mysql")]
1719
#[clap(about = "Initialize a mysql configuration")]
1820
Mysql {
1921
#[clap(long = "host")]
@@ -43,6 +45,7 @@ pub enum InitDriver {
4345
#[clap(help = "The name of the database to connect to.")]
4446
name: String,
4547
},
48+
#[cfg(feature = "postgres")]
4649
#[clap(about = "Initialize a postgres configuration")]
4750
Postgres {
4851
#[clap(long = "host")]

src/init/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rorm_declaration::config::{DatabaseConfig, DatabaseDriver};
88
use crate::entry::InitDriver;
99
use crate::migrate::config::DatabaseConfigFile;
1010

11+
/// Create the database configuration file
1112
pub fn init(database_configuration: String, driver: InitDriver, force: bool) -> anyhow::Result<()> {
1213
let p = Path::new(&database_configuration);
1314
if p.exists() && !force {
@@ -16,6 +17,7 @@ pub fn init(database_configuration: String, driver: InitDriver, force: bool) ->
1617
}
1718

1819
match driver {
20+
#[cfg(feature = "sqlite")]
1921
InitDriver::Sqlite { filename } => {
2022
let config_file = DatabaseConfigFile {
2123
database: DatabaseConfig {
@@ -31,6 +33,7 @@ pub fn init(database_configuration: String, driver: InitDriver, force: bool) ->
3133

3234
println!("Configuration was written to {}.", &database_configuration);
3335
}
36+
#[cfg(feature = "mysql")]
3437
InitDriver::Mysql {
3538
host,
3639
port,
@@ -65,6 +68,7 @@ pub fn init(database_configuration: String, driver: InitDriver, force: bool) ->
6568

6669
println!("Configuration was written to {}.", &database_configuration);
6770
}
71+
#[cfg(feature = "postgres")]
6872
InitDriver::Postgres {
6973
host,
7074
port,

src/migrate/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::Path;
44
use anyhow::{anyhow, Context};
55
use rorm_db::executor::{Executor, Nothing, Optional};
66
use rorm_db::Database;
7-
use rorm_declaration::config::{DatabaseConfig, DatabaseDriver};
7+
use rorm_declaration::config::DatabaseConfig;
88
use rorm_declaration::imr::{Annotation, DbType};
99
use rorm_declaration::migration::Migration;
1010
use rorm_sql::create_table::CreateTable;
@@ -282,13 +282,6 @@ pub async fn run_migrate(options: MigrateOptions) -> anyhow::Result<()> {
282282

283283
let db_conf = deserialize_db_conf(db_conf_path)?;
284284

285-
if let DatabaseDriver::SQLite { filename } = &db_conf.driver {
286-
if filename.is_empty() {
287-
println!("Invalid configuration: Filename for sqlite is empty");
288-
return Ok(());
289-
}
290-
}
291-
292285
run_migrate_custom(
293286
db_conf,
294287
options.migration_dir,

src/migrate/sql_builder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,22 @@ pub async fn migration_to_sql<'a>(
110110
execute_statement(tx, query_string, query_bind_params, do_log).await?;
111111
}
112112
}
113+
#[allow(unused_variables)]
113114
Operation::RawSQL {
114115
mysql,
115116
postgres,
116117
sqlite,
117118
..
118119
} => match db_impl {
120+
#[cfg(feature = "sqlite")]
119121
DBImpl::SQLite => {
120122
execute_statement(tx, sqlite.clone(), Vec::new(), do_log).await?;
121123
}
124+
#[cfg(feature = "postgres")]
122125
DBImpl::Postgres => {
123126
execute_statement(tx, postgres.clone(), Vec::new(), do_log).await?;
124127
}
128+
#[cfg(feature = "mysql")]
125129
DBImpl::MySQL => {
126130
execute_statement(tx, mysql.clone(), Vec::new(), do_log).await?;
127131
}

0 commit comments

Comments
 (0)