This is a fork of original j4mie/idiorm package
http://j4mie.github.com/idiormandparis/
A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5 and above.
Tested on PHP 5.2.0+ - may work on earlier versions with PDO and the correct database drivers.
Released under a BSD license.
See Also: Paris, an Active Record implementation built on top of Idiorm.
ORM::configure('mysql:host=localhost;dbname=test_db');
ORM::configure('username', 'mysql_user');
ORM::configure('password', 'mysql_password');
$user = ORM::for_table('user')
->where_equal('username', 'j4mie')
->find_one();
$user->first_name = 'Jamie';
$user->save();
$tweets = ORM::for_table('tweet')
->select('tweet.*')
->join('user', array(
'user.id', '=', 'tweet.user_id'
))
->where_equal('user.username', 'j4mie')
->find_many();
foreach ($tweets as $tweet) {
echo $tweet->text;
}
- Define
on duplicate key
strategy update:which translates to following SQL query:ORM::for_table('test') ->create() ->set('foo', 42) ->set('bar', 'lorem ipsum') ->set('buz', 1337) ->on_duplicate_key_update() ->on_duplicate_key_update(array('foo' => 42, 'bar' => "'dolor sit amet'" /* note single quotes */)) ->on_duplicate_key_update(array('buz' => true), $raw = false) ->save();
INSERT INTO `test` (`foo`, `bar`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `id` = LAST_INSERT_ID(`id`), `foo` = 42, `bar` = 'dolor sit amet', `buz` = VALUES(`buz`)
- Define lock mode. For
LOCK IN SHARE MODE
:forORM::for_table('test') ->select('foo') ->where_id_is(42) ->lock_in_share_mode() ->findOne();
FOR UPDATE
:ORM::for_table('test') ->select('foo') ->where_id_is(42) ->for_update() ->findOne();
- Add more than one constraint to your joins:
ORM::for_table('foo') ->table_alias('f') ->select_many(array('b.title', 'f.category')) ->left_outer_join( 'bar', array( array('f.id', '=', 'b.foo_id'), array('b.scale', '=', 'f.scale') ), 'b' ) ->find_one();
- Have value placeholders in raw join constraints:
ORM::for_table('foo') ->table_alias('f') ->select_many(array('b.title', 'f.category')) ->raw_join('bar', array('b.scale', '=', '?'), 'b', array(42)) ->find_one();
- Makes simple queries and simple CRUD operations completely painless.
- Gets out of the way when more complex SQL is required.
- Built on top of PDO.
- Uses prepared statements throughout to protect against SQL injection attacks.
- Requires no model classes, no XML configuration and no code generation: works out of the box, given only a connection string.
- Consists of one main class called
ORM
. Additional classes are prefixed withIdiorm
. Minimal global namespace pollution. - Database agnostic. Currently supports SQLite, MySQL, Firebird and PostgreSQL. May support others, please give it a try!
- Supports collections of models with method chaining to filter or apply actions to multiple results at once.
- Multiple connections supported
- PSR-1 compliant methods (any method can be called in camelCase instead of underscores eg.
find_many()
becomesfindMany()
) - you'll need PHP 5.3+
The documentation is hosted on Read the Docs: idiorm.rtfd.org
You will need to install Sphinx and then in the docs folder run:
make html
The documentation will now be in docs/_build/html/index.html
Tests are written with PHPUnit and be run through composer
composer test
To make testing on PHP 5.2 (Idiorm maintains support back to this version of PHP) there
is a Docker setup in ./test/docker_for_php52
- check the readme in there for more.
- Fix argument order in call to join() [CatalinFrancu] - issue #357
- Assign
null
toself::$_db
onreset_db()
to ensure PDO closes the connections [bleakgadfly] - issue #338
- Add a docker setup for testing with PHP 5.2 (uses PHPUnit 3.6.12, which is the last version released compatible with PHP 5.2) [Treffynnon]
- Reset Idiorm state when a cached result is returned [fayland (and Treffynnon)] - issue #319
- Fix travis builds for PHP 5.2+ (adding 7.0 and 7.1) and document support for newer PHP versions [Treffynnon]
- Correct PHPDoc comments for
selectMany()
[kawausokun] - issue #325 - Add pdo_sqlite to the composer require-dev dependencies [qyanu] - issue #328
- Document the
raw_execute()
method and add a note forget_db()
in the querying documentation - [Treffynnon]
- Fix autoincremented compound keys inserts [lrlopez] - issue #233 and pull #235
- Add @method tags for magic methods [stellis] - issue #237
- Ensure
is_dirty()
returns correctly when fed null or an empty string [tentwofour] - issue #268 - Adding Code Climate badge to the readme file [e3betht] - issue #260
- Typo in navigation [leongersen] - issue #257
- Support named placeholders logging and test [m92o] - issue #223
having_id_is()
reference undefined variable$value
[Treffynnon] - issue #224- Documentation fix - ORM query output for
where_any_is()
[uovidiu] - issue #306 - Code style fix preventing nested loops from using the same variable names [mkkeck] - issue #301
- Document shortcomings of the built in query logger [Treffynnon] - issue #307
- Add phpunit to dev dependencies, add
composer test
script shortcut and fix PDO mock in test bootstrap [Treffynnon] - New test for multiple raw where clauses [Treffynnon] - issue #236
- Remove PHP 5.2 from travis-ci containers to test against (note Idiorm still supports PHP 5.2 despite this) [Treffynnon]
- Binding of named parameters was broken [cainmi] - issue #221
- Multiple OR'ed conditions support [lrlopez] - issue #201
where_id_in()
for selecting multiple records by primary key [lrlopez] - issue #202- Add compound primary key support [lrlopez] - issue #171
- Add a RAW JOIN source to the query [moiseevigor] - issue #163
- offsetExists() should return true for null values, resolves #181 [cainmi] - issue #214
- Custom cache callback functions [peter-mw] - issue #216
- Restrict null primary keys on update/delete, resolves #203 [cainmi] - issue #205
- Ensure parameters treated by type correctly [charsleysa] & [SneakyBobito] - issue #206 & issue #208
- Reduce the type casting on aggregate functions to allow characters [herroffizier] - issue #150
- Prevent invalid method calls from triggering infinite recursion [michaelward82] - issue #152
- Add time to query logging - adds query time parameter to external logger callback function [AgelxNash] - issue #180
- Changed database array access to ensure it's always properly setup [falmp] - issue #159
- Allow unsetting the db (
ORM::set_db(null)
) to make the test work again [borrel] - issue #160 - Correct issue #176: Ensure database setup before building select [kendru] - issue #197
- Add HHVM to travis-ci build matrix [ptarjan] - issue #168
- Improve where statement precendence documentation [thomasahle] - issue #190
- Improve testing checks [charsleysa] - issue #173
Patch update to remove a broken pull request - may have consequences for users of 1.4.0 that exploited the "find_many()
now returns an associative array with the databases primary ID as the array keys" change that was merged in 1.4.0.
- Back out pull request/issue #133 as it breaks backwards compatibility in previously unexpected ways (see #162, #156 and #133) - sorry for merging this change into Idiorm - closes issue 156
find_many()
now returns an associative array with the databases primary ID as the array keys [Surt] - issue #133- Calls to
set()
andset_expr()
return$this
allowing them to be chained [Surt] - Add PSR-1 compliant camelCase method calls to Idiorm (PHP 5.3+ required) [crhayes] - issue #108
- Add static method
get_config()
to access current configuration [javierd] - issue #141 - Add logging callback functionality [lalop] - issue #130
- Add support for MS SQL
TOP
limit style (automatically used for PDO drivers: sqlsrv, dblib and mssql) [numkem] - issue #116 - Uses table aliases in
WHERE
clauses [vicvicvic] - issue #140 - Ignore result columns when calling an aggregate function [tassoevan] - issue #120
- Improve documentation [bruston] - issue #111
- Improve PHPDoc on
get_db()
[mailopl] - issue #106 - Improve documentation [sjparsons] - issue #103
- Make tests/bootstrap.php HHVM compatible [JoelMarcey] - issue #143
- Fix docblock [ulrikjohansson] - issue #147
- Fix incorrect variable name in querying documentation [fridde] - issue #146
- Documentation moved to idiorm.rtfd.org and now built using Sphinx
- Add support for multiple database connections - closes issue #15 [tag]
- Add in raw_execute - closes issue #40 [tag]
- Add
get_last_statement()
- closes issue #84 [tag] - Add HAVING clause functionality - closes issue #50
- Add
is_new
method - closes issue #85 - Add
ArrayAccess
support to the model instances allowing property access via$model['field']
as well as$model->field
- issue #51 - Add a result set object for collections of models that can support method chains to filter or apply actions to multiple results at once - issue #51 and #22
- Add support for Firebird with
ROWS
andTO
result set limiting and identifier quoting [mapner] - issue #98 - Fix last insert ID for PostgreSQL using RETURNING - closes issues #62 and #89 [laacz]
- Reset Idiorm after performing a query to allow for calling
count()
and thenfind_many()
[fayland] - issue #97 - Change Composer to use a classmap so that autoloading is better supported [javierd] - issue #96
- Add query logging to
delete_many
[tag] - Fix when using
set_expr
alone it doesn't trigger query creation - closes issue #90 - Escape quote symbols in "_quote_identifier_part" - close issue #74
- Fix issue with aggregate functions always returning
int
when isfloat
sometimes required - closes issue #92 - Move testing into PHPUnit to unify method testing and query generation testing
- Fix issue #78 - remove use of PHP 5.3 static call
- Fix bug where input parameters were sent as part-indexed, part associative
- Fix minor bug caused by IdiormStringException not extending Exception
- Setup composer for installation via packagist (j4mie/idiorm)
- Add
order_by_expr
method [sandermarechal] - Add support for raw queries without parameters argument [sandermarechal]
- Add support to set multiple properties at once by passing an associative array to
set
method [sandermarechal] - Allow an associative array to be passed to
configure
method [jordanlev] - Patch to allow empty Paris models to be saved ([j4mie/paris]) - issue #58
- Add
select_many
andselect_many_expr
- closing issues #49 and #69 - Add support for
MIN
,AVG
,MAX
andSUM
- closes issue #16 - Add
group_by_expr
- closes issue #24 - Add
set_expr
to allow database expressions to be set as ORM properties - closes issues #59 and #43 [brianherbert] - Prevent ambiguous column names when joining tables - issue #66 [hellogerard]
- Add
delete_many
method [CBeerta] - Allow unsetting of ORM parameters [CBeerta]
- Add
find_array
to get the records as associative arrays [Surt] - closes issue #17 - Fix bug in
_log_query
with?
and%
supplied in raw where statements etc. - closes issue #57 [ridgerunner]
- Fix bug in quoting column wildcard. j4mie/paris#12
- Small documentation improvements
- Add
is_dirty
method - Add basic query caching
- Add
distinct
method - Add
group_by
method
- Initial release