Compare commits

...

7 Commits

Author SHA1 Message Date
Namu
e77d8e672d chore: change version to 0.0.1
All checks were successful
Build project / quality-and-build (push) Successful in 10m45s
Build project / SonarQube Trigger (push) Successful in 22s
2026-04-02 11:44:35 +02:00
Namu
86b2517f83 chore: change version to 0.0.1 2026-04-02 11:44:26 +02:00
Namu
befe6a4d9f fix: correct sonarqube project name
All checks were successful
Build project / quality-and-build (push) Successful in 10m46s
Build project / SonarQube Trigger (push) Successful in 21s
2026-04-02 11:24:47 +02:00
Namu
de3f2af9fc refactor: follow clippy recommendation :
Some checks failed
Build project / quality-and-build (push) Successful in 10m41s
Build project / SonarQube Trigger (push) Failing after 14s
- Remove unused constructor for Table & Column
- Add .expect in databases. disconnect
- Remove usedless String::from in column serializer
2026-04-02 11:12:24 +02:00
Namu
4cdb5047ca chore: Add CI
Some checks failed
Build project / quality-and-build (push) Failing after 11m5s
Build project / SonarQube Trigger (push) Has been skipped
2026-04-02 10:52:16 +02:00
Namu
14e1ec8635 chore: Add README 2026-04-02 10:43:10 +02:00
Namu
c0d3dce334 chore: Add package description and licence 2026-04-02 10:35:21 +02:00
9 changed files with 98 additions and 33 deletions

View File

@@ -0,0 +1,51 @@
name: Build project
# run automatically when a push or pull request is triggered
on: [push, pull_request]
jobs:
build:
name: quality-and-build
runs-on: ubuntu-latest
env:
# Limit to 1 job for my little VPS
CARGO_BUILD_JOBS: 1
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Lint with Clippy
run: cargo clippy -- -D warnings
- name: Run build (Debug mode)
run: cargo build
sonarqube:
needs: build
name: SonarQube Trigger
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download SonarQube Scanner
run: |
curl -sSLo sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip
unzip sonar-scanner.zip
- name: Run SonarQube Scan
run: |
./sonar-scanner-*/bin/sonar-scanner \
-Dsonar.projectKey=db_builder \
-Dsonar.sources=. \
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} \
-Dsonar.login=${{ secrets.SONARQUBE_TOKEN }}

2
Cargo.lock generated
View File

@@ -44,7 +44,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]] [[package]]
name = "db_builder" name = "db_builder"
version = "0.1.0" version = "0.0.1"
dependencies = [ dependencies = [
"rusqlite", "rusqlite",
"serde", "serde",

View File

@@ -1,7 +1,9 @@
[package] [package]
name = "db_builder" name = "db_builder"
version = "0.1.0" version = "0.0.1"
edition = "2024" edition = "2024"
description = "This crate enables you to have a lib that create a sqlite database from a json file schema"
license = "MIT"
[dependencies] [dependencies]
serde_json = "1.0.149" serde_json = "1.0.149"

25
README.md Normal file
View File

@@ -0,0 +1,25 @@
# Db Builder
This package enables you to create your SQLite database from a json file
that represent your tables.
## Warnings
DO NOT USE IN PRODUCTION ENVIRONNEMENT, this lib is quickly developed for my personal use !
## Usage
To use this lib, you need to call the facade struct `DbBuilderFacade` and give it
the database path (the db file is created if needed) and the path to the json file that represent your db.
Exemple:
```rust
fn main() {
let facade = DbBuilderFacade{};
match facade.build("schema.json".to_string(), "exemple.db".to_string()) {
Ok(_) => println!("DB created"),
Err(message) => eprintln!("Error creating the db: {}", message)
}
}
```

View File

@@ -1,4 +1,4 @@
use rusqlite::{Connection, Result, Error}; use rusqlite::{Connection, Result};
pub fn connect(db_connection: String) -> Result<Connection> { pub fn connect(db_connection: String) -> Result<Connection> {
Connection::open(db_connection) Connection::open(db_connection)
@@ -8,6 +8,6 @@ pub fn run_command(connection: &Connection, sql: String) -> Result<usize> {
connection.execute(sql.as_str(), []) connection.execute(sql.as_str(), [])
} }
pub fn disconnect(connection: Connection) -> Result<(), (Connection, Error)> { pub fn disconnect(connection: Connection) {
connection.close() connection.close().expect("Error closing sqlite connection");
} }

View File

@@ -26,7 +26,7 @@ impl DbBuilderFacade {
if let Ok(connection) = connection_result { if let Ok(connection) = connection_result {
run_command(&connection, sql_tables).expect("Failed to execute query"); run_command(&connection, sql_tables).expect("Failed to execute query");
disconnect(connection).expect("Failed to disconnect from sqlite"); disconnect(connection);
Ok(()) Ok(())
} else { } else {
Err("Failed to connect to the server".to_string()) Err("Failed to connect to the server".to_string())
@@ -42,7 +42,7 @@ mod tests {
fn test_db_builder() { fn test_db_builder() {
let facade = DbBuilderFacade{}; let facade = DbBuilderFacade{};
match facade.build("./example.json".to_string(), "test_db".to_string()) { match facade.build("./example.json".to_string(), "test.db".to_string()) {
Ok(_) => {assert!(true)}, Ok(_) => {assert!(true)},
Err(message) => {assert!(false, "{}", message)} Err(message) => {assert!(false, "{}", message)}
} }

View File

@@ -6,7 +6,7 @@ pub struct ColumnSqlSerializer {}
impl ColumnSqlSerializer { impl ColumnSqlSerializer {
pub fn serialize(self, column: Column) -> Result<String, String> { pub fn serialize(self, column: Column) -> Result<String, String> {
let mut query = String::from(column.name); let mut query = column.name;
query.push(' '); query.push(' ');
query += &*String::from(column.datatype); query += &*String::from(column.datatype);

View File

@@ -84,6 +84,12 @@ impl ColumnBuilder {
} }
} }
impl Default for ColumnBuilder {
fn default() -> Self {
Self::new()
}
}
pub struct TableBuilder { pub struct TableBuilder {
name: String, name: String,
columns: Vec<Column>, columns: Vec<Column>,
@@ -119,6 +125,12 @@ impl TableBuilder {
} }
} }
impl Default for TableBuilder {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::mappings::SQLiteDatatypes; use crate::mappings::SQLiteDatatypes;

View File

@@ -27,28 +27,3 @@ pub struct Column {
#[serde(default)] #[serde(default)]
pub primary_key: bool pub primary_key: bool
} }
impl Table {
pub fn new(name: String, columns: Vec<Column>, strict: bool) -> Table {
Table {
name,
columns,
strict
}
}
}
impl Column {
pub fn new(name: String, datatype: SQLiteDatatypes, nullable: bool, default: Option<String>, auto_increment: bool, unique: bool, check_constraint: Option<String>, primary_key: bool) -> Column {
Column {
name,
datatype,
nullable,
default,
auto_increment,
unique,
check_constraint,
primary_key
}
}
}