PHPackages                             koriym/query-locator - 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. koriym/query-locator

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

koriym/query-locator
====================

Load and manage SQL queries from files

1.5.1(1y ago)10304.4k—9.2%13MITPHPPHP &gt;=7.1.0CI passing

Since Nov 2Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/koriym/Koriym.QueryLocator)[ Packagist](https://packagist.org/packages/koriym/query-locator)[ RSS](/packages/koriym-query-locator/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (13)Used By (3)

Koriym.QueryLocator
===================

[](#koriymquerylocator)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7c0173b177ae4e5ea7a01869af66de7da2577bb20816845bd53a8850f85a97fc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6b6f7269796d2f4b6f7269796d2e51756572794c6f6361746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d706870382e312d737570706f7274)](https://scrutinizer-ci.com/g/koriym/Koriym.QueryLocator/)[![codecov](https://camo.githubusercontent.com/28f8d8415effa4012f109c005c75108f4675ba760394699c83425ecbc8edbafa/68747470733a2f2f636f6465636f762e696f2f67682f6b6f7269796d2f4b6f7269796d2e51756572794c6f6361746f722f67726170682f62616467652e7376673f746f6b656e3d574c5a496c376a63614b)](https://codecov.io/gh/koriym/Koriym.QueryLocator)[![Continuous Integration](https://github.com/koriym/Koriym.QueryLocator/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/koriym/Koriym.QueryLocator/actions/workflows/continuous-integration.yml)

**Koriym.QueryLocator** is a PHP library that helps you manage SQL queries by locating and loading them from the file system. This approach simplifies query management and enhances code readability.

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

[](#installation)

Install the library using Composer:

```
$ composer require koriym/query-locator
```

Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

To use the QueryLocator class, instantiate it with the directory where your SQL files are stored. You can then retrieve queries using keys that correspond to the directory structure.

**SQL Files Directory Structure**

```
└── sql
    └── admin
        └── user.sql

```

**Code Example**

```
use Koriym\QueryLocator\QueryLocator;

// Define the directory where your SQL files are stored
$sqlDir = 'path/to/sql/files';

// Instantiate the QueryLocator
$query = new QueryLocator($sqlDir);

// Retrieve a query
$sql = $query['admin/user']; // This will load the contents of 'admin/user.sql'

// Retrieve a count query
$countSql = $query->getCountQuery('admin/user'); // This will generate 'SELECT COUNT(*) FROM user'
```

Features
--------

[](#features)

- **File-Based Query Management**: Store your SQL queries in separate files for better organization.
- **Simple Query Retrieval**: Use directory-based keys to retrieve queries.
- **Count Query Generation**: Automatically generate count queries.

Benefits
--------

[](#benefits)

- **Improved Readability**: Keep your PHP code clean and readable by moving SQL queries to dedicated files.
- **Easy Maintenance**: Modify your SQL queries without changing the PHP code, just update the SQL files.
- **Structured Organization**: Organize your queries in a directory structure that makes sense for your application.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance54

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~368 days

Recently: every ~760 days

Total

11

Last Release

166d ago

Major Versions

0.1.0 → 1.0.02015-11-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/db4fc75ffc631168d0d7143b6f2c24b1534dfb921212bd851c026c5cbbb1344d?d=identicon)[koriym](/maintainers/koriym)

---

Top Contributors

[![koriym](https://avatars.githubusercontent.com/u/529021?v=4)](https://github.com/koriym "koriym (107 commits)")

---

Tags

sql

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/koriym-query-locator/health.svg)

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

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[doctrine/sql-formatter

a PHP SQL highlighting library

1.9k166.0M85](/packages/doctrine-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[catfan/medoo

The lightweight PHP database framework to accelerate development

4.9k1.5M194](/packages/catfan-medoo)[phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

47950.4M55](/packages/phpmyadmin-sql-parser)

PHPackages © 2026

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