Giter Club home page Giter Club logo

bracketdb's Introduction

Bracket

Database using .json files for prototyping

Requirements

  • PHP 5.4+

Best used for

  • Prototypes/small projects
  • When you want to store some data in JSON file instead of MySQL database.

Setup

Make sure you have following structure in your project:

bracketdb/
bracketdb/data
bracketdb/data/.htaccess
bracketdb/trash
bracketdb/Bracket.php

Add to working PHP file(s).

use Bracket\BracketDB as DB;
include('bracketdb/Bracket.php');

Database actions

Create table
DB::create('users'); 

This is going to create users.json in bracketdb/data.

Connect
DB::table('users'); 
Trash table
DB::trash('users'); 

Moves users.json to bracketdb/trash.

Restore table
DB::restore('users'); 

If bracketsdb/trash/users.json exists, it will be restored.

Delete table
DB::delete('users'); 

This will permanently delete users.json from file system.

Methods

Method Info
all() Returns whole table.
get() Gets the object.
count() Counts how many rows is in the object.
first() Gets the first object.
max() Returns highest column value.
min() Returns lowest column value.
avg() Returns average column value.
sum() Returns sum of all column.
find() Finds row by ID or specified column.
lists() Returns all values of specific column.
where() Condition (column, operator, value).
andWhere() Same as where(), but used as chain method.
insert() Inserts data (array) to table.
insertAutoId() Inserts data (array) with auto-assigned ID to table.
orderBy() Orders data ascending or descending.
reorder() Reorders records by column value and saves it.
structure() Returns structure of table.
limit() Sets limit to read methods.
save() Saves table.
delete() Deletes row.
Select all
DB::table('users')->all();

Example (display all users with their ID and Name):

foreach(DB::table('users')->all() as $user) {
	echo "<br>ID:".$user->id;
	echo "<br>Name:".$user->name;
	echo "<br>";
}
Select & Where & andWhere
DB::table('users')->where($column, $operator, $value);

Example:

echo DB::table('users')->where('id', '=',  '1')->first()->id;

first() is required to get first and only row in this case.

Operator Meaning
= equal(s)
== equal(s)
!= not equal(s)
<> different than
< less than
> great than
<= less or equal than
>= great or equal than

addWhere() can be added to the end for extra condition.

Order By
DB::table('users')->orderBy($column, $type);

Example:

echo DB::table('users')->orderBy('name', 'asc')->get()[0]->name;
$arr = DB::table('users')->orderBy('name', 'asc')->get();

foreach($arr as $r) {
	echo $r->name;
}

asc for ascending order, ```desc' for descending.

Reorder

Similiar to orderBy. It reorders all data and saves it.

DB::table('users')->reorder($column);

Example:

DB::table('users')->reorder('name');
Edit
$table = DB::table('users');
$table->where('id', '=',  '1')->first()->name="New name";
$table->save();

Documentation not fully done yet.

bracketdb's People

Contributors

ssimunic avatar

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.