Demand DB
A database that requires nothing more than a PHP script. It is NOT designed to be efficient haha.
Written by Ed at the end of Sept / start of Oct 2024. Demand DB uses collections of JSON objects to store data. Each collection has its own `.json` file.
For Rapid Sites I have slightly extended the functionality to allow for easy authentication.
Reading
Data can be read either by reading a specific document which you know the ID of, or by querying a whole collection.
Reading a single document (When you knoe the ID)
You MUST know the document's ID.
// Get a task by it's ID
$task = $database->get_document("tasks", "task_id");
Reading when you don't know the IDs.
Read all documents in a collection
// Get all documents in the 'tasks' collection
$tasks = $database->get_documents("tasks")->documents;
Select all documents that match a given criteria.
// Get all tasks that have the label 'urgent'
$tasks = $database->get_documents("tasks")->where("label", "=", "urgent")->documents;
Select the first document that matches a given criteria.
$tasks = $database
->get_documents("tasks")
->where("label", "=", "urgent")
->sort_by("time", "asc")"
->first();
Select the documents owned by the current user
safely_start_session();
$database = new DemandDB();
$words = $database->get_documents('tasks')->withOwner($_SESSION["user_id"])->documents;
Create a new document
// Create a task
$taskID = $database->create_document("tasks", $data);
Update a document
Any fields that already exist in the document and that are not updated will be left alone.
// Update a task
$database->update_document("tasks", "task_id", $data);
Delete a document
$database->delete_document("tasks", "task_id");