2017 © Pedro Peláez
 

library condense

Flat-file database in PHP.

image

lambdacasserole/condense

Flat-file database in PHP.

  • Sunday, September 10, 2017
  • by lambdacasserole
  • Repository
  • 1 Watchers
  • 0 Stars
  • 69 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 5 % Grown

The README.md

Condense

Flat-file database in PHP., (*1)

Logo, (*2)

Based on the Fllat and Prequel libraries by Wylst. Special mention for Alfred Xing who seems to be the main contributor behind both. With added support for:, (*3)

Installation

Install Condense via Composer like this:, (*4)

composer require lambdacasserole/condense

Or alternatively, if you're using the PHAR (make sure the php.exe executable is in your PATH):, (*5)

php composer.phar require lambdacasserole/condense

Usage

To initialize a new database or load an existing one, do this., (*6)

$db = new Database('employees');

This will, by default, create a file db/employees.dat or load that file, if it already exists. You can change the path at which the flat file database will be created thusly., (*7)

$db = new Database('employees', '../storage');

The constructor also accepts a third parameter which allows you to specify a key to use to encrypt the database with., (*8)

$db = new Database('secrets', '../private', 'my-secret-password');

When loading the database again, this same password must be used., (*9)

Create

Use insert to add a record (row) to the database., (*10)

$hire = ['first_name' => 'Ethan', 'last_name' => 'Benson', 'salary' => 20000];
$employees->insert($hire);

Retrieve

Condense provides several methods for data retrieval., (*11)

One Value

Use the get method. Specify a field name, another field name, and a value. It will return the value of the first field where (in the same row), the value of the second field matches the given value., (*12)

// Returns the salary of the first employee with the first name 'Ethan' (20000).
$employees->get('salary', 'first_name', 'Ethan');

Field Subset

Use the select method. Returns some (or all) fields in a table, specified by giving an array of desired field names., (*13)

// Returns the whole database.
$employees->select([]);

// Returns the first name of each employee, for example: 
// [['Ethan'],['Thomas'],['James']]
$employees->select(['first_name']);

Update

Condense provides a couple of methods for updating existing data in a database., (*14)

One Field

Use the to method to update one field for any row satisfying a condition., (*15)

// Change every employee with a first name 'Ethan' to have the surname 'Smithers'.
$employees->to('last_name', 'Smithers', 'first_name', 'Ethan');

One Row

Use the update method to update a row by index., (*16)

// Change the first row in the database completely.
$employees->update(0, ['first_name' => 'Alison', 'last_name' => 'Bradberry']);

Delete

Use the remove method to delete a row in the database., (*17)

// Remove the first row in the database.
$employees->remove(0);

Caveats

This is a flat file database system. It removes the headache of setting up and configuring a database server, but introduces a few of its own:, (*18)

  • I/O will be much slower due to many disk read/write actions
  • Encrypting a database will hugely affect performance
  • Bugs may arise due to concurrency issues
  • Misconfigured web applications using this library may accidentally allow their databases to be downloaded over HTTP

The Versions

10/09 2017

dev-master

9999999-dev

Flat-file database in PHP.

  Sources   Download

MIT

The Requires

 

27/08 2017

v1.2

1.2.0.0

Flat-file database in PHP.

  Sources   Download

MIT

The Requires

 

13/08 2017

dev-unit-tests

dev-unit-tests

Flat-file database in PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

30/01 2017

v1.1

1.1.0.0

Flat-file database in PHP.

  Sources   Download

MIT

The Requires

 

24/01 2017

v1.0

1.0.0.0

Flat-file database in PHP.

  Sources   Download

MIT

The Requires