Code Monkey home page Code Monkey logo

jisly's Introduction

Jisly

PHPUnit Coverage Status Known Vulnerabilities

The smallest PHP lightweight NoSQL database library, flat file JSON.

The main goal of Jisly is to allow you to quickly start your project with the possibility of memory and flat-file storage using a NoSQL (document oriented) query syntax.

Version française ici

Concurrent access is managed !

How to install and load

This lib can be found on Packagist

composer require r0mdau/jisly:^2.0

Loading the library

Jisly relies on the PSR-4 specification for autoloading classes from file paths.

use Jisly\JislyCollection;

public function saveCart(): void {
    $jisly = new JislyCollection("/tmp/data", "cart");
    ...
}

Definitions

  1. Each document has a unique identifier called _rid.
  2. Each collection is physically represented by a file.
  3. The files are stored in a single working directory. The Jisly class is instantiated with the path to this directory as a parameter.
  4. Each time you CRUD something, all datas are stored in memory.
  5. And datas are saved on filesystem.

Examples of use

Initialization of the class

$directory contains the path to the directory where the files (=collections) of the data model will be stored.

$database = new Jisly($directory);

To access a collection

$name contains the name of the collection we want to request. Example : user.

Returns an object JislyCollection :

$database->collection($name);

Warning : each first time you access a collection, all datas are stored in memory.

To call a collection

PREAMBLE : The Insert, Update, Delete methods return a boolean, true if the action went well, false otherwise.

Insert method

Insert the array into the specified collection in JSON format and assigns a unique _rid identifier to the document if it has not been specified :

$successBool = $database->collection($file)->insert(
  [
    "name" => "Lucas",
    "firstname" => "Georges"
  ]
);

Delete method

You must first find all documents to delete to provide the _rid attribute to the delete method.

Remove the only document in the collection which has the value $rid to the attribute _rid :

$successBool = $database->collection($file)->delete($rid);

Select method

Returns all documents in the collection in an array() of objects :

$results = $database->collection($file)->find();

Return all documents in the collection that have a name attribute with Lucas as value in an array() of objects :

$results = $database->collection($file)->find(
  [
    "name" => "Lucas"
  ]
);

Return the first document that as a name attribute with 19 as an object value :

$result = $database->collection($file)->findOne(
  [
    "name" => 19
  ]
);

Logical operators OR and AND

These two logical operators can be used on find and findOne methods.

If no logical operator is provided, OR is used.

Return all documents in the collection that have a name attribute with Lucas OR a firstname attribute with Georges as values in an array() of objects :

$result = $database->collection($file)->find(
  [
    "firstname" => "Georges",
    "name" => "Lucas"
  ], JislyCollection::LOGICAL_OR
);

Return the first document in the collection that have a name attribute with Lucas AND a firstname attribute with Georges as an object value :

$result = $database->collection($file)->findOne(
  [
    "firstname" => "Georges",
    "name" => "Lucas"
  ], JislyCollection::LOGICAL_AND
);

Update method

For the modification, the documents concerned are entirely replaced by the second array() given in parameter.

You must first find all the documents to replace to provide the _rid attribute to the update method.

Modify the only document in the collection whose value $rid to the _rid attribute :

$successBool = $database->collection($file)->update(
  $rid,
  [
    "firstname" => "Georges",
    "name" => "Lucas"
  ]
);

jisly's People

Contributors

dependabot[bot] avatar peter279k avatar r0mdau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jisly's Issues

Write benchmarks

It could be interesting to have benchmarks on different actions with specified number of documents.

With increments of x10 for example between each datasets.

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.