Query Builder
Write chainable model queries while keeping classic DataMapper behaviour intact.
Learn More
A CodeIgniter 3 ORM with chainable queries, eager loading, casting, caching, and streaming helpers
Build your first model and start querying your database with DataMapper's chainable helpers.
Quick Start →Add eager loading, caching, and streaming where they fit your workload.
Explore Features →DataMapper 2.0
DataMapper 2.0 adds focused query, collection, casting, cache, and streaming helpers while preserving the classic CodeIgniter 3 workflow.
$user = new User();
$user->where('active', 1);
$user->where('age >', 18);
$user->order_by('created_at', 'DESC');
$user->limit(10);
$user->get();
// N+1 problem - multiple queries
foreach ($user as $u) {
foreach ($u->post as $post) { // Extra query each iteration!
echo $post->title;
}
}$users = (new User())
->where('active', 1)
->where('age >', 18)
->order_by('created_at', 'DESC')
->limit(10)
->with('post')
->get();
// Related posts are already loaded.
foreach ($users as $user) {
foreach ($user->post as $post) {
echo $post->title;
}
}// Without eager loading: one query for organizations, then one per organization.
$organizations = (new Organization())->get();
foreach ($organizations as $org) {
foreach ($org->installation as $installation) {
echo $installation->name;
}
}
// With eager loading: one query for organizations and one for the related installations.
$organizations = (new Organization())
->with('installation')
->get();
foreach ($organizations as $org) {
foreach ($org->installation as $installation) {
echo $installation->name;
}
}Query count
For one relation, eager loading usually turns 1 + N related queries into two queries. Nested or multiple relations add one query per loaded relation path.
// E-commerce: Get premium customers with recent orders
$customers = (new Customer())
->cache(3600)
->with([
'order' => function($q) {
$q->where('created_at >', date('Y-m-d', strtotime('-30 days')))
->where('status', 'completed')
->order_by('created_at', 'DESC')
->limit(10);
}
])
->where('status', 'premium')
->where('credits >', 100)
->where_not_null('email_verified_at')
->order_by('total_spent', 'DESC')
->get();
// Work with collections
$totalSpent = $customers->sum('total_spent');
$emails = $customers->pluck('email');
$topCustomer = $customers->first();| Feature | DataMapper 2.0 | Laravel | Doctrine ORM |
|---|---|---|---|
| Modern Query Builder | Yes | Yes | DQL |
| Eager Loading | Yes | Yes | Yes |
| Query Caching | Built-in | Manual | Complex |
| Soft Deletes | Trait | Trait | Manual |
| Timestamps | Trait | Trait | Callbacks |
| Collections | Yes | Yes | Arrays |
| Streaming | Yes | Chunk | No |
| CodeIgniter 3 | Perfect | N/A | Complex |
| Learning Curve | Easy | Medium | Steep |
| Setup Time | 5 min | N/A | Hours |
DataMapper ORM is developed and maintained by:
DataMapper ORM was originally created by Phil DeJarnett and Simon Stenhouse, with continued development by Harro Verton through version 1.8.3.
The legacy HTML manual that used to live under
/manual/has been retired. All content now lives in this VitePress site under/guide,/reference, and/examples.
If you previously linked to URLs such as /manual/pages/gettingstarted.html, update them to the equivalent path on this site (for example /guide/getting-started/introduction). When hosting the docs, configure HTTP 301 redirects from the old /manual/* paths to their new locations so bookmarks and search indexes continue to work.
DataMapper ORM powers applications across diverse industries:
Install DataMapper in minutes and start building better CodeIgniter applications.