Download the PHP package greg0/lazer-database without Composer
On this page you can find all versions of the php package greg0/lazer-database. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package lazer-database
Lazer - php flat file database based on JSON files
PHP Library to use JSON files like a database.
Functionality inspired by ORM's
Requirements
- PHP 7.1+
- Composer
Installation
Easiest way to install Lazer Database
is to use Composer. Of course you can use your own autoloader but you must configure it properly by yourself. You can find my Package on Packagist.org.
To add library to your dependencies, execute:
Tests
Easiest way to run unit tests is to use composer script
You can also use docker
Structure of table files
table_name.data.json
- table file with data
table_name.config.json
- table file with configuration
Basic Usage
First of all you should define constant LAZER_DATA_PATH
containing absolute path to folder with JSON files:
Then set up namespace:
Methods
Chain methods
setField()
- set value of field (alternative to magic__set()
)limit()
- returns results between a certain number range. Should be used right before ending methodfindAll()
.orderBy()
- sort rows by key in order, can order by more than one field (just chain it).groupBy()
- group rows by field.where()
- filter records. Alias:and_where()
.orWhere()
- other type of filtering results.with()
- join other tables by defined relations
Ending methods
getField
- get value of field (alternative to magic__get()
)issetField
- check if field is isset (alternative to magic__isset()
)addFields()
- append new fields into existing tabledeleteFields()
- removing fields from existing tableset()
- get key/value pair array argument to save.save()
- insert or Update data (automatically detect if it needs an insert or update).insert()
- force an insert.delete()
- deleting data.relations()
- returns array with table relationsconfig()
- returns object with configuration.fields()
- returns array with fields name.schema()
- returns assoc array with fields name and fields typefield => type
.lastId()
- returns last ID from table.find()
- returns one row with specified ID.findAll()
- returns rows.asArray()
- returns data as indexed or assoc array:['field_name' => 'field_name']
. Should be used after ending methodfindAll()
orfind()
.count()
- returns the number of rows. Should be used after ending methodfindAll()
orfind()
.
Create database
More information about field types and usage in PHPDoc
Remove database
Check if a database exists
Select
Multiple select
Single record select
Type ID of row in find()
method.
You also can do something like that to get first matching record:
Insert
Do not set the ID.
Update
It's very smilar to Inserting
.
You can also set many field by simple key-value array
Remove
Single record deleting
Multiple records deleting
Clear table
Relations
To work with relations use class Relation
Relation types
belongsTo
- relation many to onehasMany
- relation one to manyhasAndBelongsToMany
- relation many to many
Methods
Chain methods
belongsTo()
- set relation belongsTohasMany()
- set relation hasManyhasAndBelongsToMany()
- set relation hasAndBelongsToManylocalKey()
- set relation local keyforeignKey()
- set relation foreign keywith()
- allow to work on existing relation
Ending methods
setRelation()
- creating specified relationremoveRelation()
- remove relationgetRelation()
- return informations about relationgetJunction()
- return name of junction table inhasAndBelongsToMany
relation
Create relation
Remove relation
Get relation information
You can do it by two ways. Use Standard Database class or Relation but results will be different.
Description
For some examples please check Tutorial file. More informations you can find in PHPDoc, I think it's documented very well.
E-mail: [email protected]
If you like and using/want to use my repo or you have any suggestions I will be greatful for sending me few words on e-mail.