{"id":13684453,"url":"https://github.com/itosho/easy-query","last_synced_at":"2025-04-03T05:30:40.377Z","repository":{"id":56994375,"uuid":"102205772","full_name":"itosho/easy-query","owner":"itosho","description":"CakePHP behavior plugin for easily generating some complicated queries like (bulk) insert/upsert etc.","archived":false,"fork":false,"pushed_at":"2024-03-07T14:28:59.000Z","size":126,"stargazers_count":26,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T11:05:48.466Z","etag":null,"topics":["behavior","bulk-insert","cakephp","cakephp-orm","cakephp-plugin","cakephp5","composer-package","php8","upsert"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itosho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-02T15:28:21.000Z","updated_at":"2024-04-25T17:02:33.000Z","dependencies_parsed_at":"2024-06-21T17:26:10.062Z","dependency_job_id":null,"html_url":"https://github.com/itosho/easy-query","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itosho%2Feasy-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itosho%2Feasy-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itosho%2Feasy-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itosho%2Feasy-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itosho","download_url":"https://codeload.github.com/itosho/easy-query/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246944377,"owners_count":20858773,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["behavior","bulk-insert","cakephp","cakephp-orm","cakephp-plugin","cakephp5","composer-package","php8","upsert"],"created_at":"2024-08-02T14:00:33.716Z","updated_at":"2025-04-03T05:30:40.126Z","avatar_url":"https://github.com/itosho.png","language":"PHP","readme":"# Easy Query\nCakePHP behavior plugin for easily generating some complicated queries like (bulk) insert/upsert etc.\n\n[![codecov](https://codecov.io/gh/itosho/easy-query/branch/master/graph/badge.svg)](https://codecov.io/gh/itosho/easy-query)\n[![Latest Stable Version](https://poser.pugx.org/itosho/easy-query/v/stable)](https://packagist.org/packages/itosho/easy-query)\n[![Total Downloads](https://poser.pugx.org/itosho/easy-query/downloads)](https://packagist.org/packages/itosho/easy-query)\n[![License](https://poser.pugx.org/itosho/easy-query/license)](https://packagist.org/packages/itosho/easy-query)\n\n## Requirements\n- PHP 8.1+\n- CakePHP 5.0+\n- MySQL 8.0+ / MariaDB 10.4+\n\n### Notice\n- For CakePHP4.x, use 3.x tag.\n- For CakePHP3.x, use 1.x tag.\n\n## Installation\n```bash\ncomposer require itosho/easy-query\n```\n\n## Usage\n\n### Upsert\n```php\n$this-\u003eTags = TableRegistry::getTableLocator()-\u003eget('Tags');\n$this-\u003eTags-\u003eaddBehavior('Itosho/EasyQuery.Upsert', [\n    'uniqueColumns' =\u003e ['name'],\n    'updateColumns' =\u003e ['description', 'modified'],\n]);\n\n$data = [\n    'name' =\u003e 'cakephp',\n    'description' =\u003e 'php web framework',\n];\n$entity = $this-\u003eTags-\u003enewEntity($data);\n$this-\u003eTags-\u003eupsert($entity);\n```\n\n### Bulk Upsert\n```php\n$this-\u003eTags = TableRegistry::getTableLocator()-\u003eget('Tags');\n$this-\u003eTags-\u003eaddBehavior('Itosho/EasyQuery.Upsert', [\n    'updateColumns' =\u003e ['description', 'modified'],\n]);\n\n$data = [\n    [\n        'name' =\u003e 'cakephp',\n        'description' =\u003e 'php web framework',\n    ],\n    [\n        'name' =\u003e 'rubyonrails',\n        'description' =\u003e 'ruby web framework',\n    ]\n];\n$entities = $this-\u003eTags-\u003enewEntities($data);\n$this-\u003eTags-\u003ebulkUpsert($entities);\n```\n\n### Bulk Insert\n```php\n$this-\u003eArticles = TableRegistry::getTableLocator()-\u003eget('Articles');\n$this-\u003eArticles-\u003eaddBehavior('Itosho/EasyQuery.Insert');\n\n$data = [\n    [\n        'title' =\u003e 'First Article',\n        'body' =\u003e 'First Article Body',\n        'published' =\u003e '1',\n    ],\n    [\n        'title' =\u003e 'Second Article',\n        'body' =\u003e 'Second Article Body',\n        'published' =\u003e '0',\n    ]\n];\n$entities = $this-\u003eArticles-\u003enewEntities($data);\n$this-\u003eArticles-\u003ebulkInsert($entities);\n```\n\n### Insert Select\nFor inserting a record just once.\n\n#### case1\nSpecify search conditions.\n\n```php\n$this-\u003eArticles = TableRegistry::getTableLocator()-\u003eget('Articles');\n$this-\u003eArticles-\u003eaddBehavior('Itosho/EasyQuery.Insert');\n\n$data = [\n    'title' =\u003e 'New Article?',\n    'body' =\u003e 'New Article Body?',\n];\n$entity = $this-\u003eArticles-\u003enewEntity($data);\n$condition = ['title' =\u003e 'New Article?'];\n\n$this-\u003eArticles-\u003einsertOnce($entities);\n```\n\nGenerated SQL is below.\n\n```sql\nINSERT INTO articles (title, body)\nSELECT 'New Article?', 'New Article Body?' FROM tmp WHERE NOT EXISTS (    \n    SELECT * FROM articles WHERE title = 'New Article?'\n)\n```\n\n#### case2\nAuto set search conditions with a inserting record.\n\n```php\n$this-\u003eArticles = TableRegistry::getTableLocator()-\u003eget('Articles');\n$this-\u003eArticles-\u003eaddBehavior('Itosho/EasyQuery.Insert');\n\n$data = [\n    'title' =\u003e 'New Article',\n    'body' =\u003e 'New Article Body',\n];\n$entity = $this-\u003eArticles-\u003enewEntity($data);\n\n$this-\u003eArticles-\u003einsertOnce($entities);\n```\n\nGenerated SQL is below.\n\n```sql\nINSERT INTO articles (title, body)\nSELECT 'New Article', 'New Article Body' FROM tmp WHERE NOT EXISTS (    \n    SELECT * FROM articles WHERE title = 'New Article' AND body = 'New Article Body'\n)\n```\n\n### Advanced \nNeed to use `Timestamp` behavior, if you want to update `created` and `modified` fields automatically.\nAnd you can change the action manually by using `event` config like this.\n\n```php\n// default value is true\n$this-\u003eArticles-\u003eaddBehavior('Itosho/EasyQuery.Insert', [\n    'event' =\u003e ['beforeSave' =\u003e false],\n]);\n```\n\n## Contributing\nBug reports and pull requests are welcome on GitHub at https://github.com/itosho/easy-query.\n\n## License\nThe plugin is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":["ORM / Database / Datamapping"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitosho%2Feasy-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitosho%2Feasy-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitosho%2Feasy-query/lists"}