Database for Dummies. A simple, easy-to-use, and lightweight database for small projects. It is so simple a child could use it.
The API is very simple, it has only 5 commands, and it's very easy to use.
The following commands are available:
SET
, GET
, DELETE
, CONTAINS
, CLEAR
.
All commands are case-insensitive.
Comments are also supported, they start with two dashes and end with a newline.
The Database has 4 data types: unsigned integer, string, boolean, and NULL
.
NULL
is a special data type that represents the absence of a value.
It can only be returned by the GET
command when the key does not exist.
Setting a key to NULL
is equivalent to deleting the key.
You are able to chain commands together, multiple commands can be written in a single line, separated by a semicolon. As an example, SET 0 "Hello"; GET 0
will set the key 0
to the value "Hello"
and then get the value of the key 0
.
Values are ONLY strings.
Keys are ONLY unsigned integers.
TRUE
and FALSE
are booleans,
and only returned by the CONTAINS
command.
NULL
is a special data type that represents the absence of a value,
and only returned by the GET
command when the key does not exist.
-- This is a comment!
SET key value
GET key
DELETE key
CONTAINS key
CLEAR
Sets a value to a key.
Permission Level: WRITE
If the key already exists, it will overwrite the value.
If the key does not exist, it will create a new key with the value.
If the value is NULL
, it will delete the key.
Gets a value from a key.
Permission Level: READ
If the key does not exist, it will return NULL
.
Deletes a value from a key.
Permission Level: WRITE
If the key does not exist, it will do nothing.
Checks if a key exists.
Permission Level: READ
If the key exists, it will return TRUE
, otherwise, it will return FALSE
.
Deletes all keys and values from the database.
Permission Level: ADMIN
This action is dangerous and permanent, use with caution.
TRUE
and FALSE
are the only two boolean values in the database.
They are case-insensitive.
NULL
is a special data type that represents the absence of a value.
It can only be returned by the [GET
] command when the key does not exist.
Setting a key to NULL
is equivalent to deleting the key.
from dumbdb import DumbDB
class Message:
def __init__(self, content: str, user_id: int):
self.content = content
self.user_id = user_id
def __str__(self):
return f"Message(content={self.content}, user_id={self.user_id})"
db = DumbDB[Message]("messages")
db.set(0, Message("Hello", 0))
print(db.get(0)) # Message(content="Hello", user_id=0)
db.delete(0)
print(db.contains(0)) # False
db.clear()
use dumbdb::DumbDB;
#[derive(Debug)]
struct Message {
content: String,
user_id: u64,
}
fn main() {
let mut db = DumbDB::<Message>::new("messages");
db.set(0, Message { content: "Hello".to_string(), user_id: 0 });
println!("{:?}", db.get(0)); // Message { content: "Hello", user_id: 0 }
db.delete(0);
println!("{}", db.contains(0)); // false
db.clear();
}