PHPackages                             john-kariuki/potato-orm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. john-kariuki/potato-orm

ActiveLibrary[Database &amp; ORM](/categories/database)

john-kariuki/potato-orm
=======================

Andela Checkpoint two. A simple agnostic ORM that can perform the basic crud database operations.

1.1.3(10y ago)11421MITPHPPHP &gt;=5.6

Since Feb 13Pushed 10y ago1 watchersCompare

[ Source](https://github.com/andela-jkariuki/checkpoint-two-potato-orm)[ Packagist](https://packagist.org/packages/john-kariuki/potato-orm)[ Docs](https://github.com/andela-jkariuki/checkpoint-two-potato-orm)[ RSS](/packages/john-kariuki-potato-orm/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (2)Versions (16)Used By (0)

\#Checkpoint Two: Potato ORM

[![Build Status](https://camo.githubusercontent.com/2ffe5ce300582f4a8cb8675048d06c5e91dab4282222c82f32091116c328dc11/68747470733a2f2f7472617669732d63692e6f72672f616e64656c612d6a6b617269756b692f636865636b706f696e742d74776f2d706f7461746f2d6f726d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/andela-jkariuki/checkpoint-two-potato-orm)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/81fd0dac6ab41f7b956d3cf7037b71fb99539936f7b76d0bf9d4d09b3e45f373/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616e64656c612d6a6b617269756b692f636865636b706f696e742d74776f2d706f7461746f2d6f726d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/andela-jkariuki/checkpoint-two-potato-orm/?branch=master)[![Coverage Status](https://camo.githubusercontent.com/049e915b16751bf2ab543aee7a53146795759b3a11cbd6fd0d29dd17d05cb9df/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f616e64656c612d6a6b617269756b692f636865636b706f696e742d74776f2d706f7461746f2d6f726d2f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/andela-jkariuki/checkpoint-two-potato-orm?branch=develop)[![Latest Version on Packagist](https://camo.githubusercontent.com/19bb9f295322e6244dbda347fc4c9965d5ee1a45df6692acd26fd295c3392a0c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f686e2d6b617269756b692f706f7461746f2d6f726d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/john-kariuki/potato-orm)[![Total Downloads](https://camo.githubusercontent.com/4738ef3d662095354f91ceaef3098e8d9d680b75d5a4c5ef1b8c363ab7304623/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f686e2d6b617269756b692f706f7461746f2d6f726d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/john-kariuki/potato-orm)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/andela-jkariuki/checkpoint-two-potato-orm)

\##Andela Checkpoint Two

A simple agnostic ORM that can perform the basic crud database operations.

\#####TIA

\##Install

Via Composer

```
$ composer require john-kariuki/potato-orm
```

Via Github

```
$ git clone git@github.com:andela-jkariuki/checkpoint-two-potato-orm.git
```

Update packages

```
$ composer install
```

Rename .env.example to .env

Update your .env to have your database credentials

```
DB_DRIVER = "sqlite"
DB_USERNAME = "homestead"
DB_PASSWORD = "secret"
DB_NAME = "potato.db"
DB_HOST = "localhost"
DB_PORT = 8000
```

\##Usage

To use Potato ORM, extend the `PotatoModel` class.

The default naming convention for a table name associated with a class is it's lowercase plural syntax.

The default naming convention for the unique table field is id.

To overwrite the default naming conventions, declare protected variables as explained below.

```
/**
 * Default table name for Car class is cars.
 *
 * Default uniqueId field for table cars is id
 */
class Car extends PotatoModel
{
    //protected static $table = "your_table_name";
    //protected static $uniqueId = "your_unique_id";
}
```

Ensure the table exists before using the Potato ORM class to avoid exceptions.

Use the SQL statement template below

```
CREATE TABLE `cars` (
	`id`	INTEGER PRIMARY KEY AUTOINCREMENT,
	`name`	TEXT,
	`model`	TEXT,
	`year`	INTEGER
)
```

Potato ORM gives you access to the following methods;

Reading Data

```
//Get all rows that from a table
$cars = Car::getAll();
```

Inserting data

```
//insert a new row to the table
$car = new Car();
$car->name = "Boss";
$car->model = "Up";
$car->year = 2013;

$car->save(); //returns a boolean value. true or false if saved or not respectively.
```

Updating data

```
//Update an existing row in the database
$car = Car::find(1);
$car->name = "Me Hennesy";
$car->year = 2015;
```

Deleting data

```
//delete an existing row in the table
var_dump(Car::destroy(1));
```

\###Sample Code

Ensure to write your code inside a `try catch` block to catch any exceptions

```
namespace DryRun;

use Potato\Manager\PotatoModel;
use PDOException;

require 'vendor/autoload.php';

class Car extends PotatoModel
{
    //protected static $table = "your_table_name";
    //protected static $uniqueId = "your_unique_id";
}
try {

    echo "Create a new Car\n";

    $car = new Car();
    $car->name = "Lambo";
    $car->model = "Hura";
    $car->year = 2013;

    if ( $car->save()) {
	   echo "\nCar has been created.\n\n";
    } else {
	   echo "There was an error saving your car.";
    }

    echo  "Find the car that has just been created and updated the name and year\n";

    $car = Car::find(1);

    $car->name = "Huracan";
    $car->year = 2015;

    echo $car->save();

    echo "\None row (of our new Car) has been updated.\n\n";

    echo "Get all cars and print them out\n\n";
    $cars = Car::getAll();
    print_r($cars);

    echo "\nAwesome.! Now let's delete the old car. Buy A new one if you can\n\n";

    var_dump(Car::destroy(1));
    print_r(Car::getAll());

    echo "\nYour old car is dead and gone\n";

} catch (PDOException $e) {
    echo $e->getMessage();
}
```

Contributing
------------

[](#contributing)

Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Github](https://github.com/andela-jkariuki/checkpoint-two-potato-orm).

Pull Requests
-------------

[](#pull-requests)

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
- **Create feature branches** - Don't ask us to pull from your master branch.
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

Security
--------

[](#security)

If you discover any security related issues, please email me at [John Kariuki](john.kariuki@andela.com) or create an issue.

Credits
-------

[](#credits)

[John kariuki](https://github.com/andela-jkariuki)

License
-------

[](#license)

### The MIT License (MIT)

[](#the-mit-license-mit)

Copyright (c) 2016 John kariuki

> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity66

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

14

Last Release

3775d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/80876d59ad56fa7b92b7308a6fde6f8bb34db5a4bef2f5c7453d81fc29fcad6d?d=identicon)[andela-jkariuki](/maintainers/andela-jkariuki)

---

Tags

john-kariukiPotato-ORM

### Embed Badge

![Health badge](/badges/john-kariuki-potato-orm/health.svg)

```
[![Health](https://phpackages.com/badges/john-kariuki-potato-orm/health.svg)](https://phpackages.com/packages/john-kariuki-potato-orm)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k41.3M38.9k](/packages/orchestra-testbench)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
