PHP Classes
elePHPant
Icontem

Potato ORM: Store and retrieve objects in databases using ORM

Recommend this page to a friend!
  Info   View files Documentation   View files View files (29)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2015-12-18 (2 years ago) RSS 2.0 feedNot enough user ratingsTotal: 139 This week: 1All time: 8,732 This week: 386Up
Version License PHP version Categories
potato-orm 1.0.0BSD License5PHP 5, Databases, Design Patterns
Description Author

This package can store and retrieve objects in databases using ORM.

It provides a base model class that can be extended by applications to create entity classes that can perform different operations to store and retrieve objects from a database table.

Currently it can get all records of a table, get one object by id or that has a given value in a field, save an object to the database table, delete one object.

This package can also create database tables with support to foreign keys.

The database is access using PDO. It supports MySQL, PostgreSQL and SQLite.

  Performance   Level  
Name: adeniyi ibraheem <contact>
Classes: 6 packages by
Country: Nigeria Nigeria
Age: 31
All time rank: 18888 in Nigeria Nigeria
Week rank: 126 Up3 in Nigeria Nigeria Up

Details

Potato-ORM

Build Status License Quality Score Scruitinizer Code Code Climate Test Coverage

Potato-ORM is a package that manages the CRUD operation of database. Potato-ORM currently supports MYSQL, POSTGRES and SQLITE Database.

Installation

PHP 5.5+ and Composer are required.

Via Composer

$ composer require ibonly/potato-orm

$ composer install

Usage

App Namespace

    namespace Ibonly\PotatoORM

Create a Class that correspond to the singular form of the table name in the database. i.e.

<?php
    namespace Ibonly\PotatoORM;

    class User extends Model
    {

    }
?>

The Model class contains getAll(), where($field, $value), find($value), save() and detroy($id) methods.

getAll()

<?php
    use Ibonly\PotatoORM\User;

    $sugar = new User();
    echo $sugar->getAll();
?>

Return type = JSON

where($field, $value)

<?php
    use Ibonly\PotatoORM\User;

    $sugar = new User();
    echo $sugar->where($field, $value);
?>

Return type = JSON

find($value)

<?php
    use Ibonly\PotatoORM\User;

    $insert = User::find(1);
    $insert->password = "password";
    echo $insert->save()
?>

To return custom message, wrap the `save()` method in an `if statement`

Return type = Boolean

save()

<?php
    use Ibonly\PotatoORM\User;

    $insert = new User();
    $insert->id = NULL;
    $insert->username = "username";
    $insert->email = "example@example.com";
    $insert->password = "password";
    echo $insert->save();
?>

To return custom message, wrap the `save()` method in an `if statement`

Return type = Boolean

detroy($value)

<?php
    use Ibonly\PotatoORM\User;

    $insert = User::destroy(2);
    die($insert);
?>

Return type = Boolean

Create Database Table

Its is also possible to create Database Table with the Schema class. The table name will be specified in the createTable($name) method.

<?php
    use Ibonly\PotatoORM\Schema;

    $user = new Schema;
    $user->field('increments', 'id');
    $user->field('strings', 'username');
    $user->field('strings', 'name', 50);
    $user->field('integer', 'age');
    $user->field('primaryKey', 'id');

    echo $table->createTable('players');
?>
Return type = Boolean

Database Constraint

Foreign Key

```
    $user->field('foreignKey', 'id', 'users_id');
```

The reference table `(users)` and field `(id)` will be written as `(users_id)`

Unique

```
    $user->field('unique', 'email')
```

Testing

$ vendor/bin/phpunit test

Contributing

To contribute and extend the scope of this package, Please check out CONTRIBUTING file for detailed contribution guidelines.

Credits

Potato-ORM is created and maintained by Ibraheem ADENIYI.

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 4 directories)
Files folder imagetest (3 files, 1 directory)
Accessible without login Plain text file .env.example Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file LICENCE Lic. License
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageDatabase (2 files)
Files folder imageExceptions (7 files)
Files folder imageHelper (4 files)
Files folder imageInterface (4 files)
  Plain text file User.php Class Class source

  Files folder image Files  /  src  /  Database  
File Role Description
  Plain text file DatabaseQuery.php Class Class source
  Plain text file DBConfig.php Class Class source

  Files folder image Files  /  src  /  Exceptions  
File Role Description
  Plain text file ColumnNotExistExeption.php Class Class source
  Plain text file DataAlreadyExistException.php Class Class source
  Plain text file DataNotFoundException.php Class Class source
  Plain text file EmptyDatabaseException.php Class Class source
  Plain text file ErrorInsertingException.php Class Class source
  Plain text file InvalidConnectionException.php Class Class source
  Plain text file TableDoesNotExistException.php Class Class source

  Files folder image Files  /  src  /  Helper  
File Role Description
  Plain text file GetData.php Class Class source
  Plain text file Inflector.php Class Class source
  Plain text file Model.php Class Class source
  Plain text file Schema.php Class Class source

  Files folder image Files  /  src  /  Interface  
File Role Description
  Plain text file DatabaseQueryInterface.php Class Class source
  Plain text file GetDataInterface.php Class Class source
  Plain text file ModelInterface.php Class Class source
  Plain text file SchemaInterface.php Class Class source

  Files folder image Files  /  test  
File Role Description
Files folder imagestubs (1 file)
  Accessible without login Plain text file DatabaseQueryTest.php Test Unit test script
  Accessible without login Plain text file ModelTest.php Test Unit test script
  Accessible without login Plain text file SchemaTest.php Test Unit test script

  Files folder image Files  /  test  /  stubs  
File Role Description
  Accessible without login Plain text file StubTest.php Test Unit test script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:139
This week:1
All time:8,732
This week:386Up