Added license notices to every source file

This commit is contained in:
Johannes Randerath
2024-08-28 23:29:32 +02:00
parent 0c2c428ce4
commit c7ec089d06
98 changed files with 879 additions and 1882 deletions

View File

@@ -1,3 +1,21 @@
# This file is part of inventur.
# inventur is a simple web app using rocket to help maintain inventory data.
# Copyright (C) 2024 Johannes Randerath
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
[package]
name = "inventur_db"
version = "0.1.0"

View File

@@ -1,3 +1,21 @@
# This file is part of inventur.
# inventur is a simple web app using rocket to help maintain inventory data.
# Copyright (C) 2024 Johannes Randerath
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli

View File

@@ -1 +1,19 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
DROP TABLE jrtables;

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
CREATE TABLE jrtables (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,

View File

@@ -1 +1,19 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
DROP TABLE jrcolumns;

View File

@@ -1 +0,0 @@
-- This file should undo anything in `up.sql`

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
CREATE TABLE jrcolumns (
id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY,
name VARCHAR(255) NOT NULL,

View File

@@ -1,9 +0,0 @@
CREATE TABLE jrcolumns (
id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
jrtable_id INTEGER NOT NULL,
FOREIGN KEY jrtable(jrtable_id) REFERENCES jrtables(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
id_in_table INTEGER NOT NULL
);

View File

@@ -1 +1,19 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
DROP TABLE jrentries;

View File

@@ -1 +0,0 @@
-- This file should undo anything in `up.sql`

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
CREATE TABLE jrentries (
id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY,
row_pos INTEGER NOT NULL,

View File

@@ -1 +0,0 @@
-- Your SQL goes here

View File

@@ -1 +1,19 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
DROP TABLE jrcells;

View File

@@ -1 +0,0 @@
-- This file should undo anything in `up.sql`

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
CREATE TABLE jrcells (
id INTEGER AUTO_INCREMENT NOT NULL,
PRIMARY KEY(id),

View File

@@ -1 +0,0 @@
-- Your SQL goes here

View File

@@ -1,2 +1,20 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
ALTER TABLE jrtables
ADD num_fields INTEGER NOT NULL;

View File

@@ -1 +0,0 @@
-- This file should undo anything in `up.sql`

View File

@@ -1,2 +1,20 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
ALTER TABLE jrtables
DROP COLUMN num_fields;

View File

@@ -1 +0,0 @@
-- Your SQL goes here

View File

@@ -0,0 +1,24 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
CREATE TABLE users (
id INTEGER AUTO_INCREMENT NOT NULL,
PRIMARY KEY(id),
username VARCHAR(255) NOT NULL,
email VARCHAR(512) NOT NULL
);

View File

@@ -1 +1,19 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
DROP TABLE users;

View File

@@ -1 +0,0 @@
-- This file should undo anything in `up.sql`

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
CREATE TABLE users (
id INTEGER AUTO_INCREMENT NOT NULL,
PRIMARY KEY(id),

View File

@@ -1 +0,0 @@
-- Your SQL goes here

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
SET FOREIGN_KEY_CHECKS=0;
UPDATE TABLE jrtables
DROP COLUMN owner_id

View File

@@ -1 +0,0 @@
-- This file should undo anything in `up.sql`

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE jrtables
ADD owner_id INTEGER NOT NULL;

View File

@@ -1 +0,0 @@
-- Your SQL goes here

View File

@@ -1,2 +1,20 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
ALTER TABLE jrcolumns
DROP COLUMN column_type;

View File

@@ -1 +0,0 @@
-- This file should undo anything in `up.sql`

View File

@@ -1,2 +1,20 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
ALTER TABLE jrcolumns
ADD column_type INTEGER NOT NULL DEFAULT 0;

View File

@@ -1 +0,0 @@
-- Your SQL goes here

View File

@@ -1,28 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let tblid = args()
.nth(1)
.expect("Usage: add_cell <tblid> <rowpos> <idintbl> <value>.")
.parse::<i32>()
.expect("Expected a number.");
let rowpos = args()
.nth(2)
.expect("Usage: add_cell <tblid> <rowpos> <idintbl> <value>.")
.parse::<i32>()
.expect("Expected a number.");
let idintbl = args()
.nth(3)
.expect("Usage: add_cell <tblid> <rowpos> <idintbl> <value>.")
.parse::<i32>()
.expect("Expected a number.");
let value = args()
.nth(4)
.expect("Usage: add_cell <tblid> <clmnid> <value>.");
println!("{:?}", create_jrcell_relative(&mut establish_connection(), tblid, rowpos, idintbl, value));
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,15 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let name = args()
.nth(1)
.expect("Name missing");
let table_id = args()
.nth(2)
.expect("Table_id missing.")
.parse::<i32>()
.expect("Expected a number as table id.");
let conn = &mut establish_connection();
jrcolumns::create_jrcolumn(conn, name, table_id);
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;
use std::io::{stdin, Read};

View File

@@ -1,36 +0,0 @@
use inventur_db::*;
use std::env::args;
use std::io::{stdin, Read};
fn main() {
let tblid = args()
.nth(1)
.expect("Usage: add_entry <tblid> <uid>.")
.parse::<i32>()
.expect("Usage: add_entry <tblid> <uid>.");
let uid = args()
.nth(2)
.expect("Usage: add_entry <tblid> <uid>.")
.parse::<i32>()
.expect("Usage: add_entry <tblid> <uid>.");
let conn = &mut establish_connection();
let tbl = get_table(conn, tblid, uid);
if tbl.is_none() {
panic!("Table not found.");
}
let tbl = tbl.unwrap();
let mut rows = Vec::new();
for clm in tbl.column_names {
println!("{}:", clm);
let mut cell = String::new();
stdin().read_line(&mut cell);
rows.push(cell.clone());
}
println!("{}", add_row(conn, tblid, rows, uid).expect("Error"));
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,28 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let tblid = args()
.nth(1)
.expect("Usage: change_cell_value <tblid> <rowpos> <idintbl> <newvalue>.")
.parse::<i32>()
.expect("Expected a number.");
let rowpos = args()
.nth(2)
.expect("Usage: change_cell_value <tblid> <rowpos> <idintbl> <newvalue>.")
.parse::<i32>()
.expect("Expected a number.");
let idintbl = args()
.nth(3)
.expect("Usage: change_cell_value <tblid> <rowpos> <idintbl> <newvalue>.")
.parse::<i32>()
.expect("Expected a number.");
let newvalue = args()
.nth(4)
.expect("Usage: change_cell_value <tblid> <rowpos> <idintbl> <newvalue>.");
println!("{:?}", jrcells::change_jrcell_value_relative(&mut establish_connection(), tblid, rowpos, idintbl, newvalue));
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::io::stdin;

View File

@@ -1,38 +0,0 @@
use inventur_db::*;
use std::io::stdin;
fn main() {
let conn = &mut establish_connection();
let mut name = String::new();
let mut num_fields = String::new();
let mut uid = String::new();
println!("Name: ");
stdin().read_line(&mut name).unwrap();
let name = name.trim_end();
println!("Number of fields: ");
stdin().read_line(&mut num_fields);
println!("Userid:");
stdin().read_line(&mut uid);
let uid = uid
.trim()
.parse::<i32>()
.expect("Number expected.");
let num_fields = num_fields
.trim()
.parse::<i32>()
.expect("Number expected");
let mut fields = Vec::new();
for i in 0..num_fields {
let mut field = String::new();
stdin().read_line(&mut field);
field.trim();
fields.push(field);
}
println!("{}", create_table(conn, name.to_string(), fields, uid).unwrap());
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,14 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let uname = args()
.nth(1)
.expect("Usage: create_user <username> <email>.");
let mail = args()
.nth(2)
.expect("Usage: create_user <username> <email>.");
println!("{}", register_or_login(&mut establish_connection(), uname, mail).unwrap().uid);
}

View File

@@ -1,24 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let tblid = args()
.nth(1)
.expect("Usage: add_cell <tblid> <rowpos> <idintbl> <value>.")
.parse::<i32>()
.expect("Expected a number.");
let rowpos = args()
.nth(2)
.expect("Usage: add_cell <tblid> <rowpos> <idintbl> <value>.")
.parse::<i32>()
.expect("Expected a number.");
let idintbl = args()
.nth(3)
.expect("Usage: add_cell <tblid> <rowpos> <idintbl> <value>.")
.parse::<i32>()
.expect("Expected a number.");
println!("{:?}", delete_jrcell_relative(&mut establish_connection(), tblid, rowpos, idintbl));
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,20 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let tblid = args()
.nth(1)
.expect("Table id missing.")
.parse::<i32>()
.expect("Expected a number.");
let idintbl = args()
.nth(2)
.expect("Id in table missing.")
.parse::<i32>()
.expect("Expected a number.");
let conn = &mut establish_connection();
println!("{:?}", jrcolumns::delete_column_relative(conn, tblid, idintbl));
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,19 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let tblid = args()
.nth(1)
.expect("Usage: delete_entry <tblid> <rowpos>")
.parse::<i32>()
.expect("Expected a number.");
let rowpos = args()
.nth(2)
.expect("Usage: delete_entry <tblid> <rowpos>")
.parse::<i32>()
.expect("Expected a number.");
jrentries::delete_jrentry_relative(&mut establish_connection(), tblid, rowpos);
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,12 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let tblid = args()
.nth(1)
.expect("Usage: delete_jrtable <tableid>.")
.parse::<i32>()
.expect("Expected a number.");
println!("{:?}", jrtables::delete_jrtable(&mut establish_connection(), tblid));
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,19 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let arg = args()
.nth(1)
.expect("Missing argument.");
let conn = &mut establish_connection();
let mut uid = users::get_uid_uname(conn, &arg);
if uid.is_err() {
uid = users::get_uid_email(conn, &arg);
}
if uid.is_err() {
panic!("User not found!");
}
let uid = uid.unwrap();
delete_user(conn, uid);
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::env::args;
use inventur_db::*;

View File

@@ -1,25 +0,0 @@
use std::env::args;
use inventur_db::*;
fn main() {
let tblid = args()
.nth(1)
.expect("Table id missing.")
.parse::<i32>()
.expect("Expected a number.");
let idintbl = args()
.nth(2)
.expect("Id in table missing.")
.parse::<i32>()
.expect("Expected a number.");
let newidintbl = args()
.nth(3)
.expect("New id in table missing.")
.parse::<i32>()
.expect("Expected a number.");
let conn = &mut establish_connection();
jrcolumns::move_column_relative(conn, tblid, idintbl, newidintbl);
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,25 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let tblid = args()
.nth(1)
.expect("Usage: move_entry <tblid> <rowpos> <newpos>.")
.parse::<i32>()
.expect("Expected a number.");
let rowpos = args()
.nth(2)
.expect("Usage: move_entry <tblid> <rowpos> <newpos>.")
.parse::<i32>()
.expect("Expected a number.");
let newpos = args()
.nth(3)
.expect("Usage: move_entry <tblid> <rowpos> <newpos>.")
.parse::<i32>()
.expect("Expected a number.");
println!("{:?}", jrentries::move_jrentry(&mut establish_connection(), tblid, rowpos, newpos));
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,27 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
if args().len() != 4 {
panic!("Usage: rename_column <table_id> <id_in_table> <new name>.");
}
let table_id = args()
.nth(1)
.unwrap()
.parse::<i32>()
.expect("Table id must be a number.");
let id_in_table = args()
.nth(2)
.unwrap()
.parse::<i32>()
.expect("id in table must be a number.");
let name = args()
.nth(3)
.unwrap();
let conn = &mut establish_connection();
jrcolumns::rename_column_relative(conn, table_id, id_in_table, name);
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,23 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let table_id = args()
.nth(1)
.expect("Usage: rename_jrtable <tblid> <uid> <new name>.")
.parse::<i32>()
.expect("number expected for id.");
let uid = args()
.nth(2)
.expect("Usage: rename_jrtable <tblid> <uid> <new name>.")
.parse::<i32>()
.expect("Usage: rename_jrtable <tblid> <uid> <new name>.");
let new_name = args()
.nth(3)
.expect("Usage: rename_jrtable <tblid> <uid> <new name>.");
let conn = &mut establish_connection();
rename_table(conn, table_id, uid, new_name);
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,29 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let tblid = args()
.nth(1)
.expect("Usage: show_table <tblid>.")
.parse::<i32>()
.expect("Expected a number.");
let tbl = get_table(&mut establish_connection(), tblid, 1);
if tbl.is_none() {
panic!("Couldn't get table.");
}
let tbl = tbl.unwrap();
println!("Table {}: {}", tbl.tblid, tbl.name);
println!();
print!("|");
for clm in tbl.column_names {
print!(" {} |", clm);
}
println!();
for row in tbl.rows {
print!("|");
for cell in row.cells {
print!(" {} |", cell);
}
println!();
}
}

View File

@@ -1,16 +0,0 @@
use inventur_db::*;
fn main() {
let conn = &mut establish_connection();
let results = get_all_tables(conn).expect("Error loading tables.");
println!("Total: {} tables.", results.len());
for table in results {
println!("{}: {} has {} columns.", table.id, table.name, table.num_fields);
let columns = get_columns_of(conn, table.id).expect(format!("Error reading columns for table {}.", table.id).as_str());
for column in columns {
print!("{} ", column.name);
}
}
}

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use inventur_db::*;
use std::env::args;

View File

@@ -1,10 +0,0 @@
use inventur_db::*;
use std::env::args;
fn main() {
let uid = args()
.nth(1)
.parse::<i32>()
.expect("Usage: show_user_tblids <uid>.");
println!("{:?}", get_user_tblids(uid));
}

View File

@@ -1,3 +1,20 @@
/* Simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::schema;
use crate::models;
use crate::jrcolumns;

View File

@@ -1,98 +0,0 @@
use crate::schema;
use crate::models;
use crate::jrcolumns;
use crate::jrentries;
use models::{ Jrcell, NewJrcell };
use schema::jrcells::dsl::{jrcells, id, jrentry_id, jrcolumn_id, cell_value};
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
pub fn create_jrcell_relative(conn: &mut MysqlConnection, tblid: i32, rowpos: i32, idintbl: i32, value: String) -> Result<usize, diesel::result::Error> {
let ntrid = jrentries::get_jrentry_id(conn, tblid, rowpos);
if ntrid.is_err() {
return Err(ntrid.err().unwrap());
}
let ntrid = ntrid.unwrap();
let clmid = jrcolumns::get_clmid_relative(conn, tblid, idintbl);
if clmid.is_err() {
return Err(clmid.err().unwrap());
}
let clmid = clmid.unwrap();
create_jrcell(conn, ntrid, clmid, value)
}
pub fn change_jrcell_value_relative(conn: &mut MysqlConnection, tblid: i32, rowpos: i32, idintbl: i32, new_value: String) -> Result<usize, diesel::result::Error> {
let ntrid = jrentries::get_jrentry_id(conn, tblid, rowpos);
if ntrid.is_err() {
return Err(ntrid.err().unwrap());
}
let ntrid = ntrid.unwrap();
let clmid = jrcolumns::get_clmid_relative(conn, tblid, idintbl);
if clmid.is_err() {
return Err(clmid.err().unwrap());
}
let clmid = clmid.unwrap();
change_jrcell_value(conn, ntrid, clmid, new_value)
}
pub fn delete_jrcell_relative(conn: &mut MysqlConnection, tblid: i32, rowpos: i32, idintbl: i32) -> Result<usize, diesel::result::Error> {
let ntrid = jrentries::get_jrentry_id(conn, tblid, rowpos);
if ntrid.is_err() {
return Err(ntrid.err().unwrap());
}
let ntrid = ntrid.unwrap();
let clmid = jrcolumns::get_clmid_relative(conn, tblid, idintbl);
if clmid.is_err() {
return Err(clmid.err().unwrap());
}
let clmid = clmid.unwrap();
delete_jrcell(conn, ntrid, clmid)
}
pub fn create_jrcell(conn: &mut MysqlConnection, entryid: i32, columnid: i32, value: String) -> Result<usize, diesel::result::Error> {
use self::schema::jrentries::dsl::jrentries;
use self::schema::jrcolumns::dsl::jrcolumns;
let ntr = jrentries
.find(entryid)
.execute(conn);
if ntr.is_err() {
return ntr;
}
let clmn = jrcolumns
.find(columnid)
.execute(conn);
if clmn.is_err() {
return clmn;
}
let cell = NewJrcell { cell_value: value, jrentry_id: entryid, jrcolumn_id: columnid };
diesel::insert_into(crate::schema::jrcells::table)
.values(cell)
.execute(conn)
}
pub fn change_jrcell_value(conn: &mut MysqlConnection, entryid: i32, columnid: i32, new_value: String) -> Result<usize, diesel::result::Error> {
diesel::update(jrcells.filter(jrentry_id.eq(entryid)).filter(jrcolumn_id.eq(columnid)))
.set(cell_value.eq(new_value))
.execute(conn)
}
pub fn delete_jrcell(conn: &mut MysqlConnection, entryid: i32, columnid: i32) -> Result<usize, diesel::result::Error> {
diesel::delete(jrcells.filter(jrentry_id.eq(entryid)).filter(jrcolumn_id.eq(columnid)))
.execute(conn)
}
pub fn get_entry_cells(conn: &mut MysqlConnection, entryid: i32) -> Result<Vec<Jrcell>, diesel::result::Error> {
jrcells
.filter(jrentry_id.eq(entryid))
.select(Jrcell::as_select())
.load(conn)
}

View File

@@ -1,3 +1,20 @@
/* Simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
use crate::models;

View File

@@ -1,197 +0,0 @@
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
use crate::models;
use crate::schema;
use crate::jrtables;
use models::{ Jrcolumn, NewJrcolumn };
use schema::jrcolumns::dsl::{ jrcolumns, id, name, jrtable_id, id_in_table };
pub fn create_jrcolumn(conn: &mut MysqlConnection, tblid: i32, clmnname: String) -> Result<usize, diesel::result::Error> {
let ncols = jrtables::get_ncols(conn, tblid);
if ncols.is_err() {
return ncols;
}
let ncols = ncols.unwrap() as i32;
let jrcolumn = NewJrcolumn { name: clmnname, jrtable_id: tblid, id_in_table: ncols + 1 };
diesel::insert_into(crate::schema::jrcolumns::table)
.values(&jrcolumn)
.execute(conn)
}
pub fn create_jrcolumns(conn: &mut MysqlConnection, tblid: i32, names: Vec<String>) -> Result<usize, diesel::result::Error> {
let mut cols : Vec<NewJrcolumn> = Vec::new();
let ncols = jrtables::get_ncols(conn, tblid);
if ncols.is_err() {
return ncols;
}
let mut ncols = ncols.unwrap() as i32;
for clmnname in names {
ncols += 1;
cols.push(NewJrcolumn { name: clmnname, jrtable_id: tblid, id_in_table: ncols});
}
let cols = cols;
diesel::insert_into(crate::schema::jrcolumns::table)
.values(&cols)
.execute(conn)
}
pub fn get_last_column_id_of(conn: &mut MysqlConnection, tblid: i32) -> Result<i32, diesel::result::Error> {
jrcolumns
.filter(jrtable_id.eq(tblid))
.order(id_in_table.desc())
.select(id)
.first::<i32>(conn)
}
pub fn get_columns_of(conn: &mut MysqlConnection, tblid: i32) -> Result<Vec<Jrcolumn>, diesel::result::Error> {
jrcolumns
.filter(jrtable_id.eq(tblid))
.order(id_in_table.asc())
.select(Jrcolumn::as_select())
.load(conn)
}
pub fn get_clmid_relative(conn: &mut MysqlConnection, tblid: i32, idintbl: i32) -> Result<i32, diesel::result::Error> {
jrcolumns
.filter(jrtable_id.eq(tblid))
.filter(id_in_table.eq(idintbl))
.select(id)
.first::<i32>(conn)
}
pub fn rename_column_relative(conn: &mut MysqlConnection, tblid: i32, id_in_tbl: i32, new_name: String) -> Result<usize, diesel::result::Error> {
let clmid = get_clmid_relative(conn, tblid, id_in_tbl);
if clmid.is_err() {
return Err(clmid.err().unwrap());
}
rename_column(conn, clmid.unwrap(), new_name)
}
pub fn rename_column(conn: &mut MysqlConnection, clmnid: i32, new_name: String) -> Result<usize, diesel::result::Error> {
diesel::update(jrcolumns.find(clmnid))
.set(name.eq(new_name))
.execute(conn)
}
pub fn move_column_relative(conn: &mut MysqlConnection, tblid: i32, id_in_tbl: i32, new_id_in_tbl: i32) -> Result<usize, diesel::result::Error> {
let clmid = get_clmid_relative(conn, tblid, id_in_tbl);
if clmid.is_err() {
return Err(clmid.err().unwrap());
}
move_column(conn, clmid.unwrap(), new_id_in_tbl)
}
pub fn move_column(conn: &mut MysqlConnection, clmnid: i32, new_id_in_table: i32) -> Result<usize, diesel::result::Error>{
let tbl_id = jrcolumns
.find(clmnid)
.select(jrtable_id)
.first::<i32>(conn);
if tbl_id.is_err() {
return Err(tbl_id.err().unwrap());
}
let tbl_id = tbl_id.unwrap();
let cols = jrcolumns
.filter(jrtable_id.eq(tbl_id))
.order(id_in_table.asc())
.select(Jrcolumn::as_select())
.load(conn);
if cols.is_err() {
return Err(cols.err().unwrap());
}
let cols = cols.unwrap();
let ncols = cols.len() as i32;
if new_id_in_table > ncols || new_id_in_table < 0 {
return Err(diesel::result::Error::NotFound);
}
let cur_id_in_table =
jrcolumns
.find(clmnid)
.select(id_in_table)
.first::<i32>(conn);
if cur_id_in_table.is_err() {
return Err(cur_id_in_table.err().unwrap());
}
let cur_id_in_table = cur_id_in_table.unwrap();
let dir;
let a;
let b;
if cur_id_in_table < new_id_in_table {
dir = -1;
a = cur_id_in_table + 1;
b = new_id_in_table;
} else {
dir = 1;
a = new_id_in_table;
b = cur_id_in_table - 1;
}
for j in a..=b {
let upd = diesel::update(jrcolumns.find(cols[(j-1) as usize].id))
.set(id_in_table.eq(id_in_table + dir))
.execute(conn);
if upd.is_err() {
return upd;
}
}
diesel::update(jrcolumns.find(clmnid))
.set(id_in_table.eq(new_id_in_table))
.execute(conn)
}
pub fn delete_column_relative(conn: &mut MysqlConnection, tblid: i32, idinclm: i32) -> Result<usize, diesel::result::Error> {
let clmid = get_clmid_relative(conn, tblid, idinclm);
if clmid.is_err() {
return Err(clmid.err().unwrap());
}
delete_column(conn, clmid.unwrap())
}
pub fn delete_column(conn: &mut MysqlConnection, clmnid: i32) -> Result<usize, diesel::result::Error> {
let tblid = jrcolumns
.find(clmnid)
.select(jrtable_id)
.first::<i32>(conn);
if tblid.is_err() {
return Err(tblid.err().unwrap());
}
let tblid = tblid.unwrap();
let ncols = jrcolumns
.filter(jrtable_id.eq(tblid))
.execute(conn);
if ncols.is_err() {
return ncols;
}
let ncols = ncols.unwrap() as i32;
let mv = move_column(conn, clmnid, ncols);
if mv.is_err() {
return mv;
}
diesel::delete(jrcolumns.find(clmnid))
.execute(conn)
}
pub fn get_clmns_of(conn: &mut MysqlConnection, tblid: i32) -> Result<Vec<Jrcolumn>, diesel::result::Error> {
jrcolumns
.filter(jrtable_id.eq(tblid))
.order(id_in_table.asc())
.select(Jrcolumn::as_select())
.load(conn)
}

View File

@@ -1,3 +1,20 @@
/* Simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::models;
use crate::schema;

View File

@@ -1,131 +0,0 @@
use crate::models;
use crate::schema;
use schema::jrentries::dsl::{jrentries, id, jrtable_id, row_pos};
use models::{ Jrentry, NewJrentry };
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
pub fn create_jrentry(conn: &mut MysqlConnection, tblid: i32) -> Result<usize, diesel::result::Error> {
let rowpos = jrentries
.filter(jrtable_id.eq(tblid))
.select(row_pos)
.load::<i32>(conn);
if rowpos.is_err() {
return Err(rowpos.err().unwrap());
}
let rowpos = rowpos.unwrap().len() + 1;
let ntr = NewJrentry { jrtable_id: tblid, row_pos: rowpos as i32 };
diesel::insert_into(crate::schema::jrentries::table)
.values(ntr)
.execute(conn)
}
pub fn move_jrentry(conn: &mut MysqlConnection, tblid: i32, rowpos: i32, newrowpos: i32) -> Result<usize, diesel::result::Error> {
let ntrids = jrentries
.filter(jrtable_id.eq(tblid))
.order(row_pos.asc())
.select(id)
.load::<i32>(conn);
if ntrids.is_err() {
return Err(ntrids.err().unwrap());
}
let ntrids = ntrids.unwrap();
let a;
let b;
let dir;
let entryid = ntrids[(rowpos-1) as usize];
if rowpos < newrowpos {
a = rowpos + 1;
b = newrowpos;
dir = -1;
}else {
a = newrowpos;
b = rowpos - 1;
dir = 1;
}
for i in a..=b {
let upd = diesel::update(jrentries.find(ntrids[(i-1) as usize]))
.set(row_pos.eq(row_pos + dir))
.execute(conn);
if upd.is_err() {
return upd;
}
}
diesel::update(jrentries.find(entryid))
.set(row_pos.eq(newrowpos))
.execute(conn)
}
pub fn delete_jrentry_relative(conn: &mut MysqlConnection, tblid: i32, rowpos: i32) -> Result<usize, diesel::result::Error> {
let entryid = jrentries
.filter(jrtable_id.eq(tblid))
.filter(row_pos.eq(rowpos))
.select(id)
.first::<i32>(conn);
if entryid.is_err() {
return Err(entryid.err().unwrap());
}
delete_jrentry(conn, entryid.unwrap())
}
pub fn delete_jrentry(conn: &mut MysqlConnection, entryid: i32) -> Result<usize, diesel::result::Error> {
let rp = jrentries
.find(entryid)
.select(row_pos)
.first::<i32>(conn);
let tblid = jrentries
.find(entryid)
.select(jrtable_id)
.first::<i32>(conn);
if rp.is_err() {
return Err(tblid.err().unwrap());
}
if tblid.is_err() {
return Err(tblid.err().unwrap());
}
let rp = rp.unwrap();
let tblid = tblid.unwrap();
let nr = jrentries
.filter(jrtable_id.eq(tblid))
.execute(conn);
if nr.is_err() {
return nr;
}
move_jrentry(conn, tblid, rp, nr.unwrap() as i32);
diesel::delete(jrentries.find(entryid)).execute(conn)
}
pub fn get_jrentry_id(conn: &mut MysqlConnection, tblid: i32, rowpos: i32) -> Result<i32, diesel::result::Error> {
jrentries
.filter(jrtable_id.eq(tblid))
.filter(row_pos.eq(rowpos))
.select(id)
.first::<i32>(conn)
}
pub fn get_entries_of(conn: &mut MysqlConnection, tblid: i32) -> Result<Vec<Jrentry>, diesel::result::Error> {
jrentries
.filter(jrtable_id.eq(tblid))
.select(Jrentry::as_select())
.load(conn)
}

View File

@@ -1,3 +1,20 @@
/* Simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
use crate::models;

View File

@@ -1,95 +0,0 @@
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
use crate::models;
use crate::schema;
use crate::jrcolumns;
use models::{ Jrtable, NewJrtable };
use schema::jrtables::dsl::{ jrtables, id, name, owner_id };
pub fn create_jrtable(conn: &mut MysqlConnection, tblname: &String, field_names: Vec<String>, uid: i32) -> Result<i32, diesel::result::Error> {
let jrtable = NewJrtable { name: tblname.to_string(), owner_id: uid };
let tbl = diesel::insert_into(crate::schema::jrtables::table)
.values(&jrtable)
.execute(conn);
if tbl.is_err() {
return Err(tbl.err().unwrap());
}
let tblid = jrtables
.order(id.desc())
.select(id)
.first::<i32>(conn);
if tblid.is_err() {
return Err(tblid.err().unwrap());
}
let tblid = tblid.unwrap();
let cols = jrcolumns::create_jrcolumns_empty_tbl(conn, tblid, field_names);
if cols.is_err() {
return Err(cols.err().unwrap());
}
Ok(tblid)
}
pub fn rename_jrtable(conn: &mut MysqlConnection, tblid: i32, new_name: &str) -> Result<usize, diesel::result::Error> {
diesel::update(jrtables.find(tblid))
.set(name.eq(new_name))
.execute(conn)
}
pub fn delete_jrtable(conn: &mut MysqlConnection, tblid: i32) -> Result<usize, diesel::result::Error> {
diesel::delete(jrtables.find(tblid))
.execute(conn)
}
pub fn get_all_tables(conn: &mut MysqlConnection) -> Result<Vec<Jrtable>, diesel::result::Error> {
jrtables
.select(Jrtable::as_select())
.load(conn)
}
pub fn get_tbl(conn: &mut MysqlConnection, tblid: i32) -> Result<Jrtable, diesel::result::Error> {
jrtables
.find(tblid)
.select(Jrtable::as_select())
.first(conn)
}
pub fn get_ncols(conn: &mut MysqlConnection, tblid: i32) -> Result<usize, diesel::result::Error> {
use schema::jrcolumns::dsl::{ jrcolumns, jrtable_id };
jrcolumns
.filter(jrtable_id.eq(tblid))
.execute(conn)
}
pub fn get_nrows(conn: &mut MysqlConnection, tblid: i32) -> Result<usize, diesel::result::Error> {
use schema::jrentries::dsl::{jrentries, jrtable_id};
jrentries
.filter(jrtable_id.eq(tblid))
.execute(conn)
}
pub fn get_tblids_uid(conn: &mut MysqlConnection, uid: i32) -> Result<Vec<i32>, diesel::result::Error> {
jrtables
.filter(owner_id.eq(uid))
.select(id)
.load::<i32>(conn)
}
pub fn get_owner_id(conn: &mut MysqlConnection, tblid: i32) -> Result<i32, diesel::result::Error> {
jrtables
.find(tblid)
.select(owner_id)
.first::<i32>(conn)
}
pub fn get_tbl_by_name_uid(conn: &mut MysqlConnection, tblname: &String, uid: i32) -> Result<i32, diesel::result::Error> {
jrtables
.filter(owner_id.eq(uid))
.filter(name.eq(tblname))
.select(id)
.first::<i32>(conn)
}

View File

@@ -1,4 +1,20 @@
#![recursion_limit = "512"]
/* Simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//! Database API using the table style system provided by this crate
mod models;
mod schema;

View File

@@ -1,314 +0,0 @@
//! Database API using the table style system provided by this crate
mod models;
mod schema;
mod jrtables;
mod jrcolumns;
mod jrentries;
mod jrcells;
mod users;
use dotenvy::dotenv;
use std::env;
use diesel::mysql::MysqlConnection;
use diesel::prelude::*;
/// represents and summarised all relevant data of a table.
/// Standard return type if whole tables should be returned
pub struct Tbl {
/// table id of the represented object
pub tblid: i32,
pub name: String,
pub column_names: Vec<String>,
pub rows: Vec<TRow>,
}
/// Represents a table's row.
/// Internal data structure is abstracted until strings.
pub struct TRow {
pub row_pos: i32,
pub cells: Vec<String>,
}
/// Identifies a user
/// All fields are unique within the db at any given point.
pub struct User {
/// User's unique id.
pub uid: i32,
pub uname: String,
pub email: String,
}
/// Connect to database.
/// Return value must be passed to most of the crate's functions.
pub fn establish_connection() -> MysqlConnection {
dotenv().ok();
let db_url = env::var("DATABASE_URL").expect("No database url set.");
MysqlConnection::establish(&db_url)
.unwrap_or_else(|_| panic!("Couldn't open database."))
}
/// Fetch one whole table from the database. Identified by it's ID.
/// Needs the id of the requesting user.
/// Returns:
/// A Tbl struct
/// Or:
/// None
/// if the table was not found or
/// if it could not be read or
/// if the requesting user is not the table's owner or
/// if there has been another error
///
pub fn get_table(conn: &mut MysqlConnection, tblid: i32, uid: i32) -> Option<Tbl> {
let tbl = jrtables::get_tbl(conn, tblid);
if tbl.is_err() {
return None;
}
let tbl = tbl.unwrap();
if tbl.owner_id != uid {
return None;
}
let clmns = jrcolumns::get_clmns_of(conn, tblid);
if clmns.is_err() {
return None;
}
let clmns = clmns.unwrap();
let mut clmn_nms = Vec::new();
for clmn in &clmns {
clmn_nms.push(clmn.name.clone());
}
let clmn_nms = clmn_nms;
let mut clmn_ids = Vec::new();
for clmn in clmns {
clmn_ids.push(clmn.id);
}
let clmn_ids = clmn_ids;
let rowids = jrentries::get_entries_of(conn, tblid);
if rowids.is_err() {
return None;
}
let rowids = rowids.unwrap();
let mut rows = Vec::new();
for rowid in rowids {
let row = jrcells::get_entry_cells(conn, rowid.id);
if row.is_err() {
return None;
}
let row = row.unwrap();
let mut data = Vec::new();
for cell in row {
data.push(cell.cell_value);
}
let data = data;
rows.push(TRow { row_pos: rowid.row_pos, cells: data });
}
Some(Tbl { tblid: tbl.id, name: tbl.name, column_names: clmn_nms, rows: rows })
}
pub fn get_tblnames(conn: &mut MysqlConnection, tblids: Vec<i32>) -> Option<Vec<String>> {
let mut tblnames = Vec::new();
for tblid in tblids {
let tblname = jrtables::get_tbl(conn, tblid);
if tblname.is_err() {
return None;
}
tblnames.push(tblname.unwrap().name);
}
Some(tblnames)
}
/// Returns a Vec of the ids of a user's table if the user exists, else None.
/// User is identified by its user ID.
pub fn get_user_tblids(conn: &mut MysqlConnection, uid: i32) -> Option<Vec<i32>> {
let tblids = jrtables::get_tblids_uid(conn, uid);
if tblids.is_err() {
return None;
}
Some(tblids.unwrap())
}
/// Change the name of a table.
/// Needs the user ID of the requesting user.
/// Returns Some(true) if the action seems to have been successful and the requesting user is the
/// table's owner.
/// None otherwise.
pub fn rename_table(conn: &mut MysqlConnection, tblid: i32, new_name: String, uid: i32) -> Option<bool> {
let owner = jrtables::get_owner_id(conn, tblid);
if owner.is_err() || owner.unwrap() != uid {
return None;
}
let rnm = jrtables::rename_jrtable(conn, tblid, &new_name);
if rnm.is_err() {
return None;
}
Some(true)
}
/// Delete a table.
/// Needs the user ID of the requesting user.
/// Returns Some(true) if the action seems to have been successful and the requesting user is the
/// table's owner.
/// None otherwise.
pub fn delete_table(conn: &mut MysqlConnection, tblid: i32, uid: i32) -> Option<bool> {
let owner = jrtables::get_owner_id(conn, tblid);
if owner.is_err() || owner.unwrap() != uid {
return None;
}
let dlt = jrtables::delete_jrtable(conn, tblid);
if dlt.is_err() {
return None;
}
Some(true)
}
/// Create a new table.
/// Needs the user ID of the requesting user.
/// Returns the id of the newly created table if the action seems to have been successful and the requesting user is the
/// table's owner.
/// None otherwise.
pub fn create_table(conn: &mut MysqlConnection, name: String, field_names: Vec<String>, uid: i32) -> Option<i32> {
if jrtables::get_tbl_by_name_uid(conn, &name, uid).is_ok() {
return None;
}
if jrtables::create_jrtable(conn, &name, field_names, uid).is_err() {
return None;
}
let tblid = jrtables::get_tbl_by_name_uid(conn, &name, uid);
if tblid.is_err() {
return None;
}
Some(tblid.unwrap())
}
/// Returns a User struct of a requested user if the combination of username and email are
/// consistent or both do not exist yet, in which case the user is newly created.
pub fn register_or_login(conn: &mut MysqlConnection, uname: String, mail: String) -> Option<User> {
let mut uid = users::get_uid_email(conn, &mail);
if uid.is_err() {
if users::get_uid_uname(conn, &uname).is_ok() || users::create_user(conn, &uname, &mail).is_err() {
return None;
}
uid = users::get_uid_email(conn, &mail);
if uid.is_err() {
return None;
}
}
let uid = uid.unwrap();
let nm = users::get_uname(conn, uid);
if nm.is_err() || nm.unwrap() != uname {
return None;
}
Some(User { uid: uid, uname: uname, email: mail })
}
pub fn delete_user(conn: &mut MysqlConnection, uid: i32) -> Option<bool> {
if users::delete_user(conn, uid).is_err() {
return None;
}
Some(true)
}
pub fn add_row(conn: &mut MysqlConnection, tblid: i32, values: Vec<String>, uid: i32) -> Option<i32> {
let owner = jrtables::get_owner_id(conn, tblid);
let nrows = jrtables::get_nrows(conn, tblid);
if nrows.is_err() || owner.is_err() || owner.unwrap() != uid {
return None;
}
let nrows = nrows.unwrap() as i32;
if jrentries::create_jrentry(conn, tblid).is_err() {
return None;
}
let entryid = jrentries::get_jrentry_id(conn, tblid, nrows+1);
if entryid.is_err() {
return None;
}
let entryid = entryid.unwrap();
let cols = jrcolumns::get_clmns_of(conn, tblid);
if cols.is_err() {
return None;
}
let cols = cols.unwrap();
for (i,col) in cols.iter().enumerate() {
if jrcells::create_jrcell(conn, entryid, col.id, &values[i]).is_err() {
return None;
}
}
Some(entryid)
}
pub fn delete_row(conn: &mut MysqlConnection, tblid: i32, row_pos: i32, uid: i32) -> Option<bool> {
let owner = jrtables::get_owner_id(conn, tblid);
if owner.is_err() || owner.unwrap() != uid || jrentries::delete_jrentry_relative(conn, tblid, row_pos).is_err() {
return None;
}
Some(true)
}
pub fn move_row(conn: &mut MysqlConnection, tblid: i32, rowpos: i32, newpos: i32, uid: i32) -> Option<bool> {
let owner = jrtables::get_owner_id(conn, tblid);
if owner.is_err() || owner.unwrap() != uid || jrentries::move_jrentry(conn, tblid, rowpos, newpos).is_err() {
return None;
}
Some(true)
}
pub fn edit_cell(conn: &mut MysqlConnection, tblid: i32, row_pos: i32, column_pos: i32, new_value: String, uid: i32) -> Option<bool> {
let owner = jrtables::get_owner_id(conn, tblid);
if owner.is_err() ||
owner.unwrap() != uid ||
jrcells::change_jrcell_value_relative(conn, tblid, row_pos, column_pos, new_value).is_err()
{
return None;
}
Some(true)
}
pub fn move_column(conn: &mut MysqlConnection, tblid:i32, column_pos: i32, new_column_pos: i32, uid: i32) -> Option<bool> {
let owner = jrtables::get_owner_id(conn, tblid);
if owner.is_err() ||
owner.unwrap() != uid ||
jrcolumns::move_column_relative(conn, tblid, column_pos, new_column_pos).is_err()
{
return None;
}
Some(true)
}
pub fn add_column(conn: &mut MysqlConnection, tblid: i32, name: String, uid: i32) -> Option<i32> {
let owner = jrtables::get_owner_id(conn, tblid);
if owner.is_err() ||
owner.unwrap() != uid ||
jrcolumns::create_jrcolumn(conn, tblid, name).is_err()
{
return None;
}
let clmid = jrcolumns::get_last_column_id_of(conn, tblid);
if clmid.is_err() {
return None;
}
Some(clmid.unwrap())
}
pub fn delete_column(conn: &mut MysqlConnection, tblid: i32, column_pos: i32, uid: i32) -> Option<bool> {
let owner = jrtables::get_owner_id(conn, tblid);
if owner.is_err() ||
owner.unwrap() != uid ||
jrcolumns::delete_column_relative(conn, tblid, column_pos).is_err()
{
return None;
}
Some(true)
}
pub fn rename_column(conn: &mut MysqlConnection, tblid: i32, column_pos: i32, new_name: String, uid: i32) -> Option<bool> {
let owner = jrtables::get_owner_id(conn, tblid);
if owner.is_err() ||
owner.unwrap() != uid ||
jrcolumns::rename_column_relative(conn, tblid, column_pos, new_name).is_err()
{
return None;
}
Some(true)
}

View File

@@ -1,3 +1,20 @@
/* Simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use diesel::prelude::*;
use crate::schema::{jrtables, jrcolumns, jrentries, jrcells, users};

View File

@@ -1,97 +0,0 @@
use diesel::prelude::*;
use crate::schema::{jrtables, jrcolumns, jrentries, jrcells, users};
#[derive(Queryable, Selectable, Identifiable, Associations)]
#[diesel(table_name = crate::schema::jrtables)]
#[diesel(belongs_to(User, foreign_key = owner_id))]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Jrtable {
pub id: i32,
pub name: String,
pub owner_id: i32,
}
#[derive(Insertable)]
#[diesel(table_name = jrtables)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct NewJrtable {
pub name: String,
pub owner_id: i32,
}
#[derive(Queryable, Selectable, Identifiable, Associations)]
#[diesel(table_name = jrcolumns)]
#[diesel(belongs_to(Jrtable))]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Jrcolumn {
pub id: i32,
pub name: String,
pub jrtable_id: i32,
pub id_in_table: i32,
}
#[derive(Insertable)]
#[diesel(table_name = jrcolumns)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct NewJrcolumn {
pub name: String,
pub jrtable_id: i32,
pub id_in_table: i32,
}
#[derive(Queryable, Selectable, Identifiable, Associations)]
#[diesel(table_name = jrentries)]
#[diesel(belongs_to(Jrtable))]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Jrentry {
pub id: i32,
pub row_pos: i32,
pub jrtable_id: i32,
}
#[derive(Insertable)]
#[diesel(table_name = jrentries)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct NewJrentry {
pub row_pos: i32,
pub jrtable_id: i32,
}
#[derive(Queryable, Selectable, Identifiable, Associations)]
#[diesel(table_name = jrcells)]
#[diesel(belongs_to(Jrentry))]
#[diesel(belongs_to(Jrcolumn))]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct Jrcell {
pub id: i32,
pub cell_value: String,
pub jrentry_id: i32,
pub jrcolumn_id: i32,
}
#[derive(Insertable)]
#[diesel(table_name = jrcells)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct NewJrcell {
pub cell_value: String,
pub jrentry_id: i32,
pub jrcolumn_id: i32,
}
#[derive(Queryable, Selectable, Identifiable)]
#[diesel(table_name = users)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct User {
pub id: i32,
pub username: String,
pub email: String,
}
#[derive(Insertable)]
#[diesel(table_name = users)]
#[diesel(check_for_backend(diesel::mysql::Mysql))]
pub struct NewUser {
pub username: String,
pub email: String,
}

View File

@@ -1,3 +1,20 @@
/* Simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// @generated automatically by Diesel CLI.
diesel::table! {

View File

@@ -1,3 +1,21 @@
/* This file is part of inventur.
* inventur is a simple web app using rocket to help maintain inventory data.
* Copyright (C) 2024 Johannes Randerath
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use crate::models;
use crate::schema;

View File

@@ -1,56 +0,0 @@
use crate::models;
use crate::schema;
use schema::users::dsl::{users, id, username, email};
use models::NewUser;
use diesel::prelude::*;
use diesel::mysql::MysqlConnection;
pub fn create_user(conn: &mut MysqlConnection, uname: String, mail: String) -> Result<usize, diesel::result::Error> {
let user = NewUser { username: uname, email: mail};
diesel::insert_into(crate::schema::users::table)
.values(&user)
.execute(conn)
}
pub fn delete_user(conn: &mut MysqlConnection, uid: i32) -> Result<usize, diesel::result::Error> {
diesel::delete(users.find(uid))
.execute(conn)
}
pub fn get_uid_email(conn: &mut MysqlConnection, mail: String) -> Result<i32, diesel::result::Error> {
users
.filter(email.eq(mail))
.select(id)
.first::<i32>(conn)
}
pub fn get_uid_uname(conn: &mut MysqlConnection, uname: String) -> Result<i32, diesel::result::Error> {
users
.filter(username.eq(uname))
.select(id)
.first::<i32>(conn)
}
pub fn get_uname(conn: &mut MysqlConnection, uid: i32) -> Result<String, diesel::result::Error> {
users
.find(uid)
.select(username)
.first::<String>(conn)
}
pub fn get_email(conn: &mut MysqlConnection, uid: i32) -> Result<String, diesel::result::Error> {
users
.find(uid)
.select(email)
.first::<String>(conn)
}
pub fn get_user_tables(conn: &mut MysqlConnection, uid: i32) -> Result<Vec<i32>, diesel::result::Error> {
use schema::jrtables::dsl::{jrtables, id as tblid, owner_id};
jrtables
.filter(owner_id.eq(uid))
.select(tblid)
.load::<i32>(conn)
}