The goal of this library is to serve as an abstraction layer on top of multiple database adapters and allow storage and query of JSON based documents and relationships.
This library will abstract multiple database technologies using the adapter's design patterns. Below is a list of various adapters we should consider to support:
- MariaDB
- MySQL
- Postgres
- MongoDB
This library will support storing and fetching of all common JSON simple and complex data types.
- String
- Integer
- Float
- Boolean
- Null
- Array
- Object
- Relationships
- Reference (collection / document)
- References (Array of - collection / document)
Databases that don't support the storage of complex data types should store them as strings and parse them correctly when fetched.
Each database adapter should support the following action for fast storing and retrieval of collections of documents.
Databases (Schemas for MariaDB)
- create
- delete
Collections (Tables for MariaDB)
- createCollection($name)
- deleteCollection($name)
Attributes (Table columns for MariaDB)
- createAttribute(string $collection, string $name, string $type)
- deleteAttribute(string $collection, string $name)
Indices (Table indices for MariaDB)
- createIndex(string $collection, string $name, string $type)
- deleteIndex(string $collection, string $name, string $type)
Documents (Table rows columns for MariaDB)
- getDocument(string $collection, $id)
- createDocument(string $collection, array $data)
- updateDocument(string $collection, $id, array $data)
- deleteDocument(string $collection, $id)
Each database adapter should allow querying simple and advanced queries in consideration of underline limitations.
Method for quering data:
- find(string $collection, $filters)
- findFirst(string $collection, $filters)
- findLast(string $collection, $filters)
- count(string $collection, $filters)
- Equal (==)
- Not Equal (!=)
- Less Than (<)
- Less or equal (<=)
- Bigger Than (>)
- Bigger or equal (>=)
- Containes / In
- Is Null
- Is Empty
Each database adapter should support two methods for paging. The first method is the classic Limit and Offset
. The second method is After
paging, which allows better performance at a larger scale.
Multi-column support, order type, use native types
Each database collection should hold parallel tables (if needed) with row-level metadata, used to abstract features that are not enabled in all the adapters.
Allow to apply custom filters on specific pre-chosen fields. Avaliable filters:
- Encryption
- JSON (might be redundent with object support)
- Hashing (md5,bcrypt)
The library should support memory caching using internal or external memory devices for all read operations. Write operations should actively clean or update the cache.
All database adapters should support UTF-8 encoding and accept emoji characters.
- Data Types
- Operations
- Security
- Benchmarks
- Performance Tips
- Known Limitations
- Check for SQL Injections
Collections Metadata
CREATE TABLE IF NOT EXISTS `collections` (
`_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`_metadata` text() DEFAULT NULL,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Documents
CREATE TABLE IF NOT EXISTS `documents_[NAME]` (
`_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`_uid` varchar(128) NOT NULL AUTO_INCREMENT,
`custom1` text() DEFAULT NULL,
`custom2` text() DEFAULT NULL,
`custom3` text() DEFAULT NULL,
PRIMARY KEY (`_id`),
UNIQUE KEY `_index1` (`$id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Documents Authorization
CREATE TABLE IF NOT EXISTS `documents_[NAME]_authorization` (
`_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`_document` varchar(128) DEFAULT NULL,
`_role` varchar(128) DEFAULT NULL,
`_action` varchar(128) DEFAULT NULL,
PRIMARY KEY (`_id`),
KEY `_index1` (`_document`)
KEY `_index1` (`_document`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;