mirror of
https://github.com/creating2morrow/neveko.git
synced 2024-10-30 00:27:36 +00:00
check for empty keys in db.rs
This commit is contained in:
parent
88b616bd01
commit
34465f7b97
1 changed files with 15 additions and 0 deletions
|
@ -51,6 +51,11 @@ impl Interface {
|
||||||
///
|
///
|
||||||
/// writing multiple key value pairs.
|
/// writing multiple key value pairs.
|
||||||
pub fn write(e: &Environment, h: &DbHandle, k: &str, v: &str) {
|
pub fn write(e: &Environment, h: &DbHandle, k: &str, v: &str) {
|
||||||
|
// don't try and write empty keys
|
||||||
|
if k.is_empty() {
|
||||||
|
error!("can't write empty key");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let txn = e.new_transaction().unwrap();
|
let txn = e.new_transaction().unwrap();
|
||||||
{
|
{
|
||||||
// get a database bound to this transaction
|
// get a database bound to this transaction
|
||||||
|
@ -75,6 +80,11 @@ impl Interface {
|
||||||
///
|
///
|
||||||
/// returned. NEVEKO does not currently support duplicate keys.
|
/// returned. NEVEKO does not currently support duplicate keys.
|
||||||
pub fn read(e: &Environment, h: &DbHandle, k: &str) -> String {
|
pub fn read(e: &Environment, h: &DbHandle, k: &str) -> String {
|
||||||
|
// don't try and read empty keys
|
||||||
|
if k.is_empty() {
|
||||||
|
error!("can't read empty key");
|
||||||
|
return utils::empty_string();
|
||||||
|
}
|
||||||
let reader = e.get_reader().unwrap();
|
let reader = e.get_reader().unwrap();
|
||||||
let db = reader.bind(&h);
|
let db = reader.bind(&h);
|
||||||
let value = db.get::<&str>(&k).unwrap_or_else(|_| "");
|
let value = db.get::<&str>(&k).unwrap_or_else(|_| "");
|
||||||
|
@ -96,6 +106,11 @@ impl Interface {
|
||||||
///
|
///
|
||||||
/// error will be logged.
|
/// error will be logged.
|
||||||
pub fn delete(e: &Environment, h: &DbHandle, k: &str) {
|
pub fn delete(e: &Environment, h: &DbHandle, k: &str) {
|
||||||
|
// don't try and delete empty keys
|
||||||
|
if k.is_empty() {
|
||||||
|
error!("can't delete empty key");
|
||||||
|
return;
|
||||||
|
}
|
||||||
let txn = e.new_transaction().unwrap();
|
let txn = e.new_transaction().unwrap();
|
||||||
{
|
{
|
||||||
// get a database bound to this transaction
|
// get a database bound to this transaction
|
||||||
|
|
Loading…
Reference in a new issue