/crash_test

Rien de plus que des tests sur mes projets/intégrations

Primary LanguagePHPMIT LicenseMIT

Queryflatfile

Build Status Coverage Status GitHub Packagist PHP from Packagist GitHub code size in bytes

About

Queryflatfile is a flat file database library written in PHP. Stores your data by default in JSON format, also supports txt, msgPack and igbinary formats. Manipulate your data with a QueryBuilder similar to SQL syntax.

Sommaire

Requirements

PHP version

Support more than 85% of current PHP versions

Version PHP QueryFlatFile 1.4.x
<= 5.4 ✗ Unsupported
5.5 / 5.6 ✓ Supported
7.0 / 7.1 / 7.2 / 7.3 / 7.4 ✓ Supported

Extensions

  • txt for recording data with PHP serialize,
  • json for recording data in JSON format,
  • msgpack for recording data in binary.
  • msgpack for recording data in binary.

Memory required

The minimum amount of memory required depends on the amount of data you are going to process and the type of operations. To gain performance use the PHP 7.x versions and the MsgPack driver.

Permission of files and directory

Permission to write and read files in the directory that will store your data.

Installation

Composer

To install QueryFlatFile via Composer you must have the installer or the binary file Composer

Go to your project directory, open a command prompt and run the following command:

composer require soosyze/queryflatfile --no-dev

Or, if you use the binary file,

php composer.phar require soosyze/queryflatfile --no-dev

Simple example

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

use Queryflatfile\Schema;
use Queryflatfile\Request;
use Queryflatfile\TableBuilder;
use Queryflatfile\Driver\Json;

$bdd = new Schema('data', 'schema', new Json());
$req = new Request($bdd);

$bdd->createTableIfNotExists('user', function(TableBuilder $table){
    $table->increments('id')
          ->string('name')
          ->string('firstname')->nullable();
});

$req->insertInto('user', [ 'name', 'firstname' ])
    ->values([ 'NOEL', 'Mathieu' ])
    ->values([ 'DUPOND', 'Jean' ])
    ->values([ 'MARTIN', null ])
    ->execute();

$data = $req->select('id', 'name')
    ->from('user')
    ->where('firstname', '=', 'Jean')
    ->fetch();

print_r($data);

$bdd->dropTableIfExists('user');

The above example will output:

Array
(
    [id] => 2
    [name] => DUPOND
)

Methods

Schema

  • dropSchema(),
  • getSchema(),
  • getSchemaTable( $table ),
  • hasColumn( $table, $columns ),
  • hasTable( $table ),
  • setConfig( $host, $name = 'schema', DriverInterface $driver = null ).

Handling tables

  • alterTable( $table, callable $callback ),
  • createTable( $table, callable $callback = null ),
  • createTableIfNotExists( $table, callable $callback = null ) :
    • boolean( $name ),
    • char( $name, $length = 1),
    • date( $name ),
    • dateTime( $name ),
    • float( $name ),
    • increments( $name ),
    • integer( $name ),
    • string( $name, $length = 255),
    • text( $name ).
  • dropTable( $table ),
  • dropTableIfExists( $table ),
  • truncateTable( $table ).

Selection request

  • select( mixed $var [, mixed $... ] ),
  • from( $table ),
  • leftJoin( $table, callable|string $column, $condition = null, $value = null ),
  • rightJoin( $table, callable|string $column, $condition = null, $value = null ),
  • union( Request $union ),
  • unionAll( Request $union ),
  • orderBy( $columns, $order = 'asc' ),
  • limit( $limit, $offset = 0 ).

Request for execution

  • insertInto( $table, array $columns ),
  • values( array $columns ),
  • update( $table, array $columns ),
  • delete().

Result (s) of the query

  • execute() Performs the insertion, modification and deletion of data,
  • fetch() Returns the first result of the query,
  • fetchAll() Returns all the results of the query,
  • lists( $name = null ) Returns a list of the column passed in parameter.

Where

  • where( callable|string $column, $condition = null, $value = null ),
  • orWhere( callable|string $column, $condition = null, $value = null ),
  • notWhere( callable|string $column, $condition = null, $value = null ),
  • orNotWhere( callable|string $column, $condition = null, $value = null ).

Supported conditions (===, ==, !=, <>, <, <=, >, >=, like, ilike, not like, not ilike)

Where between

  • between( $column, $min, $max ),
  • orBetween( $column, $min, $max ),
  • notBetween( $column, $min, $max ),
  • orNotBetween( $column, $min, $max ).

Where in

  • in( $column, callable|array $values ),
  • orIn( $column, callable|array $values ),
  • notIn( $column, callable|array $values ),
  • orNotIn( $column, callable|array $values ).

Where isNull

  • isNull( $column ),
  • orIsNull( $column ),
  • isNotNull( $column ),
  • orIsNotNull( $column ).

Where regex

  • regex( $column, $pattern),
  • orRegex( $column, $pattern ),
  • notRegex( $column, $pattern ),
  • orNotRegex( $column, $pattern ).

Usage

For examples of uses, refer to the user documentation.