Crates.io | sql_db_creator |
lib.rs | sql_db_creator |
version | 0.2.5 |
source | src |
created_at | 2023-01-23 14:25:00.534554 |
updated_at | 2023-01-25 12:08:34.242114 |
description | Generate sql databases by only configure the data of the databases in json files |
homepage | |
repository | https://github.com/Sok-Bou/SQL-DB-Creator |
max_upload_size | |
id | 765854 |
size | 29,477 |
Generate sql databases by only configure the data of the databases in json files
Check the examples after reading.
https://github.com/Sok-Bou/SQL-DB-Creator-Example
With this crate you can generate multiple mysql or postgressql databases and fill them (optional) with data.
By now you folder structure should look like this
📂 src
┣- 📂 db (1)
┃ ┣--- 📂 countries (2)
┃ ┃ ┣ --- 📜 geography.json (3)
┃ ┃ ┗ --- 📜 government.json (4)
┃ ┗--- 📂 flowers (5)
┃ ┃ ┣ --- 📜 infos.json (6)
┃ ┃ ┗ --- 📜 region.json (7)
┣ 📜 main.rs (8)
(1) Required name 'db'
(2) First database with name 'countries'
(3) Table in database 'countries' with name 'geography'
(4) Table in database 'countries' with name 'government'
(5) Second database with name 'flowers'
(6) Table in database 'flowers' with name 'infos'
(7) Table in database 'flowers' with name 'region'
(8) The main file
(mysql example. Database: 'countries', Table: 'geography')
{
"schema": {
"name": "VARCHAR(255)",
"area": "INT(255)",
"region": "VARCHAR(255)",
"costline": "INT(255)",
"borders": "INT(255)",
"is_in_europe": "BIT"
},
"data": [
{
"name": "Germany",
"area": 357021,
"region": "Central Europe",
"costline": 2389,
"borders": 3714,
"is_in_europe": true
},
{
"name": "United States of America",
"area": 9826675,
"region": "North Americs",
"costline": 19920,
"borders": 12191,
"is_in_europe": false
}
]
}
(postgressql example. Database: 'countries', Table: 'geography')
{
"schema": {
"name": "VARCHAR(255)",
"area": "INTEGER",
"region": "VARCHAR(255)",
"costline": "INTEGER",
"borders": "INTEGER",
"is_in_europe": "BOOLEAN"
},
"data": [
{
"name": "Germany",
"area": 357021,
"region": "Central Europe",
"costline": 2389,
"borders": 3714,
"is_in_europe": true
},
{
"name": "United States of America",
"area": 9826675,
"region": "North Americs",
"costline": 19920,
"borders": 12191,
"is_in_europe": false
}
]
}
In the schema part are the infos to create the schema of the table with column names and data types as they appear in the example above. In the data part are the infos to fill the table with our table data. The data section is optional. We can only generate the table. Of course in case we fill the table with data, we have to be careful with the values. The values should have the right type as given in the schema.
(mysql example)
use sql_db_creator::{ DBType, Config, setup };
fn main() {
let config = Config {
user: String::from("root"),
password: String::from("password"),
host: String::from("localhost")
};
setup(DBType::MySql, config);
}
(postgressql example)
use sql_db_creator::{ DBType, Config, setup };
fn main() {
let config = Config {
user: String::from("postgres"),
password: String::from("admin"),
host: String::from("localhost")
};
setup(DBType::PostgresSql, config);
}