PHPackages                             mevdschee/pathpdo - 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. mevdschee/pathpdo

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

mevdschee/pathpdo
=================

JSON interface to a PDO connected SQL database.

11PHPCI failing

Since Mar 16Pushed 2mo agoCompare

[ Source](https://github.com/mevdschee/pathpdo)[ Packagist](https://packagist.org/packages/mevdschee/pathpdo)[ RSS](/packages/mevdschee-pathpdo/feed)WikiDiscussions main Synced 5d ago

READMEChangelogDependenciesVersions (2)Used By (0)

pathpdo
=======

[](#pathpdo)

A PHP path engine library for PDO. Allows to query the database using PathQL (see: [PathQL.org](https://pathql.org/)).

### Requirements

[](#requirements)

- PHP 8 with JSON
- PDO drivers

Metadata Configuration
----------------------

[](#metadata-configuration)

By default, PathPDO queries the database schema at runtime to determine foreign key relationships for automatic path inference. For better performance, you can cache this metadata in a file.

### Setting a Metadata File

[](#setting-a-metadata-file)

```
use Tqdev\PdoJson\Schema;

// Use a metadata file instead of querying the database
Schema::setMetadataFile('pathpdo.json');

// Or use PHP array format
Schema::setMetadataFile('pathpdo.php');

// Switch back to database-based metadata
Schema::setMetadataFile(null);
```

### Exporting Metadata

[](#exporting-metadata)

To create a metadata file from your current database:

```
$db = PathPdo::create($username, $password, $database);
$schema = new Schema();

// Export as JSON (default)
$schema->exportMetadata($db, 'pathpdo.json');

// Export as PHP array
$schema->exportMetadata($db, 'pathpdo.php', 'php');
```

### Custom Metadata Cache

[](#custom-metadata-cache)

For advanced use cases, you can implement your own metadata caching (e.g., Redis, Memcached, database) using the `setMetaData()` and `getMetaData()`methods:

```
use Tqdev\PdoJson\Schema;

// Example: Caching metadata in Redis
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);

// Check if metadata is cached
if ($redis->exists('pathpdo:metadata')) {
    // Load from cache
    $json = $redis->get('pathpdo:metadata');
    Schema::setMetaData($json);
} else {
    // Generate from database
    $db = PathPdo::create($username, $password, $database);
    $schema = new Schema();
    $json = $schema->getMetaData($db);

    // Store in cache
    $redis->set('pathpdo:metadata', $json, 3600); // Cache for 1 hour
    Schema::setMetaData($json);
}

// Now PathPDO will use the cached metadata
```

The `setMetaData()` method accepts a JSON string in the same format as metadata files, while `getMetaData()` returns the current metadata as JSON (from cache, file, or database).

### Metadata File Format (JSON)

[](#metadata-file-format-json)

```
{
    "foreign_keys": [
        {
            "from_table": "comments",
            "from_column": "post_id",
            "to_table": "posts",
            "to_column": "id"
        },
        {
            "from_table": "posts",
            "from_column": "category_id",
            "to_table": "categories",
            "to_column": "id"
        }
    ]
}
```

### Benefits

[](#benefits)

- **Performance**: Eliminates schema queries on every request
- **Portability**: Works even without direct access to information\_schema
- **Version Control**: Track schema changes in your repository
- **Consistency**: Ensures the same schema interpretation across environments

Using PathQL
------------

[](#using-pathql)

### Basic Query

[](#basic-query)

The `pathQuery()` method executes SQL queries and returns results in a hierarchical structure based on table relationships:

```
$db = PathPdo::create($username, $password, $database);

// Simple query
$results = $db->pathQuery('SELECT `id`,`name` FROM `users`');
// Returns: [{"id": 1, "name": "John"}, {"id": 2, "name": "Jane"}]

// With parameters (named/ordered)
$results = $db->pathQuery('SELECT * FROM users WHERE id = :id', ['id' => 1]);
$results = $db->pathQuery('SELECT * FROM users WHERE id = ?', [1]);
```

### Specifying Paths with Array Parameter

[](#specifying-paths-with-array-parameter)

You can specify paths for tables or aliases using the third parameter:

```
// Map table aliases to their paths
$results = $db->pathQuery(
    'SELECT p.id, c.id, c.content
     FROM posts p
     LEFT JOIN comments c ON c.post_id = p.id
     WHERE p.id = :id',
    ['id' => 1],  // Named query parameters
    [    // Path mapping
        'p' => '$',
        'c' => '$.comments[]'
    ]
);
// Returns: {"id": 1, "comments": [{"id": 1, "content": "..."}, {"id": 2, "content": "..."}]}
```

### Path Syntax

[](#path-syntax)

- `$` - Root object
- `$.property` - Nested property
- `$[]` - Array of objects
- `$.property[]` - Nested array
- `$.parent.child[]` - Deeply nested array

### Examples

[](#examples)

```
// Single object result
$stats = $db->pathQuery(
    'SELECT COUNT(*) as posts FROM posts',
    [],
    ['posts' => '$.statistics']
);
// Returns: {"statistics": {"posts": 12}}

// Nested arrays
$results = $db->pathQuery(
    'SELECT u.name, p.title, c.content
     FROM users u
     LEFT JOIN posts p ON p.user_id = u.id
     LEFT JOIN comments c ON c.post_id = p.id
     WHERE u.id = ?',
    [1], // Ordered query parameters
    [
        'u' => '$',
        'p' => '$.posts[]',
        'c' => '$.posts[].comments[]'
    ]
);
// Returns: {
//   "name": "John",
//   "posts": [
//     {"title": "First Post", "comments": [{"content": "Nice!"}, ...]},
//     ...
//   ]
// }
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance58

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![mevdschee](https://avatars.githubusercontent.com/u/1288217?v=4)](https://github.com/mevdschee "mevdschee (116 commits)")

### Embed Badge

![Health badge](/badges/mevdschee-pathpdo/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

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

The Illuminate Database package.

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

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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