Compare commits

6 Commits
master ... main

Author SHA1 Message Date
94bb674c60 Enable CI woodpecker
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
2023-02-16 22:18:51 +01:00
04eaec69d8 Update copyright and year
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
2021-05-23 14:45:01 +02:00
9e517a8ada Update Cargo.toml
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
2021-05-21 12:10:48 +02:00
da4db8e207 updatetin compiler warnings and documentation strings
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
2021-05-21 12:08:36 +02:00
1ab02a1565 update binaries
* copyright dates
* linting use statements

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
2021-05-21 12:07:41 +02:00
dffac8ead2 update functions
* introduce async handling
* use r2d2 as connection handler

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
2021-05-21 12:02:51 +02:00
24 changed files with 145 additions and 86 deletions

View File

@@ -1,18 +1,16 @@
[package] [package]
name = "advotracker_db" name = "advotracker_db"
version = "0.1.0" version = "0.1.0-alpha1"
authors = ["Ralf Zerres <ralf.zerres@networkx.de>"] authors = ["Ralf Zerres <ralf.zerres@networkx.de>"]
description = "Advotracker crate implementing Database handling.\n" description = "Advotracker crate implementing Database handling.\n"
repository = "https://gitea.networkx.de:50443/rzerres/advotracker_db"
homepage = "https://gitea.networkx.de:50443/rzerres/advotracker_db"
readme = "README.md" readme = "README.md"
license = "(0BSD OR MIT)" license = "(0BSD OR MIT)"
edition = "2018" edition = "2018"
categories = ["command-line-interface"]
#build = "build.rs" #build = "build.rs"
default-run = "new-role"
[profile.release]
panic = "abort"
[profile.dev]
rpath = true
[lib] [lib]
name = "advotracker_db" name = "advotracker_db"
@@ -22,41 +20,45 @@ crate-type = ["dylib"]
[[bin]] [[bin]]
name = "get-harms" name = "get-harms"
path = "src/bin/get-harms.rs" path = "src/bin/get-harms.rs"
advotracker_db = { Path="." } advotrackerdb = { Path="." }
[[bin]] [[bin]]
name = "get-roles" name = "get-roles"
path = "src/bin/get-roles.rs" path = "src/bin/get-roles.rs"
advotracker_db = { Path="." } advotrackerdb = { Path="." }
[[bin]] [[bin]]
name = "get-users" name = "get-users"
path = "src/bin/get-users.rs" path = "src/bin/get-users.rs"
advotracker_db = { Path="." } advotrackerdb = { Path="." }
[[bin]] [[bin]]
name = "new-role" name = "new-role"
path = "src/bin/new-role.rs" path = "src/bin/new-role.rs"
advotracker_db = { Path="." } advotrackerdb = { Path="." }
[[bin]] [[bin]]
name = "new-harm" name = "new-harm"
path = "src/bin/new-harm.rs" path = "src/bin/new-harm.rs"
advotracker_db = { Path="." } advotrackerdb = { Path="." }
[[bin]] [[bin]]
name = "new-user" name = "new-user"
path = "src/bin/new-user.rs" path = "src/bin/new-user.rs"
advotracker_db = { Path="." } advotrackerdb = { Path="." }
[dependencies] [dependencies]
lazy_static = "1.0" lazy_static = "1.0"
async-diesel = { git = "https://github.com/mehcode/async-diesel", branch = "master" }
async-trait = { version = "0.1.21" }
async-std = { version = "1.9.0", features = [ "attributes", "unstable" ] }
bcrypt = { version = "0.8.2" } bcrypt = { version = "0.8.2" }
chrono = { version = "0.4.15", features = [ "serde" ] } chrono = { version = "0.4.15", features = [ "serde" ] }
diesel = { version = "1.4.5", features = [ "sqlite", "chrono" ] } diesel = { version = "1.4.5", features = [ "chrono", "postgres", "r2d2", "sqlite"] }
dotenv = { version = "0.15.0" } dotenv = { version = "0.15.0" }
futures = { version = "0.3.1" }
#ldap3 = { version = "0.6" } #ldap3 = { version = "0.6" }
r2d2 = { version = "0.8.7" }
serde = { version = "~1.0", features = [ "derive" ] } serde = { version = "~1.0", features = [ "derive" ] }
#serde_derive = { version = "1.0" }
serde_json = { version = "~1.0" } serde_json = { version = "~1.0" }

