Query Builder
Chain methods naturally with modern syntax. Write clean, readable queries that feel like Laravel Eloquent.
Learn More
Build faster with modern query syntax, eager loading, and zero configuration
Build your first model and start querying your database with elegant syntax.
Quick Start →Add eager loading, caching, and other advanced features to boost performance.
Explore Features →Modern Syntax
DataMapper 2.0 brings modern PHP patterns to CodeIgniter 3, making your code cleaner and more maintainable.
$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') // Eager load - ONE query!
->get();
// No N+1 problem!
foreach ($users as $user) {
foreach ($user->post as $post) { // Already loaded!
echo $post->title;
}
}// Before: 101 queries (N+1 nightmare)
$organizations = (new Organization())->get();
foreach ($organizations as $org) {
foreach ($org->installation as $installation) {
echo $installation->name;
}
}
// After: 2 queries (98% reduction!)
$organizations = (new Organization())
->with('installation')
->get();
foreach ($organizations as $org) {
foreach ($org->installation as $installation) {
echo $installation->name;
}
}Performance Boost
Eager loading can reduce queries by 95-99% in typical applications with relationships.
// E-commerce: Get premium customers with recent orders
$customers = (new Customer())
->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)
->whereNotNull('email_verified_at')
->order_by('total_spent', 'DESC')
->cache(3600) // Cache for 1 hour
->get();
// Work with collections
$totalSpent = $customers->sum('total_spent');
$emails = $customers->pluck('email');
$topCustomer = $customers->first();| Feature | DataMapper 2.0 | Laravel Eloquent | 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.