Skip to content

Commit

Permalink
Merge pull request #11 from Wilovy09/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilovy09 authored Jan 9, 2025
2 parents 758724a + 3ec30a2 commit 47fb26b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
**/target
**/temp
**/seeders
*.env
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ license = "MIT"
repository = "https://github.com/Wilovy09/Grow-rs"
homepage = "https://github.com/Wilovy09/Grow-rs"

[features]
default = ["libsql", "sqlx"]
libsql = ["dep:grow_libsql"]
sqlx = ["dep:grow_sqlx"]

[dependencies]
clap = { version = "4.5.23", features = ["derive", "string"] }
dotenv = "0.15.0"
tokio = { version = "1.42.0", features = ["full"] }
grow_libsql = { version = "0.1.0", path = "./grow_libsql" }
grow_sqlx = { version = "0.1.0", path = "./grow_sqlx" }
grow_libsql = { version = "0.1.0", path = "./grow_libsql", optional = true }
grow_sqlx = { version = "0.1.0", path = "./grow_sqlx", optional = true }

[[bin]]
name = "grow"
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ cargo install --git https://github.com/Wilovy09/Grow-rs
| grow list | Displays a list of all available seeders in the `seeders/` folder. |
| grow run NAME.ron | Run the seeder. If no file is specified, it will run all seeders in alphabetical order. |

## Cargo features

| Feature | Description |
|-----------|-----------------------------------------------|
| `default` | Install `libsql` && `sqlx databases` support. |
| `libsql` | Install only `libsql` support. |
| `sqlx` | Install only `sqlx databases` support. |

## Seeder Example

A seeder file in `.ron` format could have the following content:
Expand All @@ -42,23 +50,23 @@ A seeder file in `.ron` format could have the following content:
// Table name
User: [
{
"role": "Administrator",
"role": "Admin",
"email": "[email protected]",
"password": "hashed_password_admin",
"created_at": "2024-12-22 12:00:00",
"updated_at": "2024-12-22 12:00:00"
},
{
"role": "Cliente",
"email": "cliente1@example.com",
"password": "hashed_password_cliente1",
"role": "Client",
"email": "client1@example.com",
"password": "hashed_password_client1",
"created_at": "2024-12-22 12:00:00",
"updated_at": "2024-12-22 12:00:00"
},
{
"role": "Cliente",
"email": "cliente2@example.com",
"password": "hashed_password_cliente2",
"role": "Client",
"email": "client2@example.com",
"password": "hashed_password_client2",
"created_at": "2024-12-22 12:00:00",
"updated_at": "2024-12-22 12:00:00"
}
Expand Down Expand Up @@ -87,6 +95,7 @@ The CLI automatically detects the database type via `DATABASE_URL` and handles t
## Features

- [ ] Create a library to run seeder in the code and not with CLI
- [x] Add cargo features to CLI.
- [ ] Add `fake` in column value to create fake data.

Example for `fake` feature:
Expand Down
25 changes: 22 additions & 3 deletions src/commands/infer_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,38 @@ pub async fn infer_database(
) -> Result<String, Box<dyn Error>> {
if let Some(scheme) = database_url.split("://").next() {
match scheme {
#[cfg(feature = "libsql")]
"libsql" => {
println!("LibSQL");
grow_libsql::run_seeder(database_url, file_name).await;
Ok("LibSQL".to_string())
}
#[cfg(not(feature = "libsql"))]
"libsql" => {
let error_message = format!(
"The schema {} is only available with libsql feature\n\
Run: cargo install grow-rs -F libsql\n\
https://github.com/Wilovy09/Grow-rs",
scheme
);
Err(error_message.into())
}
#[cfg(feature = "sqlx")]
"postgres" | "mysql" | "sqlite" => {
println!("SQLx database detected: {}", scheme);
grow_sqlx::run_seeder(&database_url, file_name).await?;
Ok(scheme.to_string())
}
#[cfg(not(feature = "sqlx"))]
"postgres" | "mysql" | "sqlite" => {
let error_message = format!(
"The schema {} is only available with sqlx feature\n\
Run: cargo install grow-rs -F sqlx\n\
https://github.com/Wilovy09/Grow-rs",
scheme
);
Err(error_message.into())
}
_ => {
let error_message = format!("Unknown schema: {}", scheme);
eprintln!("{}", error_message);
Err(error_message.into())
}
}
Expand Down

0 comments on commit 47fb26b

Please sign in to comment.