Giter Club home page Giter Club logo

folderdb's Introduction

FolderDB

Version Average time to resolve an issue Average time to resolve an issue stable MIT License

FolderDB is a flat-file JSON database with usage similarity to MongoDB's PHP API.

It saves data into directories as files with key/value pairs in JSON format. The "key" is the file name where the "value" is JSON data.

FolderDB uses magic methods to automatically create or manage "collections"/directories.

composer require irfan-dahir/folderdb

$client->users->insert(
    'username',
    \FolderDb\Document::fromArray([
        'id' => '123',
        'first_name' => 'John',
        'last_name' => 'Doe',
        'email' => '[email protected]'
    ])
);

$user = $client->users->get('username');

echo $user->email; // "[email protected]"

// To Array
echo $user->toArray()['email'];

Getting Started

require_once __DIR__ .'/vendor/autoload.php';

// Create a client and pass the path to the database folder
$client = new \FolderDb\Client('/path/to/database');

Create a Folder

$client->users;

Insert data

$data = [
    'id' => '123',
    'first_name' => 'John',
    'last_name' => 'Doe',
    'email' => '[email protected]'
];

// `new \FolderDb\Document()` takes JSON string directly, so we have to convert it to array
$client->users->insert(
    'username',
    \FolderDb\Document::fromArray($data)
);

Count

echo $client->users->count(); // 2

Get document

$user = $client->users->get('username'); // returns `\FolderDb\Document`

// Access your entry as an object
echo $user->email; // "[email protected]"


// Access your entry as an array
$userArray = $user->toArray();
echo $userArray['email']; // "[email protected]"

Get all documents in a folder

$user = $client->users->getAll(); // returns array of `\FolderDb\Document`

Check if document exists

$client->users->exists('username'); // returns boolean

Delete "Collection"

⚠️ This method deletes the "Collection" folder and it's contents. ⚠️

$user->delete(); // returns boolean

Dependencies

Issues

Please create an issue for any bugs/security risks/etc

folderdb's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.