View File

@@ -1,3 +1,10 @@
// SPDX-License-Identifier: 0BSD, MIT
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
*/
fn main() { fn main() {
println!("hey cargo"); println!("hey cargo");
//println!("cargo:rustc-link-lib=dylib=advotracker_db.so"); //println!("cargo:rustc-link-lib=dylib=advotracker_db.so");

View File

@@ -1,8 +1,8 @@
// SPDX-License-Identifier: (0BSD or MIT)
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: 0BSD
*/ */
DROP INDEX IF EXISTS NumberHarm_ix_numberHarm; DROP INDEX IF EXISTS NumberHarm_ix_numberHarm;

View File

@@ -1,8 +1,8 @@
// SPDX-License-Identifier: (0BSD or MIT)
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD, MIT)
*/ */
-- echo ".read <this_file> | -- echo ".read <this_file> |

View File

@@ -1,13 +1,15 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
fn main() { fn main() {
use advotracker_db::functions::db_connection::establish_connection; use advotracker_db::{
use advotracker_db::models::harms::Harm; functions::db_connection::establish_connection,
models::harms::Harm,
};
let connection = establish_connection(); let connection = establish_connection();

View File

@@ -1,16 +1,18 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
fn main() { fn main() {
use diesel::RunQueryDsl; use diesel::RunQueryDsl;
use advotracker_db::functions::db_connection::establish_connection; use advotracker_db::{
use advotracker_db::models::roles::Role; functions::db_connection::establish_connection,
use advotracker_db::schema::roles::dsl::*; models::roles::Role,
schema::roles::dsl::*,
};
let connection = establish_connection(); let connection = establish_connection();

View File

@@ -1,13 +1,16 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
fn main() { fn main() {
use advotracker_db::functions::db_connection::establish_connection;
use advotracker_db::models::users::User; use advotracker_db::{
functions::db_connection::establish_connection,
models::users::User,
};
let connection = establish_connection(); let connection = establish_connection();

View File

@@ -1,7 +1,7 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020_2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
@@ -9,8 +9,10 @@ fn main() {
use chrono::Local; use chrono::Local;
use std::io::{stdin, Read}; use std::io::{stdin, Read};
use advotracker_db::functions::db_connection::*; use advotracker_db::{
use advotracker_db::models::harms::Harm; functions::db_connection::*,
models::harms::Harm,
};
let connection = establish_connection(); let connection = establish_connection();

View File

@@ -1,15 +1,17 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
fn main() { fn main() {
use std::io::{stdin, Read}; use std::io::{stdin, Read};
use advotracker_db::functions::db_connection::*; use advotracker_db::{
use advotracker_db::models::roles::Role; functions::db_connection::*,
models::roles::Role,
};
let connection = establish_connection(); let connection = establish_connection();

View File

@@ -1,15 +1,17 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
fn main() { fn main() {
use std::io::{stdin, Read}; use std::io::{stdin, Read};
use advotracker_db::functions::db_connection::*; use advotracker_db::{
use advotracker_db::models::users::User; functions::db_connection::*,
models::users::User,
};
let connection = establish_connection(); let connection = establish_connection();
@@ -134,7 +136,6 @@ fn main() {
*/ */
// Some data structure. // Some data structure.
//use advotracker_db::models::users::User;
println!( println!(
"\nCreate new json stuct representing user: {} {}", "\nCreate new json stuct representing user: {} {}",
first_name, last_name first_name, last_name
@@ -168,7 +169,7 @@ fn main() {
/* /*
let user_id = 1; let user_id = 1;
let role_id = 1; let role_id = 1;
use advotracker_db::functions::roles::*; use advotrackerdb::functions::roles::*;
let _ = set_user_role(&connection, &user_id, &role_id); let _ = set_user_role(&connection, &user_id, &role_id);
*/ */
} }

View File

@@ -1,18 +1,21 @@
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
//use diesel::debug_query; //use diesel::debug_query;
use diesel::prelude::*; use diesel::{
prelude::*,
r2d2::{Builder, ConnectionManager, Pool},
};
use diesel::sqlite::SqliteConnection; use diesel::sqlite::SqliteConnection;
use diesel::sqlite::Sqlite; use diesel::sqlite::Sqlite;
use dotenv::dotenv; use dotenv::dotenv;
use std::env; use std::env;
/// establish a sqlite connection /// establish a connection
pub fn establish_connection() -> SqliteConnection { pub fn establish_connection() -> SqliteConnection {
// load our .env file // load our .env file
dotenv().ok(); dotenv().ok();
@@ -22,7 +25,8 @@ pub fn establish_connection() -> SqliteConnection {
// establish a new SQLite connection (taking the reference from database_url) // establish a new SQLite connection (taking the reference from database_url)
SqliteConnection::establish(&database_url) SqliteConnection::establish(&database_url)
.unwrap_or_else(|_| panic!("Error connecting to {}", &database_url)) .unwrap_or_else(|_| panic!("Error connecting to {}", &database_url));
/* /*
* WIP: integrate tracing! * WIP: integrate tracing!
trace!( trace!(
@@ -33,6 +37,31 @@ pub fn establish_connection() -> SqliteConnection {
*/ */
} }
/// establish a connection to a db pool
pub fn build() -> Result<Pool<M>, Error> {
// TODO: consume database_url
// precedence in decreasing order:
// 1: commandline
// 2: env
// 3: user_config
// 4: system_config
// load .env file
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
// establish a new SQLite connection (taking the reference from database_url)
// SqliteConnection::establish(&database_url)
// .unwrap_or_else(|_| panic!("Error connecting to {}", &database_url))
// establish a new connection
let manager = ConnectionManager::<SqliteConnection>::new(&database_url);
let pool = Pool::builder.build(manager)?;
Ok(pool)
}
/// show the sql query /// show the sql query
pub fn show_query<T>(query: &T) pub fn show_query<T>(query: &T)
where where

View File

@@ -5,9 +5,8 @@
* SPDX-License-Identifier: (0BSD or MIT) * SPDX-License-Identifier: (0BSD or MIT)
*/ */
// table specific functions /// module handling configuratio of database
/// module handling database connections pub mod config;
pub mod db_connection;
/// module handling harms /// module handling harms
pub mod harms; pub mod harms;

View File

@@ -7,9 +7,14 @@
//#[cfg(test)] //#[cfg(test)]
use async_std::*;
use async_diesel::*;
use chrono::Local; use chrono::Local;
use diesel::debug_query; use diesel::debug_query;
use diesel::prelude::*; use diesel::{
prelude::*,
r2d2::Pool,
};
use diesel::sqlite::{Sqlite, SqliteConnection}; use diesel::sqlite::{Sqlite, SqliteConnection};
use diesel::{QueryDsl, RunQueryDsl}; use diesel::{QueryDsl, RunQueryDsl};
use std::error::Error; use std::error::Error;
@@ -22,17 +27,17 @@ use crate::schema::roles::dsl::*;
use crate::schema::roles::*; use crate::schema::roles::*;
impl Role { impl Role {
// implement CRUD-Functions for our trait // implement CRUD-Functions
// new- -> Create // new- -> Create
// show- -> Read // show- -> Read
// update- -> Update // update- -> Update
// delete- -> Delete // delete- -> Delete
/// create a new role record /// create a new role record
pub fn new( pub async fn new(
param_role_name: &str, param_role_name: &str,
param_id_user_changed: i32, param_id_user_changed: i32,
connection: &SqliteConnection, pool: &Pool,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
//let row = Self::get(param_role_name, param_user_id_changed, &connection); //let row = Self::get(param_role_name, param_user_id_changed, &connection);
//if row.len() == 0 { //if row.len() == 0 {
@@ -45,12 +50,8 @@ impl Role {
}; };
diesel::insert_into(roles::table) diesel::insert_into(roles::table)
.values(struct_role) .values(struct_role)
.execute(connection)?; .execute_async(&pool)
.await?;
Ok(())
//else {
// Err(("row already exists!"))
//}
} }
/* /*

View File

@@ -6,11 +6,12 @@
*/ */
#[cfg(test)] #[cfg(test)]
use diesel::debug_query; use async_std::*;
//use diesel::debug_query;
use diesel::dsl::*; use diesel::dsl::*;
use diesel::prelude::*; use diesel::prelude::*;
#[cfg(test)] //#[cfg(test)]
use diesel::sqlite::Sqlite; //use diesel::sqlite::Sqlite;
#[cfg(test)] #[cfg(test)]
use diesel::sqlite::SqliteConnection; use diesel::sqlite::SqliteConnection;
@@ -34,10 +35,10 @@ fn examine_set_users_default_values() {
} }
/// set user defaults /// set user defaults
pub fn set_roles_default_values(connection: &SqliteConnection) -> QueryResult<usize> { pub async fn set_roles_default_values(pool: &pool) -> QueryResult<usize> {
use schema::roles::dsl::*; use schema::roles::dsl::*;
insert_into(roles).default_values().execute(connection) insert_into(roles).default_values().execute_async(&pool).await?;
} }
#[test] #[test]

View File

@@ -1,27 +1,28 @@
// SPDX-License-Identifier: 0BSD, MIT
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/ */
#![warn(missing_docs, rust_2018_idioms, rust_2018_compatibility)] #![warn(missing_debug_implementation, missing_docs, rust_2018_compatibility, rust_2018_idioms)]
#![recursion_limit="256"] #![recursion_limit="256"]
#![warn(clippy::pedantic)] #![warn(clippy::pedantic)]
//#![warn(clippy::nursery)] //#![warn(clippy::nursery)]
//! advotracker database //! advotracker database
//!
//! Supports lawyers to capture relevant data encountered during an //! Supports lawyers to capture relevant data encountered during an
//! online legal advice. //! online legal advice. This crate handles all database
//! This SQL database backend will consuming Diesel to make use of //! communication. It uses diesel-async and diesel to convert rust
//! sql features. //! structures to create sql queries (ORM). r2d2 is used to manage and
//! utilize a connection pool.
// ?? is this needed in edition 2018 anymore ??
#[macro_use] #[macro_use]
extern crate diesel; extern crate diesel;
/// SQL functions and methods /// SQL functions
pub mod functions; pub mod functions;
/// SQL models definitions /// SQL models definitions

View File

@@ -1,8 +1,8 @@
// SPDX-License-Identifier: (0BSD or MIT)
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/ */
use crate::schema::claim; use crate::schema::claim;

View File

@@ -1,8 +1,8 @@
// SPDX-License-Identifier: (0BSD or MIT)
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/ */
use chrono::NaiveDateTime; use chrono::NaiveDateTime;

View File

@@ -1,8 +1,8 @@
// SPDX-License-Identifier: (0BSD or MIT)
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/ */
use crate::schema::*; use crate::schema::*;

View File

@@ -1,8 +1,8 @@
// SPDX-License-Identifier: (0BSD or MIT)
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/ */
/// defining roles /// defining roles

View File

@@ -1,8 +1,8 @@
// SPDX-License-Identifier: (0BSD or MIT)
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/ */
use chrono::NaiveDateTime; use chrono::NaiveDateTime;

View File

@@ -1,8 +1,8 @@
// SPDX-License-Identifier: (0BSD or MIT)
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/ */
// bring models into scope // bring models into scope

View File

@@ -1,8 +1,8 @@
// SPDX-License-Identifier: (0BSD or MIT)
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/ */
use crate::schema::user_roles; use crate::schema::user_roles;

View File

@@ -1,8 +1,8 @@
// SPDX-License-Identifier: (0BSD or MIT)
/* /*
* advotracker - Hotline tackingtool for Advocats * advotracker - Hotline tackingtool for Advocats
* *
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de> * Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/ */
use chrono::NaiveDateTime; use chrono::NaiveDateTime;

View File

@@ -1,3 +1,10 @@
// SPDX-License-Identifier: 0BSD, MIT
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
*/
#![allow(missing_docs)] #![allow(missing_docs)]
table! { table! {