ritalin/omelet

SQL base object mapper for php

0.3.4 2015-07-08 06:11 UTC

README

This Library is inspired by Doma(https://github.com/domaframework/doma).

Requirements

php >= 5.5.x

Installation

Omelet can be installed with Composer.

Define the following requirement in your composer.json file:

{
    "require": {
        "ritalin/omelet": "*"
    }
}

Quick Start

  1. Define Dao (Data Access Object) interface.

    • DAO method is need to describe an annotation comment to distingish database command/query.
    use \Omelet\Annotation\Select;
    
    interface TodoDao {
        /**
         * @Select
         */
        function listAll();
    }
  2. Prepare sql file of same name as method. sql file path depends on namespace for dao interface.

    -- listAll.sql
    select * from todo order by id
  3. Instanciate \Omelet\Builder\DaoBuilderContext .

    • At least, need to a connection string to database as configuration.
    $config = \Omelet\Builder\Configuration;
    $config->connectionString = "driver=pdo_sqlite&path=/path/to/todo.sqlite3";
    
    $context = new \Omelet\Builder\DaoBuilderContext($config);
  4. Generate Dao concrete class.

    $context->build(Todo::class);
  5. Use Dao.

    • A Dao concrete class name note that 'Impl' is suffixed to interface name by default.
    $conn = \Doctrine\DBAL\DriverManager->getConnection($context->connectionString());
    $dao = new TodoImpl($conn, $context);
    $rows = $dao->listAll();

Sample Application

Please see ritalin/omelet-bear-example implemented with BEAR.Sunday (https://github.com/bearsunday/BEAR.Sunday) framework.

now work in progress ...