Compare commits
4 Commits
4cdb5047ca
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e77d8e672d | ||
|
|
86b2517f83 | ||
|
|
befe6a4d9f | ||
|
|
de3f2af9fc |
@@ -45,7 +45,7 @@ jobs:
|
|||||||
- name: Run SonarQube Scan
|
- name: Run SonarQube Scan
|
||||||
run: |
|
run: |
|
||||||
./sonar-scanner-*/bin/sonar-scanner \
|
./sonar-scanner-*/bin/sonar-scanner \
|
||||||
-Dsonar.projectKey=UdpSocketServer \
|
-Dsonar.projectKey=db_builder \
|
||||||
-Dsonar.sources=. \
|
-Dsonar.sources=. \
|
||||||
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} \
|
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} \
|
||||||
-Dsonar.login=${{ secrets.SONARQUBE_TOKEN }}
|
-Dsonar.login=${{ secrets.SONARQUBE_TOKEN }}
|
||||||
|
|||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -44,7 +44,7 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "db_builder"
|
name = "db_builder"
|
||||||
version = "0.0.0"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "db_builder"
|
name = "db_builder"
|
||||||
version = "0.0.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"
|
description = "This crate enables you to have a lib that create a sqlite database from a json file schema"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -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");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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())
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user