jelix / dao
Lightweight object relation mapping based on the Database Access Object pattern
Installs: 1 532
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 0
Open Issues: 0
Requires
- php: >=7.4
- ext-dom: *
- ext-iconv: *
- ext-simplexml: *
- jelix/database: ^1.3.1
- jelix/file-utilities: ^1.8.4
- psr/log: ^1.1.2
Requires (Dev)
- phpunit/phpunit: 8.5.*
This package is auto-updated.
Last update: 2024-12-19 22:00:23 UTC
README
A lightweight object relation mapping based on the Database Access Object pattern.
It uses JelixDatabase as database connector.
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 $daosDirectory = '...'; // instance of a dao loader, using a Context object $loader = new DaoLoader( new \Jelix\Dao\Context( $connector, $tempPath, $daosDirectory ) ); $daoFile = 'myDao'; $dao = $loader->get($daoFile); // we can now use methods to query records $list = $dao->findAll(); foreach($list as $record) { echo $record->aField; } $record = $dao->get($primaryKey); echo $record->aField; $list = $dao->myCustomMethod(); //...
Documentation
The documentation is available into the docs directory.
History
This library has been extracted from the Jelix framework 1.7/1.8, and has been modernized a bit since. Except class names, API of factories and records are mostly the same. The XML format of dao file is the same as in Jelix 1.6/1.7/1.8.