Skip to content

ritalin/omelet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Omelet - SQL base object mapper for php.

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 ...

About

Micro Object Relational Mapper for PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages