Convert Figma logo to code with AI

j4mie logoidiorm

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.

2,007
369
2,007
5

Top Related Projects

9,433

Doctrine Database Abstraction Layer

4,825

The lightweight PHP database framework to accelerate the development.

[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Quick Overview

Idiorm is a lightweight, minimalist Object-Relational Mapping (ORM) library for PHP. It provides a simple yet powerful interface for database interactions, supporting multiple database systems while maintaining a small footprint and easy-to-use API.

Pros

  • Lightweight and easy to learn, with minimal setup required
  • Supports multiple database systems (MySQL, SQLite, PostgreSQL)
  • Chainable method calls for intuitive query building
  • No complex configuration or schema definitions needed

Cons

  • Limited advanced features compared to more comprehensive ORMs
  • No built-in support for migrations or complex relationships
  • May not be suitable for large-scale, complex applications
  • Less active development and community support compared to more popular ORMs

Code Examples

  1. Basic query to fetch all records from a table:
$users = ORM::for_table('user')->find_many();
foreach ($users as $user) {
    echo $user->name;
}
  1. Inserting a new record:
$user = ORM::for_table('user')->create();
$user->name = 'John Doe';
$user->email = 'john@example.com';
$user->save();
  1. Updating an existing record:
$user = ORM::for_table('user')->where('id', 1)->find_one();
$user->name = 'Jane Doe';
$user->save();
  1. Complex query with joins and conditions:
$orders = ORM::for_table('order')
    ->select('order.*')
    ->select('customer.name', 'customer_name')
    ->join('customer', array('order.customer_id', '=', 'customer.id'))
    ->where('order.status', 'completed')
    ->where_gt('order.total', 100)
    ->order_by_desc('order.created_at')
    ->find_many();

Getting Started

  1. Install Idiorm using Composer:
composer require j4mie/idiorm
  1. Include Composer's autoloader and configure the database connection:
require 'vendor/autoload.php';

ORM::configure('mysql:host=localhost;dbname=your_database');
ORM::configure('username', 'your_username');
ORM::configure('password', 'your_password');
  1. Start using Idiorm in your PHP code:
$user = ORM::for_table('user')->find_one(1);
echo $user->name;

Competitor Comparisons

9,433

Doctrine Database Abstraction Layer

Pros of DBAL

  • More comprehensive and feature-rich database abstraction layer
  • Supports a wider range of database systems and advanced SQL features
  • Active development and maintenance by a large community

Cons of DBAL

  • Steeper learning curve due to its complexity and extensive features
  • Heavier footprint and potentially slower performance for simple use cases

Code Comparison

Idiorm:

ORM::for_table('users')
    ->where('name', 'John')
    ->find_one();

DBAL:

$queryBuilder = $conn->createQueryBuilder();
$result = $queryBuilder
    ->select('*')
    ->from('users')
    ->where('name = :name')
    ->setParameter('name', 'John')
    ->executeQuery()
    ->fetchAssociative();

Summary

DBAL offers a more powerful and flexible solution for database interactions, supporting complex queries and multiple database systems. However, this comes at the cost of increased complexity and a steeper learning curve. Idiorm, on the other hand, provides a simpler and more lightweight approach, which may be sufficient for smaller projects or those with basic database needs. The choice between the two depends on the specific requirements of your project, the level of database abstraction needed, and the desired balance between simplicity and feature richness.

4,825

The lightweight PHP database framework to accelerate the development.

Pros of Medoo

  • Supports multiple database types (MySQL, MSSQL, SQLite, etc.)
  • Offers more advanced features like JOIN operations and subqueries
  • Provides better security with automatic parameter binding

Cons of Medoo

  • Slightly steeper learning curve due to more complex API
  • May be considered "heavier" for simple projects
  • Less focus on raw SQL queries compared to Idiorm

Code Comparison

Medoo:

$data = $database->select("users", [
    "name",
    "email"
], [
    "age[>]" => 18
]);

Idiorm:

$users = ORM::for_table('users')
    ->select(['name', 'email'])
    ->where_gt('age', 18)
    ->find_many();

Both Medoo and Idiorm are PHP database abstraction libraries, but they differ in their approach and feature set. Medoo offers more advanced functionality and supports multiple database types, making it suitable for complex projects. However, this comes at the cost of a slightly steeper learning curve. Idiorm, on the other hand, focuses on simplicity and raw SQL queries, which can be advantageous for smaller projects or developers who prefer more direct database interaction. The code comparison shows that both libraries offer intuitive ways to perform database operations, with Medoo using array-based syntax and Idiorm using method chaining.

[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Pros of illuminate/database

  • More feature-rich with advanced querying capabilities and relationships
  • Part of the Laravel ecosystem, offering seamless integration with other Laravel components
  • Active development and large community support

Cons of illuminate/database

  • Steeper learning curve due to more complex API and features
  • Heavier footprint, potentially overkill for simple projects
  • Requires more setup and configuration compared to Idiorm

Code Comparison

Idiorm:

$user = ORM::for_table('users')->find_one($id);
$user->name = 'John';
$user->save();

illuminate/database:

$user = DB::table('users')->find($id);
$user->update(['name' => 'John']);

Summary

Idiorm is a lightweight ORM suitable for small projects, offering simplicity and ease of use. illuminate/database, part of the Laravel framework, provides a more robust solution with advanced features, better suited for larger applications. While Idiorm excels in simplicity, illuminate/database offers more power and flexibility at the cost of increased complexity.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Idiorm

idiorm master branch Latest Stable Version Total Downloads Code Climate

https://j4mie.github.io/idiormandparis/


In maintenance only mode

Idiorm and Paris are now considered to be feature complete as of version 1.5.0. Whilst they will continue to be maintained with bug fixes there will be no further new features added from this point on. This means that if a pull request makes breaking changes to the API or requires anything other than a patch version bump of the library then it will not be merged.

Please do not submit feature requests or API breaking changes as they will be closed without ceremony.

Should I use Idiorm/Paris?

If you're starting a new project

It is not recommended that you use either Idiorm or Paris in new projects.

I recommend that you use the Eloquent database library from Laravel as Taylor based it on Idiorm when he wrote it. This means that many of the same ideas are present there, but it is more actively maintained and has a more modern code style.

If you have existing projects based on Idiorm or Paris

You can continue to use both projects as they will continue to receive security patches and bug fixes. It is important to note that future versions of PHP may not be supported if changes they require would break backwards compatibility.

At this point you can either use another database library such as Eloquent from Laravel (see If you're starting a new project above) or you could decide to fork Idiorm and/or Paris to patch them with your own modifications.

But, why?

For further information on the state of this project please see https://github.com/j4mie/idiorm/issues/360


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.8 - released 2022-07-18

1.5.7 - released 2020-04-29

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