Giter Site home page Giter Site logo

bilbon's Introduction

Bilbon : The greatest minimalistic & fantastic ORM

Made by a geek for geeks

What or Who is Bilbon ? Well, in the first place it's an hobbit ...

Bilbo the hobbit

... but it's also a lightest weight ORM in da world - less than 100 lines of code.

U may ask why ?

Well coz it's funny to code light things, coz is 100% tested, coz it's bug free - but overall coz if someday you want to CRUD something, this maybe could be helpfull :)

How does it works ?

Creating a model

class User extends \bilbon\Hobbit {
    public static $table = 'user';
    public function setName( $name ) {
        $this->name = $name;
    }
}

As you see every object is an hobbit, but if you want to ... you could also write :

use \bilbon\Hobbit as ActiveRecord;
class User extends ActiveRecord {
    public static $table = 'user';
    public function setName( $name ) {
        $this->name = $name;
    }
}

... do you want to ? You shouldn't, keep the ORM style and directly use the Hobbit mojo (coz it's cool)

Using a model

$user = new User();
$user->setName('Thorin');
$user->insert();

but it's not necessary to define getters & setters, you can dirrectly do :

$user = new User();
$user->name = 'Thorin';
$user->insert();

Requesting

$users = User::request('select * from users');
print_r($users);

The great Gandalf storage

Gandalf provides the PDO storage. To define a storage engine you can directly define it's configuration :

\bilbon\Gandalf::$instances['default'] = array(
    'dsn' => 'mysql:host=localhost,dbname=epic',
    'user' => 'root',
    'password' => ''
);

An ActiveRecord could use another storage provider if you configure it :

use \bilbon\Gandalf as Storage;
use \bilbon\Hobbit as ActiveRecord;
Storage::$instances['sauron'] = array(
    'dsn' => 'mysql:host=127.0.0.1,dbname=private',
    'user' => 'root',
    'password' => ''
);
class BadGuys extends ActiveRecord {
    public static $storage = 'sauron';
    public static $table = 'bad_guys';
}

You can also freely use the PDO connector like this :

use \bilbon\Gandalf as Storage;
Storage::$instances['sauron'] = array(
    'dsn' => 'mysql:host=127.0.0.1,dbname=private',
    'user' => 'root',
    'password' => ''
);
Storage::get('sauron')->exec('whatever you want');

Disclamer

It's cool if you want to use it over a small business logic domain as for example 3 or 4 tables, but not more.

Keep in mind that just a CRUD wrapper written for fun ...

It's under MIT license - do what you want with ...


Even more epic

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.