PHPackages                             morris/lessql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. morris/lessql

ActiveLibrary[Database &amp; ORM](/categories/database)

morris/lessql
=============

LessQL: A lightweight and performant PHP ORM alternative

1.0.0(6y ago)405140.0k↑19.6%40[10 issues](https://github.com/morris/lessql/issues)[1 PRs](https://github.com/morris/lessql/pulls)3MITPHPPHP &gt;=5.3.4CI failing

Since Dec 18Pushed 3y ago22 watchersCompare

[ Source](https://github.com/morris/lessql)[ Packagist](https://packagist.org/packages/morris/lessql)[ Docs](https://github.com/morris/lessql)[ RSS](/packages/morris-lessql/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (3)

LessQL
======

[](#lessql)

[![Build Status](https://camo.githubusercontent.com/6fbdfde092659a8f8a6ee6dafaec68e860f4cdfc4d68795ec5b468f01b1672ad/68747470733a2f2f7472617669732d63692e6f72672f6d6f727269732f6c657373716c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/morris/lessql)[![Test Coverage](https://camo.githubusercontent.com/bf5f2bea8f56481b39112ba575a259634b7cb9319a75d9e1f751b809c9da8fe6/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6d6f727269732f6c657373716c2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/morris/lessql/coverage)

LessQL is a lightweight and performant alternative to Object-Relational Mapping for PHP.

**[Guide](doc/guide.md) | [Conventions](doc/conventions.md) | [API Reference](doc/api.md) | [About](doc/about.md)**

*If you are looking for an SQL-based approach superior to raw PDO, check out [DOP](https://github.com/morris/dop) as an alternative.*

Installation
------------

[](#installation)

Install LessQL via composer: `composer require morris/lessql`. LessQL requires PHP &gt;= 5.6 and PDO.

Usage
-----

[](#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
--------

[](#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](https://www.notorm.com/), it was written from scratch to provide a clean API and simplified concepts.

Contributors
------------

[](#contributors)

- [jayaddison](https://github.com/jayaddison)
- [f0ma](https://github.com/f0ma)

Thanks!

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity52

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 87.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~164 days

Recently: every ~350 days

Total

13

Last Release

2200d ago

Major Versions

v0.4.1 → 1.0.02020-05-09

PHP version history (2 changes)v0.1-betaPHP &gt;=5.3.0

v0.3.4PHP &gt;=5.3.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/5a8abc912c6edf7bd2c37c29dae5cf7d775cbd6df90601e262440e21448582af?d=identicon)[morris](/maintainers/morris)

---

Top Contributors

[![morris](https://avatars.githubusercontent.com/u/32837?v=4)](https://github.com/morris "morris (106 commits)")[![CQD](https://avatars.githubusercontent.com/u/94944?v=4)](https://github.com/CQD "CQD (5 commits)")[![palicao](https://avatars.githubusercontent.com/u/659961?v=4)](https://github.com/palicao "palicao (3 commits)")[![luiz-brandao](https://avatars.githubusercontent.com/u/704231?v=4)](https://github.com/luiz-brandao "luiz-brandao (1 commits)")[![metala](https://avatars.githubusercontent.com/u/120106?v=4)](https://github.com/metala "metala (1 commits)")[![nataliawinter](https://avatars.githubusercontent.com/u/9592064?v=4)](https://github.com/nataliawinter "nataliawinter (1 commits)")[![cos800](https://avatars.githubusercontent.com/u/635184?v=4)](https://github.com/cos800 "cos800 (1 commits)")[![vikkio88](https://avatars.githubusercontent.com/u/248805?v=4)](https://github.com/vikkio88 "vikkio88 (1 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![jayaddison](https://avatars.githubusercontent.com/u/55152140?v=4)](https://github.com/jayaddison "jayaddison (1 commits)")

---

Tags

ormphpsqldatabaseormsqlpdonotorm

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/morris-lessql/health.svg)

```
[![Health](https://phpackages.com/badges/morris-lessql/health.svg)](https://phpackages.com/packages/morris-lessql)
```

###  Alternatives

[ramadan/easy-model

A Laravel package for enjoyably managing database queries.

101.6k](/packages/ramadan-easy-model)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
