Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 94bb674c60 | |||
| 04eaec69d8 | |||
| 9e517a8ada | |||
| da4db8e207 | |||
| 1ab02a1565 | |||
| dffac8ead2 |
32
Cargo.toml
32
Cargo.toml
@@ -1,18 +1,16 @@
|
||||
[package]
|
||||
name = "advotracker_db"
|
||||
version = "0.1.0"
|
||||
version = "0.1.0-alpha1"
|
||||
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"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
||||
[profile.dev]
|
||||
rpath = true
|
||||
default-run = "new-role"
|
||||
|
||||
[lib]
|
||||
name = "advotracker_db"
|
||||
@@ -22,41 +20,45 @@ crate-type = ["dylib"]
|
||||
[[bin]]
|
||||
name = "get-harms"
|
||||
path = "src/bin/get-harms.rs"
|
||||
advotracker_db = { Path="." }
|
||||
advotrackerdb = { Path="." }
|
||||
|
||||
[[bin]]
|
||||
name = "get-roles"
|
||||
path = "src/bin/get-roles.rs"
|
||||
advotracker_db = { Path="." }
|
||||
advotrackerdb = { Path="." }
|
||||
|
||||
[[bin]]
|
||||
name = "get-users"
|
||||
path = "src/bin/get-users.rs"
|
||||
advotracker_db = { Path="." }
|
||||
advotrackerdb = { Path="." }
|
||||
|
||||
[[bin]]
|
||||
name = "new-role"
|
||||
path = "src/bin/new-role.rs"
|
||||
advotracker_db = { Path="." }
|
||||
advotrackerdb = { Path="." }
|
||||
|
||||
[[bin]]
|
||||
name = "new-harm"
|
||||
path = "src/bin/new-harm.rs"
|
||||
advotracker_db = { Path="." }
|
||||
advotrackerdb = { Path="." }
|
||||
|
||||
[[bin]]
|
||||
name = "new-user"
|
||||
path = "src/bin/new-user.rs"
|
||||
advotracker_db = { Path="." }
|
||||
advotrackerdb = { 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 = [ "sqlite", "chrono" ] }
|
||||
diesel = { version = "1.4.5", features = [ "chrono", "postgres", "r2d2", "sqlite"] }
|
||||
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" }
|
||||
|
||||
@@ -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() {
|
||||
println!("hey cargo");
|
||||
//println!("cargo:rustc-link-lib=dylib=advotracker_db.so");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: (0BSD or MIT)
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: 0BSD
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
DROP INDEX IF EXISTS NumberHarm_ix_numberHarm;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: (0BSD or MIT)
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD, MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
-- echo ".read <this_file> |
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
/*
|
||||
* 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)
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
use advotracker_db::functions::db_connection::establish_connection;
|
||||
use advotracker_db::models::harms::Harm;
|
||||
use advotracker_db::{
|
||||
functions::db_connection::establish_connection,
|
||||
models::harms::Harm,
|
||||
};
|
||||
|
||||
let connection = establish_connection();
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
/*
|
||||
* 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)
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
use diesel::RunQueryDsl;
|
||||
|
||||
use advotracker_db::functions::db_connection::establish_connection;
|
||||
use advotracker_db::models::roles::Role;
|
||||
use advotracker_db::schema::roles::dsl::*;
|
||||
use advotracker_db::{
|
||||
functions::db_connection::establish_connection,
|
||||
models::roles::Role,
|
||||
schema::roles::dsl::*,
|
||||
};
|
||||
|
||||
let connection = establish_connection();
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
/*
|
||||
* 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)
|
||||
*/
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* 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)
|
||||
*/
|
||||
|
||||
@@ -9,8 +9,10 @@ fn main() {
|
||||
use chrono::Local;
|
||||
use std::io::{stdin, Read};
|
||||
|
||||
use advotracker_db::functions::db_connection::*;
|
||||
use advotracker_db::models::harms::Harm;
|
||||
use advotracker_db::{
|
||||
functions::db_connection::*,
|
||||
models::harms::Harm,
|
||||
};
|
||||
|
||||
let connection = establish_connection();
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
/*
|
||||
* 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)
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
use std::io::{stdin, Read};
|
||||
|
||||
use advotracker_db::functions::db_connection::*;
|
||||
use advotracker_db::models::roles::Role;
|
||||
use advotracker_db::{
|
||||
functions::db_connection::*,
|
||||
models::roles::Role,
|
||||
};
|
||||
|
||||
let connection = establish_connection();
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
/*
|
||||
* 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)
|
||||
*/
|
||||
|
||||
fn main() {
|
||||
use std::io::{stdin, Read};
|
||||
|
||||
use advotracker_db::functions::db_connection::*;
|
||||
use advotracker_db::models::users::User;
|
||||
use advotracker_db::{
|
||||
functions::db_connection::*,
|
||||
models::users::User,
|
||||
};
|
||||
|
||||
let connection = establish_connection();
|
||||
|
||||
@@ -134,7 +136,6 @@ fn main() {
|
||||
*/
|
||||
|
||||
// Some data structure.
|
||||
//use advotracker_db::models::users::User;
|
||||
println!(
|
||||
"\nCreate new json stuct representing user: {} {}",
|
||||
first_name, last_name
|
||||
@@ -168,7 +169,7 @@ fn main() {
|
||||
/*
|
||||
let user_id = 1;
|
||||
let role_id = 1;
|
||||
use advotracker_db::functions::roles::*;
|
||||
use advotrackerdb::functions::roles::*;
|
||||
let _ = set_user_role(&connection, &user_id, &role_id);
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
/*
|
||||
* 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)
|
||||
*/
|
||||
|
||||
//use diesel::debug_query;
|
||||
use diesel::prelude::*;
|
||||
use diesel::{
|
||||
prelude::*,
|
||||
r2d2::{Builder, ConnectionManager, Pool},
|
||||
};
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use diesel::sqlite::Sqlite;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
|
||||
/// establish a sqlite connection
|
||||
/// establish a connection
|
||||
pub fn establish_connection() -> SqliteConnection {
|
||||
// load our .env file
|
||||
dotenv().ok();
|
||||
@@ -22,7 +25,8 @@ 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!(
|
||||
@@ -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
|
||||
pub fn show_query<T>(query: &T)
|
||||
where
|
||||
@@ -5,9 +5,8 @@
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
// table specific functions
|
||||
/// module handling database connections
|
||||
pub mod db_connection;
|
||||
/// module handling configuratio of database
|
||||
pub mod config;
|
||||
|
||||
/// module handling harms
|
||||
pub mod harms;
|
||||
|
||||
@@ -7,9 +7,14 @@
|
||||
|
||||
//#[cfg(test)]
|
||||
|
||||
use async_std::*;
|
||||
use async_diesel::*;
|
||||
use chrono::Local;
|
||||
use diesel::debug_query;
|
||||
use diesel::prelude::*;
|
||||
use diesel::{
|
||||
prelude::*,
|
||||
r2d2::Pool,
|
||||
};
|
||||
use diesel::sqlite::{Sqlite, SqliteConnection};
|
||||
use diesel::{QueryDsl, RunQueryDsl};
|
||||
use std::error::Error;
|
||||
@@ -22,17 +27,17 @@ use crate::schema::roles::dsl::*;
|
||||
use crate::schema::roles::*;
|
||||
|
||||
impl Role {
|
||||
// implement CRUD-Functions for our trait
|
||||
// implement CRUD-Functions
|
||||
// new- -> Create
|
||||
// show- -> Read
|
||||
// update- -> Update
|
||||
// delete- -> Delete
|
||||
|
||||
/// create a new role record
|
||||
pub fn new(
|
||||
pub async fn new(
|
||||
param_role_name: &str,
|
||||
param_id_user_changed: i32,
|
||||
connection: &SqliteConnection,
|
||||
pool: &Pool,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
//let row = Self::get(param_role_name, param_user_id_changed, &connection);
|
||||
//if row.len() == 0 {
|
||||
@@ -45,12 +50,8 @@ impl Role {
|
||||
};
|
||||
diesel::insert_into(roles::table)
|
||||
.values(struct_role)
|
||||
.execute(connection)?;
|
||||
|
||||
Ok(())
|
||||
//else {
|
||||
// Err(("row already exists!"))
|
||||
//}
|
||||
.execute_async(&pool)
|
||||
.await?;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
*/
|
||||
|
||||
#[cfg(test)]
|
||||
use diesel::debug_query;
|
||||
use async_std::*;
|
||||
//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;
|
||||
|
||||
@@ -34,10 +35,10 @@ fn examine_set_users_default_values() {
|
||||
}
|
||||
|
||||
/// 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::*;
|
||||
|
||||
insert_into(roles).default_values().execute(connection)
|
||||
insert_into(roles).default_values().execute_async(&pool).await?;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
17
src/lib.rs
17
src/lib.rs
@@ -1,27 +1,28 @@
|
||||
// SPDX-License-Identifier: 0BSD, MIT
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2019 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
#![warn(missing_docs, rust_2018_idioms, rust_2018_compatibility)]
|
||||
#![warn(missing_debug_implementation, missing_docs, rust_2018_compatibility, rust_2018_idioms)]
|
||||
#![recursion_limit="256"]
|
||||
|
||||
#![warn(clippy::pedantic)]
|
||||
//#![warn(clippy::nursery)]
|
||||
|
||||
//! advotracker database
|
||||
//!
|
||||
//! Supports lawyers to capture relevant data encountered during an
|
||||
//! online legal advice.
|
||||
//! This SQL database backend will consuming Diesel to make use of
|
||||
//! sql features.
|
||||
//! 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.
|
||||
|
||||
// ?? is this needed in edition 2018 anymore ??
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
||||
/// SQL functions and methods
|
||||
/// SQL functions
|
||||
pub mod functions;
|
||||
|
||||
/// SQL models definitions
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: (0BSD or MIT)
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
use crate::schema::claim;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: (0BSD or MIT)
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: (0BSD or MIT)
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
use crate::schema::*;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: (0BSD or MIT)
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
/// defining roles
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: (0BSD or MIT)
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: (0BSD or MIT)
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
// bring models into scope
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: (0BSD or MIT)
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
use crate::schema::user_roles;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// SPDX-License-Identifier: (0BSD or MIT)
|
||||
/*
|
||||
* advotracker - Hotline tackingtool for Advocats
|
||||
*
|
||||
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
* Copyright 2020-2021 Ralf Zerres <ralf.zerres@networkx.de>
|
||||
*/
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
|
||||
@@ -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)]
|
||||
|
||||
table! {
|
||||
|
||||
Reference in New Issue
Block a user