Added documentation and refactored
This commit is contained in:
@@ -21,26 +21,12 @@ use crate::jrcolumns;
|
||||
use crate::jrentries;
|
||||
|
||||
use models::{ Jrcell, NewJrcell };
|
||||
use schema::jrcells::dsl::{jrcells, id, jrentry_id, jrcolumn_id, cell_value};
|
||||
use schema::jrcells::dsl::*;
|
||||
|
||||
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() {
|
||||
@@ -55,20 +41,6 @@ pub fn change_jrcell_value_relative(conn: &mut MysqlConnection, tblid: i32, rowp
|
||||
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;
|
||||
@@ -101,12 +73,6 @@ pub fn change_jrcell_value(conn: &mut MysqlConnection, entryid: i32, columnid: i
|
||||
.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))
|
||||
@@ -114,9 +80,3 @@ pub fn get_entry_cells(conn: &mut MysqlConnection, entryid: i32) -> Result<Vec<J
|
||||
.load(conn)
|
||||
}
|
||||
|
||||
pub fn get_entry_cell_ids(conn: &mut MysqlConnection, entryid: i32) -> Result<Vec<i32>, diesel::result::Error> {
|
||||
jrcells
|
||||
.filter(jrentry_id.eq(entryid))
|
||||
.select(id)
|
||||
.load(conn)
|
||||
}
|
||||
|
||||
@@ -124,7 +124,10 @@ pub fn delete_jrentry(conn: &mut MysqlConnection, entryid: i32) -> Result<usize,
|
||||
if nr.is_err() {
|
||||
return nr;
|
||||
}
|
||||
move_jrentry(conn, tblid, rp, nr.unwrap() as i32);
|
||||
let mr = move_jrentry(conn, tblid, rp, nr.unwrap() as i32);
|
||||
if mr.is_err() {
|
||||
return mr;
|
||||
}
|
||||
diesel::delete(jrentries.find(entryid)).execute(conn)
|
||||
|
||||
}
|
||||
|
||||
@@ -60,12 +60,6 @@ pub fn delete_jrtable(conn: &mut MysqlConnection, tblid: i32) -> Result<usize, d
|
||||
.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)
|
||||
|
||||
@@ -68,7 +68,7 @@ impl From<isize> for FIELDTYPE {
|
||||
fn from(value: isize) -> Self {
|
||||
match value {
|
||||
1 => FIELDTYPE::NUMBER,
|
||||
x => FIELDTYPE::TEXT,
|
||||
_ => FIELDTYPE::TEXT,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,11 +148,6 @@ pub fn get_table(conn: &mut MysqlConnection, tblid: i32, uid: i32) -> Option<Tbl
|
||||
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 mut clmn_tps = Vec::new();
|
||||
for clmn in &clmns {
|
||||
clmn_tps.push(clmn.column_type);
|
||||
@@ -210,7 +205,7 @@ pub fn sort_table(tbl: Tbl, sort_field: usize, sort_dir: u8) -> Tbl {
|
||||
/// search_value is a string to search for in the search_fields.
|
||||
/// Returned Tbl is not sorted and should be according to user preferences before being displayed.
|
||||
pub fn search_table(tbl: Tbl, search_fields: Vec<i32>, search_value: String) -> Tbl {
|
||||
let mut rows = tbl.rows;
|
||||
let rows = tbl.rows;
|
||||
let mut field_sets = HashSet::new();
|
||||
for field in search_fields {
|
||||
for row in &rows {
|
||||
|
||||
@@ -58,17 +58,4 @@ pub fn get_uname(conn: &mut MysqlConnection, uid: i32) -> Result<String, diesel:
|
||||
.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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user