andela-aonyango/potato-orm

A lightweight ORM built using PHP and PDO.

v1.0.3 2016-02-26 12:27 UTC

This package is not auto-updated.

Last update: 2024-04-05 15:39:43 UTC


README

potato-orm

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

A light-weight ORM which allows you to insert records into a database, retrieve them, update them, and delete them.

Install

Via Composer

$ composer require andela-aonyango/potato-orm

In the package directory, run

$ composer install

Usage

Edit the example .env provided in the root of this package with the database settings you will use (make sure you .gitignore YOUR .env file). The one given uses MYSQL settings. PDO supports many database drivers so you can get familiar with what are valid/invalid inputs for the DSN and so on.

Sample Table

create table Person (
    id int unsigned auto_increment primary key,
    first_name varchar(30) not null,
    last_name varchar(30) not null,
    age int(2),
    gender varchar(7)
);

Sample Usage

<?php
// Example usage of this ORM

require "vendor/autoload.php";

use PotatoORM\Models\Person;

$person = new Person();
$person->first_name = "yua";
$person->last_name = "madha";
$person->age = 73;

// the add() method inserts an object and returns the last inserted id
$id = $person->add();

// retrieve the just-added person
$test = $person->find($id);

print_r($test);

$test->gender = "female";
$test->update();

// is the update successful
print_r($test->find($id));

// delete the person from the database
$test->remove();

// retrieve all people
print_r($person->findAll());
?>

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email andrew.onyango@andela.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.