Idiorm & Paris

Idiorm 是用于PHP5的轻量级的、接近零配置的、对象关系映射器和流畅的查询构建器。(A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.)

Github星跟蹤圖

Idiorm 是用于PHP5的轻量级的、接近零配置的对象关系映射器和流畅的查询构建器。Paris 是基于Idiorm的Active Record实现。

特性:
  • 使简单的查询和简单的CRUD操作完全无痛。
  • 在需要更复杂的SQL时摆脱困境。
  • 建立在PDO之上。
  • 使用SQL预处理语句来保护SQL注入攻击。
  • 不需要模型类,不需要XML配置,也不需要代码生成:只需要一个连接字符串就能开箱即用。
  • 由一个主类ORM组成。 额外的类以Idiorm为前缀。 最小全局命名空间污染。
  • 与数据库无关。目前支持SQLite,MySQL,Firebird和PostgreSQL。 还可以支持其他的,请试试!
  • 支持方法链的模型集合,以便在一次将多个结果过滤或应用操作。
  • 支持多个连接
  • PSR-1兼容方法(任何方法都可以以驼峰式调用而不是下划线,例如find_many() 成为findMany()) - 您将需要PHP 5.3+

用法示例:

$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;}

概覽

名稱與所有者j4mie/idiorm
主編程語言PHP
編程語言PHP (語言數: 2)
平台
許可證
發布數32
最新版本名稱v1.5.8 (發布於 )
第一版名稱0.1 (發布於 )
創建於2010-02-11 01:34:57
推送於2024-03-14 07:17:09
最后一次提交2022-07-19 09:52:54
星數2k
關注者數112
派生數370
提交數502
已啟用問題?
問題數236
打開的問題數2
拉請求數33
打開的拉請求數3
關閉的拉請求數106
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

Idiorm

Build Status Latest Stable Version Total Downloads Code Climate

http://j4mie.github.com/idiormandparis/


Feature complete

Idiorm is now considered to be feature complete as of version 1.5.0. Whilst it will continue to be maintained with bug fixes there will be no further new features added from this point on.

Please do not submit feature requests or pull requests adding new features as they will be closed without ceremony.


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.

Features

  • 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 with Idiorm. 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() becomes findMany()) - you'll need PHP 5.3+

Documentation

The documentation is hosted on Read the Docs: idiorm.rtfd.org

Building the Docs

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

Let's See Some Code

$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;
}

Tests

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.

Changelog

1.5.6 - released 2018-05-31

  • Assign null to self::$_db on reset_db() to ensure PDO closes the connections [bleakgadfly] - issue #338

1.5.5 - released 2018-01-05

  • 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]

1.5.4 - released 2018-01-04

1.5.3 - released 2017-03-21

  • Document the raw_execute() method and add a note for get_db() in the querying documentation - [Treffynnon]

1.5.2 - released 2016-12-14

1.5.1 - released 2014-06-23

1.5.0 - released 2014-06-22

1.4.1 - released 2013-12-12

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

1.4.0 - released 2013-09-05

1.3.0 - released 2013-01-31

  • 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 and TO 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 then find_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 is float sometimes required - closes issue #92
  • Move testing into PHPUnit to unify method testing and query generation testing

1.2.3 - released 2012-11-28

  • Fix issue #78 - remove use of PHP 5.3 static call

1.2.2 - released 2012-11-15

  • Fix bug where input parameters were sent as part-indexed, part associative

1.2.1 - released 2012-11-15

  • Fix minor bug caused by IdiormStringException not extending Exception

1.2.0 - released 2012-11-14

  • 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 and select_many_expr - closing issues #49 and #69
  • Add support for MIN, AVG, MAX and SUM - 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]

1.1.1 - released 2011-01-30

  • Fix bug in quoting column wildcard. j4mie/paris#12
  • Small documentation improvements

1.1.0 - released 2011-01-24

  • Add is_dirty method
  • Add basic query caching
  • Add distinct method
  • Add group_by method

1.0.0 - released 2010-12-01

  • Initial release
去到頂部