mirror of
https://github.com/eliasrenman/r-database.git
synced 2026-03-16 20:46:08 +01:00
feat: added failsafe for pk overwriting
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
use super::{index::Index, row::Row};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use std::collections::{hash_map::Entry, HashMap};
|
||||
use std::{
|
||||
borrow::Borrow,
|
||||
collections::{hash_map::Entry, HashMap},
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Table {
|
||||
@@ -41,6 +44,10 @@ impl Table {
|
||||
return Err("Primary key is not of type u64".to_string());
|
||||
}
|
||||
|
||||
if self.rows.contains_key(row_primary_key.unwrap().borrow()) {
|
||||
return Err("Primary key already exists".to_string());
|
||||
}
|
||||
|
||||
// Insert row into database
|
||||
self.rows.insert(row_primary_key.unwrap(), row.clone());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user