jelix/dao

Lightweight object relation mapping based on the Database Access Object pattern

dev-main 2021-10-04 10:34 UTC

This package is auto-updated.

Last update: 2021-12-04 10:51:07 UTC


README

Lightweight object relation mapping based on the Database Access Object pattern.

This library has been extracted from the Jelix framework 1.7, and has been modernized a bit.

The work to use it outside Jelix is in progress.

installation

You can install it from Composer. In your project:

composer require "jelix/dao"

Usage

Quick start:

use \Jelix\Database\AccessParameters;
use \Jelix\Database\Connection;
use \Jelix\Dao\DaoLoader;

// create a connector to the database
$accessParameters = new AccessParameters(
    array(
      'driver'=>'sqlite3',
      "database"=>"/...../tests.sqlite3",
    ), 
    array('charset'=>'UTF-8')
);

$connector = Connection::create($accessParameters);

// path to a directory where compiled class can be stored
$tempPath = '...'; 

// path to a directory where to find dao xml files
// it is optional
$daosDirectory = '...';

$loader = new DaoLoader(
        $connector,
        $tempPath,
        $daosDirectory
);

$daoFile = 'myDao.xml';

$dao = $loader->get($daoFile);

// we can now use methods to query records

$list = $dao->findAll();

$record = $dao->get($primaryKey);

$list = $dao->myCustomMethod();

Documentation is not available yet. But you can read the documentation of the original library from Jelix, to know more : jDao.