Lessql
LessQL: A lightweight and performant PHP ORM alternative
Install / Use
/learn @morris/LessqlREADME
LessQL
LessQL is a lightweight and performant alternative to Object-Relational Mapping for PHP.
Guide | Conventions | API Reference | About
If you are looking for an SQL-based approach superior to raw PDO, check out DOP as an alternative.
Installation
Install LessQL via composer: composer require morris/lessql.
LessQL requires PHP >= 5.6 and PDO.
Usage
// SCHEMA
// user: id, name
// post: id, title, body, date_published, is_published, user_id
// categorization: category_id, post_id
// category: id, title
// Connection
$pdo = new PDO('sqlite:blog.sqlite3');
$db = new LessQL\Database($pdo);
// Find posts, their authors and categories efficiently:
// Eager loading of references happens automatically.
// This example only needs FOUR queries, one for each table.
$posts = $db->post()
->where('is_published', 1)
->orderBy('date_published', 'DESC');
foreach ($posts as $post) {
$author = $post->user()->fetch();
foreach ($post->categorizationList()->category() as $category) {
// ...
}
}
// Saving complex structures is easy
$row = $db->createRow('post', [
'title' => 'News',
'body' => 'Yay!',
'categorizationList' => [
[
'category' => ['title' => 'New Category']
],
['category' => $existingCategoryRow]
]
]);
// Creates a post, a new category, two new categorizations
// and connects them all correctly.
$row->save();
Features
- Efficient deep finding through intelligent eager loading
- Constant number of queries, no N+1 problems
- Save complex, nested structures with one method call
- Convention over configuration
- Work closely to your database: LessQL is not an ORM
- No glue code required
- Clean, readable source code
- Fully tested with SQLite3, MySQL and PostgreSQL
- MIT license
Inspired mainly by NotORM, it was written from scratch to provide a clean API and simplified concepts.
Contributors
Thanks!
Related Skills
oracle
347.2kBest practices for using the oracle CLI (prompt + file bundling, engines, sessions, and file attachment patterns).
prose
347.2kOpenProse VM skill pack. Activate on any `prose` command, .prose files, or OpenProse mentions; orchestrates multi-agent workflows.
Command Development
108.0kThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
Plugin Structure
108.0kThis skill should be used when the user asks to "create a plugin", "scaffold a plugin", "understand plugin structure", "organize plugin components", "set up plugin.json", "use ${CLAUDE_PLUGIN_ROOT}", "add commands/agents/skills/hooks", "configure auto-discovery", or needs guidance on plugin directory layout, manifest configuration, component organization, file naming conventions, or Claude Code plugin architecture best practices.
