2017 © Pedro Peláez
 

library micro-db

Simple orm library

image

fullstackpe/micro-db

Simple orm library

  • Thursday, May 3, 2018
  • by marcomilon
  • Repository
  • 1 Watchers
  • 0 Stars
  • 82 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Micro-db

Latest Stable Version Build Status, (*1)

Micro-db is a lightweight ORM library., (*2)

Installation

First you need to install Composer. You may do so by following the instructions at getcomposer.org. Then run, (*3)

composer require fullstackpe/micro-db, (*4)

If you prefer you can create a composer.json in your project folder., (*5)

{
    "require": {
        "fullstackpe/micro-db": "^1.1"
    }
}

Then run the command, (*6)

composer install, (*7)

The ActiveRecord Class

If you have a table called book. You need to create an active record Class called Book that extends the Class micro\db\ActiveRecord. The class Book needs to implement two methods: tableName() and dbConnection()., (*8)

Example

use micro\db\ActiveRecord;

class Book extends ActiveRecord {

    public static function tableName() 
    {
        return 'book';
    }

    public static function dbConnection() 
    {
        $servername = "127.0.0.1";
        $username = "root";
        $password = "fullstack";
        $database = "mysql";

        return new \micro\db\Connection($servername, $username, $password, $database);
    }
}

Then you can instantiate the class., (*9)

Example

// Create a new book
$book = new Book();
$book->title('This is the title of my book');
$book->save();

// fetchs all books
$books = Book::find()->all();
foreach($books as $book) {
    echo $book->title;
}

// search for one book
$condition = [
    ['=', 'id', '1']
];
$book = Book::find()->where($condition)->one();
echo $book->title

The QueryBuilder Class

The queryBuilder class builds a Sql statement., (*10)

Example

$table = 'home';
$qB = new \micro\db\QueryBuilder();
$columns = [
    'id',
    'name',
    'address'
];
$sql = $qB->select($columns)->from($table)->getRawSql();

The variable $sql is equal to the string "SELECT id, name, address FROM home"., (*11)

Contribution

Feel free to contribute! Just create a new issue or a new pull request., (*12)

License

This library is released under the MIT License., (*13)

The Versions

03/05 2018

dev-master

9999999-dev

Simple orm library

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

orm

09/02 2018

1.1.0

1.1.0.0

Simple orm library

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

orm

09/02 2018

dev-dev

dev-dev

Simple orm library

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

orm

19/12 2017

1.0.0

1.0.0.0

Simple orm library

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

orm