Compare commits

1 Commits
main ... master

Author SHA1 Message Date
d194f79abc Enable CI woodpecker
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
2023-02-16 22:30:06 +01:00
24 changed files with 86 additions and 145 deletions

View File

@@ -1,16 +1,18 @@
[package]
name = "advotracker_db"
version = "0.1.0-alpha1"
version = "0.1.0"
authors = ["Ralf Zerres <ralf.zerres@networkx.de>"]
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"
license = "(0BSD OR MIT)"
edition = "2018"
categories = ["command-line-interface"]
#build = "build.rs"
default-run = "new-role"
[profile.release]
panic = "abort"
[profile.dev]
rpath = true
[lib]
name = "advotracker_db"
@@ -20,45 +22,41 @@ crate-type = ["dylib"]
[[bin]]
name = "get-harms"
path = "src/bin/get-harms.rs"
advotrackerdb = { Path="." }
advotracker_db = { Path="." }
[[bin]]
name = "get-roles"
path = "src/bin/get-roles.rs"
advotrackerdb = { Path="." }
advotracker_db = { Path="." }
[[bin]]
name = "get-users"
path = "src/bin/get-users.rs"
advotrackerdb = { Path="." }
advotracker_db = { Path="." }
[[bin]]
name = "new-role"
path = "src/bin/new-role.rs"
advotrackerdb = { Path="." }
advotracker_db = { Path="." }
[[bin]]
name = "new-harm"
path = "src/bin/new-harm.rs"
advotrackerdb = { Path="." }
advotracker_db = { Path="." }
[[bin]]
name = "new-user"
path = "src/bin/new-user.rs"
advotrackerdb = { Path="." }
advotracker_db = { Path="." }
[dependencies]
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" }
chrono = { version = "0.4.15", features = [ "serde" ] }
diesel = { version = "1.4.5", features = [ "chrono", "postgres", "r2d2", "sqlite"] }
diesel = { version = "1.4.5", features = [ "sqlite", "chrono" ] }
dotenv = { version = "0.15.0" }
futures = { version = "0.3.1" }
#ldap3 = { version = "0.6" }
r2d2 = { version = "0.8.7" }
serde = { version = "~1.0", features = [ "derive" ] }
#serde_derive = { version = "1.0" }
serde_json = { version = "~1.0" }

View File

@@ -1,10 +1,3 @@
// SPDX-License-Identifier: 0BSD, MIT
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
*/
fn main() {
println!("hey cargo");
//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
*
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: 0BSD
*/
DROP INDEX IF EXISTS NumberHarm_ix_numberHarm;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,21 +1,18 @@
/*
* advotracker - Hotline tackingtool for Advocats
*
* Copyright 2021 Ralf Zerres <ralf.zerres@networkx.de>
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*/
//use diesel::debug_query;
use diesel::{
prelude::*,
r2d2::{Builder, ConnectionManager, Pool},
};
use diesel::prelude::*;
use diesel::sqlite::SqliteConnection;
use diesel::sqlite::Sqlite;
use dotenv::dotenv;
use std::env;
/// establish a connection
/// establish a sqlite connection
pub fn establish_connection() -> SqliteConnection {
// load our .env file
dotenv().ok();
@@ -25,8 +22,7 @@ pub fn establish_connection() -> SqliteConnection {
// establish a new SQLite connection (taking the reference from 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!
trace!(
@@ -37,31 +33,6 @@ 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
pub fn show_query<T>(query: &T)
where

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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