wallrio/deskdb

A small embedded database, based on JSON format.

1.0.5 2021-09-18 23:24 UTC

This package is auto-updated.

Last update: 2024-04-19 05:11:39 UTC


README

A small embedded database, based on JSON format.

Installation

It's recommended that you use Composer to install Directly.

$ composer require wallrio/deskdb "*"

Instantiate a collection class

use deskdb\Collection as Collection;

$deskdb = new Collection(COLLECTION_NAME,DRIVER);
  • Example
use deskdb\drivers\JSON as JSON;
use deskdb\Collection as Collection;

$collection = new Collection('users',new JSON(__DIR__.'/mybase/'));

JSON, is the class responsible for effectively carrying out operations.

JSON, if the contractor's value is omitted, then the system's temporary directory will be used.

Create a document

use deskdb\Document as Document;

$user = new Document();
$user->name = "Fulano da Silva";
$user->username = "fulano";
$user->password = md5("fulano");

$collection->post($user);

Another examples

Search all documents in the collection

$result = $collection->get();

Search for a document

$result = $collection->get(KEY,VALUE,OPERATOR);
  • KEY: can be any document key
  • VALUE: can be any document value, partial or whole
  • OPERATOR: reference value to perform the search
    • ==: search for a similar value
    • !=: search for different value
    • ===: search by identical value
    • !==: look for exactly different value
    • like: look for a similar value (type soundex)
    • !like: search for unlike value (type soundex)
    • contain: search by value part
    • !contain: search for part of non-existent value

Search for the first document occurrence

$result = $collection->getFirst(KEY,VALUE,OPERATOR);

Delete document

$result = $collection->get();

$collection->delete($result);

the value ** delete ** accepts an array of results

Update document

$result = $collection->getFirst();

$result->name="ANOTHER NAME";
$result->age="34";

$collection->put($result);

the ** put ** value accepts an array of results

Recomendations

It is explicitly recommended to use the code below to block the viewing of your JSON directories and documents.

Below example of script for blocking

APACHE

Create an .htaccess file in your application's main directory

# Block directory list view
Options -Indexes

# Block the visualization of document JSON
<Files "*_deskdb.json">
Order Allow,Deny
Deny from all
</Files>
NGINX

Insert the excerpt below into your server's nginx.conf file.

location ~ \.*_deskdb.json {
        deny all;
    }

License

The DeskDB is licensed under the MIT license. See License File for more information.