Skip to content

sslgeorge/PotatoORM

Repository files navigation

#PotatoORM StyleCI Circle CI Coverage Status

This is an implementation of a poor man's ORM, this ORM helps abstraction from the database/data-access layer, providing you with a clean and easy way to create models.

##Usage

The procedure for usage include creating a class that inherits the BaseModel class

    namespace BB8\Potatoes\ORM\Models;

    use BB8\Potatoes\ORM\System\BaseModel;

    class User extends BaseModel
    {
        protected static $tableName = "Users";
    }

####Create To create a new model you instantiate the class that extends the BaseModel class and set properties of the model and then calling the save() method to save to the databse

    $user = new User();
    $user->first_name   =   "Darth";
    $user->last_name    =   "Vader";
    $user->description  =   "Once a heroic Jedi Knight";

    $user->save();

####Get/Select To get/select a particular record, you can use the getAll(), selectWhere(), or find() methods

#####getAll() Returns array containing object of the calling class, in this case User

    User::getAll();

#####selectWhere() Takes an associative array as parameter containing the conditions to meet and returns an array of the objects if multiple result, or a single object if single result.

    User::selectWhere(array("first_name"=>"Darth"));

#####find() Returns a single object matching the id passed to the find() method

    User::find(1);

####Update To update a record, you first find the record, change the values in the model and call the save method to update

    $user = User::find(1);
    $user->description = "Darth Vader was seduced by the dark side of the Force and became a Sith Lord";
    $user->save();

####Delete To delete a record, pass the id of the record to the static destroy() method

    User::destroy(1);

About

A simple poor mans ORM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages