PHPackages                             itosho/easy-query - 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. itosho/easy-query

ActiveCakephp-plugin[Database &amp; ORM](/categories/database)

itosho/easy-query
=================

CakePHP behavior plugin for easily generating some complicated queries like (bulk) insert/upsert etc.

v3.0.0(2y ago)2623.2k↓37%3MITPHPPHP &gt;=8.1

Since Oct 8Pushed 2y ago1 watchersCompare

[ Source](https://github.com/itosho/easy-query)[ Packagist](https://packagist.org/packages/itosho/easy-query)[ Docs](https://github.com/itosho/easy-query)[ RSS](/packages/itosho-easy-query/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (5)Versions (11)Used By (0)

Easy Query
==========

[](#easy-query)

CakePHP behavior plugin for easily generating some complicated queries like (bulk) insert/upsert etc.

[![codecov](https://camo.githubusercontent.com/a34770a1cefccbefbc67c5745cfc1bcc37200ae6b20bd6c4d592bc4b811d964b/68747470733a2f2f636f6465636f762e696f2f67682f69746f73686f2f656173792d71756572792f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/itosho/easy-query)[![Latest Stable Version](https://camo.githubusercontent.com/defa6a541908c662447a6108779b295c99c603fd8943c567207c4a95e3021d57/68747470733a2f2f706f7365722e707567782e6f72672f69746f73686f2f656173792d71756572792f762f737461626c65)](https://packagist.org/packages/itosho/easy-query)[![Total Downloads](https://camo.githubusercontent.com/9158ed0a6627306cc9d627d33e05d50109bf26223a22228f4d1e1f9979da8bc1/68747470733a2f2f706f7365722e707567782e6f72672f69746f73686f2f656173792d71756572792f646f776e6c6f616473)](https://packagist.org/packages/itosho/easy-query)[![License](https://camo.githubusercontent.com/6385054637022ba627cacbb44f19e28efe5807159d1280161b2728c7b10fa3d0/68747470733a2f2f706f7365722e707567782e6f72672f69746f73686f2f656173792d71756572792f6c6963656e7365)](https://packagist.org/packages/itosho/easy-query)

Requirements
------------

[](#requirements)

- PHP 8.1+
- CakePHP 5.0+
- MySQL 8.0+ / MariaDB 10.4+

### Notice

[](#notice)

- For CakePHP4.x, use 3.x tag.
- For CakePHP3.x, use 1.x tag.

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

[](#installation)

```
composer require itosho/easy-query
```

Usage
-----

[](#usage)

### Upsert

[](#upsert)

```
$this->Tags = TableRegistry::getTableLocator()->get('Tags');
$this->Tags->addBehavior('Itosho/EasyQuery.Upsert', [
    'uniqueColumns' => ['name'],
    'updateColumns' => ['description', 'modified'],
]);

$data = [
    'name' => 'cakephp',
    'description' => 'php web framework',
];
$entity = $this->Tags->newEntity($data);
$this->Tags->upsert($entity);
```

### Bulk Upsert

[](#bulk-upsert)

```
$this->Tags = TableRegistry::getTableLocator()->get('Tags');
$this->Tags->addBehavior('Itosho/EasyQuery.Upsert', [
    'updateColumns' => ['description', 'modified'],
]);

$data = [
    [
        'name' => 'cakephp',
        'description' => 'php web framework',
    ],
    [
        'name' => 'rubyonrails',
        'description' => 'ruby web framework',
    ]
];
$entities = $this->Tags->newEntities($data);
$this->Tags->bulkUpsert($entities);
```

### Bulk Insert

[](#bulk-insert)

```
$this->Articles = TableRegistry::getTableLocator()->get('Articles');
$this->Articles->addBehavior('Itosho/EasyQuery.Insert');

$data = [
    [
        'title' => 'First Article',
        'body' => 'First Article Body',
        'published' => '1',
    ],
    [
        'title' => 'Second Article',
        'body' => 'Second Article Body',
        'published' => '0',
    ]
];
$entities = $this->Articles->newEntities($data);
$this->Articles->bulkInsert($entities);
```

### Insert Select

[](#insert-select)

For inserting a record just once.

#### case1

[](#case1)

Specify search conditions.

```
$this->Articles = TableRegistry::getTableLocator()->get('Articles');
$this->Articles->addBehavior('Itosho/EasyQuery.Insert');

$data = [
    'title' => 'New Article?',
    'body' => 'New Article Body?',
];
$entity = $this->Articles->newEntity($data);
$condition = ['title' => 'New Article?'];

$this->Articles->insertOnce($entities);
```

Generated SQL is below.

```
INSERT INTO articles (title, body)
SELECT 'New Article?', 'New Article Body?' FROM tmp WHERE NOT EXISTS (
    SELECT * FROM articles WHERE title = 'New Article?'
)
```

#### case2

[](#case2)

Auto set search conditions with a inserting record.

```
$this->Articles = TableRegistry::getTableLocator()->get('Articles');
$this->Articles->addBehavior('Itosho/EasyQuery.Insert');

$data = [
    'title' => 'New Article',
    'body' => 'New Article Body',
];
$entity = $this->Articles->newEntity($data);

$this->Articles->insertOnce($entities);
```

Generated SQL is below.

```
INSERT INTO articles (title, body)
SELECT 'New Article', 'New Article Body' FROM tmp WHERE NOT EXISTS (
    SELECT * FROM articles WHERE title = 'New Article' AND body = 'New Article Body'
)
```

### Advanced

[](#advanced)

Need to use `Timestamp` behavior, if you want to update `created` and `modified` fields automatically. And you can change the action manually by using `event` config like this.

```
// default value is true
$this->Articles->addBehavior('Itosho/EasyQuery.Insert', [
    'event' => ['beforeSave' => false],
]);
```

Contributing
------------

[](#contributing)

Bug reports and pull requests are welcome on GitHub at .

License
-------

[](#license)

The plugin is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 78.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 ~292 days

Recently: every ~396 days

Total

9

Last Release

802d ago

Major Versions

v1.2.2 → v2.0.02020-10-03

v2.0.0 → v3.0.02024-03-07

PHP version history (3 changes)v1.2.2PHP &gt;=7.1.0

v2.0.0PHP &gt;=7.2.0

v3.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/64cafe6055d2af7f785fb5c9bbc060092688268ea21a59d77f26ac52d6e2d496?d=identicon)[itosho](/maintainers/itosho)

---

Top Contributors

[![itosho](https://avatars.githubusercontent.com/u/1996511?v=4)](https://github.com/itosho "itosho (77 commits)")[![arusinowski](https://avatars.githubusercontent.com/u/1587389?v=4)](https://github.com/arusinowski "arusinowski (10 commits)")[![o0h](https://avatars.githubusercontent.com/u/907122?v=4)](https://github.com/o0h "o0h (8 commits)")[![mosaxiv](https://avatars.githubusercontent.com/u/28671296?v=4)](https://github.com/mosaxiv "mosaxiv (2 commits)")[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (1 commits)")

---

Tags

behaviorbulk-insertcakephpcakephp-ormcakephp-plugincakephp5composer-packagephp8upsertplugincakephpBehaviorupsertbulk insertbulk upsertinsert selectinsert once

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/itosho-easy-query/health.svg)

```
[![Health](https://phpackages.com/badges/itosho-easy-query/health.svg)](https://phpackages.com/packages/itosho-easy-query)
```

###  Alternatives

[josegonzalez/cakephp-upload

CakePHP plugin to handle file uploading sans ridiculous automagic

5451.3M9](/packages/josegonzalez-cakephp-upload)[muffin/trash

Adds soft delete support to CakePHP ORM tables.

851.3M11](/packages/muffin-trash)[pgbi/cakephp3-soft-delete

SoftDelete plugin for CakePHP

87291.9k](/packages/pgbi-cakephp3-soft-delete)[dereuromark/cakephp-databaselog

A CakePHP plugin for storing and viewing application logs in the database

44165.0k2](/packages/dereuromark-cakephp-databaselog)[xety/cake3-upload

Cake3 plugin to upload files.

2825.6k1](/packages/xety-cake3-upload)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

845.7k](/packages/tommyknocker-pdo-database-class)

PHPackages © 2026

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