PHPackages                             kynx/gqlite - 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. kynx/gqlite

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

kynx/gqlite
===========

Talk to embedded GraphQLite database

0.1.4(1mo ago)01MITPHPPHP ^8.4.0 || ^8.5.0CI passing

Since Feb 8Pushed 1mo agoCompare

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

READMEChangelog (5)Dependencies (6)Versions (8)Used By (0)

kynx/gqlite
===========

[](#kynxgqlite)

[![Continuous Integration](https://github.com/kynx/graphqlite/actions/workflows/continuous-integration.yml/badge.svg?branch=main)](https://github.com/kynx/graphqlite/actions/workflows/continuous-integration.yml)

Talk to an embedded graph database with PHP.

> This project is in the early stages of development! Feel free to play, but bear in mind that there are a lot of missing features!

This package provides a driver for the [SQLite](https://www.sqlite.org/)-based graph database [GraphQLite](https://github.com/colliery-io/graphqlite). If you came here looking for something to handle the [GraphQL protocol](https://graphql.org), you're in the wrong place: try [Packagist](https://packagist.org/?query=graphql)!

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

[](#installation)

```
composer require kynx/gqlite
```

GraphQLite provides an SQLLite extension that must be available locally. There are a few ways to install it.

### Via a Package Manager

[](#via-a-package-manager)

```
brew install graphqlite       # macOS/Linux (Homebrew)
pip install graphqlite        # Python
```

Make a note of the path it's installed `graphqlite.(dylib|so|dll)` to - you will need this later.

### Download a Release Binary

[](#download-a-release-binary)

Binary builds are available from the GraphQLite GitHub repository: . Download the `dylib`, `so` or `dll` file suitable for your platform.

### Build from Source

[](#build-from-source)

See the [From Source](https://colliery-io.github.io/graphqlite/latest/how-to/installation.html#from-source) instructions in the GraphQLite documentation.

Usage
-----

[](#usage)

This library provides convenience methods to make managing the nodes and edges of your graph simple and type-safe. It also allows you to query the GraphQLite database using the [Cypher](https://neo4j.com/docs/cypher-manual/current/introduction/) language:

```
use Kynx\GqLite\Graph;
use Kynx\GqLite\ValueObject\Edge;
use Kynx\GqLite\ValueObject\Node;

// replace with path to GraphQLite extension installed above
$extensionPath = getenv('GRAPHQLITE_EXTENSION_PATH');

// Get a connection to an in-memory graph database
$graph = Graph::connect($extensionPath, ':memory:');

// Add some nodes and edges
$graph->nodes->upsert(new Node("alice", ["name" => "Alice", "age" => 30], "Person"));
$graph->nodes->upsert(new Node("bob", ["name" => "Bob", "age" => 25], "Person"));
$graph->edges->upsert(new Edge("alice", "bob", "KNOWS", ["since" => 2020]));

// Query with Cypher
$results = $graph->query('MATCH (a:Person)-[:KNOWS]->(b) RETURN a.name AS a, b.name AS b');
foreach ($results as $row) {
    echo $row['a'] . ' knows ' . $row['b'] . "\n";
}

// outputs:
// Alice knows Bob
```

To learn more about Cypher, see the [Neo4J manual](https://neo4j.com/docs/cypher-manual/current/introduction/). GraphQLite supports a subset of the language.

To learn more about GraphQLite, see the excellent [documentation](https://colliery-io.github.io/graphqlite/latest/introduction.html).

The `Graph` object
------------------

[](#the-graph-object)

The `Graph` object has a number entrypoints:

EntrypointDescription`Graph::nodes`CRUD operations on nodes`Graph::edges`CRUD operations on edges`Graph::centrality`Algorithms for ranking node importance`Graph::traversals`Breadth and depth-first traversals`Graph::query()`Execute raw Cypher queries### Nodes and Edges

[](#nodes-and-edges)

The CRUD operations consume and return `Node` and `Edge` value objects.

A `Node` has an ID, an associative array of properties and one or more labels. Properties are where you store data associated with the node. Labels are like tags, and are used to query the database for specific nodes.

An `Edge` connects two nodes. It has a source ID, a target ID, a relation type and an associative array of properties. As with node labels, the relation type is used query the database for specific types of relations.

### Queries

[](#queries)

The `Graph::query()` method returns a `Result` object. Iterating that will give you an associate array. For example, `MATCH (n {id: 'alice'}) RETURN n` will give you a structure like:

```
{
  "n": {
    "id": 1,
    "labels": ["Person"],
    "properties": {
      "id": "alice",
      "name": "Alice",
      "age": 30
    }
  }
}
```

Note there are **two** IDs! The first is the identifier generated by SQLite for the node, the second is the one you assigned.

For Cypher queries, only the second is of any use. To avoid confusion we recommend mapping the results to `Node` and `Edge` objects. The [Usage](#usage) example above could be re-written:

```
$results = $graph->query('MATCH (a:Person)-[:KNOWS]->(b) RETURN a, b');
foreach ($results as $row) {
    $a = Node::fromArray($row['a']);
    $b = Node::fromArray($row['b']);

    echo $a->id . ' knows ' . $b->id . "\n";
}

// Outputs:
// alice knows bob
```

See [static-analysis.php](./examples/static-analysis.php) in the `examples` directory for the full code, with type-safety thrown in.

#### Parameters

[](#parameters)

Just as with SQL, do **not** pass user input directly into the query. Instead use placeholders and parameters to ensure they are sanitized. Cypher uses the dollar sign (`$`) to denote a placeholder:

```
$results = $graph->query(
    'MATCH (a {name: $name})-[:KNOWS]->(b) RETURN a, b',
    ['name' => $_GET['name']]
);
```

**Make sure your query is single-quoted so PHP variables are not expanded!**

### Centrality

[](#centrality)

Algorithms for ranking node importance.

MethodDescription`Graph::centrality::betweenness()`Ranks nodes based on how often a node lies on shortest path between nodes.`Graph::centrality::closeness()`Ranks nodes based on how close a node is to all other nodes`Graph::centrality::degree()`Returns the in-degree, out-degree, and total degree for each node`Graph::centrality::eigenvector()`Ranks nodes based on connections to other important nodes`Graph::centrality::pageRank()`Ranks nodes based on [PageRank](https://en.wikipedia.org/wiki/PageRank) algorithm`Graph::centrality::topPageRank()`As above, but only returns the first `n` resultsSupported Versions
------------------

[](#supported-versions)

This library aims to support the latest version of [GraphQLite](https://github.com/colliery-io/graphqlite). Older versions may work, but we do not test against them. Currently GraphQLite is pre-1.0.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance89

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 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 ~10 days

Total

5

Last Release

54d ago

### Community

Maintainers

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

---

Top Contributors

[![kynx](https://avatars.githubusercontent.com/u/1320145?v=4)](https://github.com/kynx "kynx (13 commits)")

---

Tags

databasesqlitegraphGraphQLitegraph database

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kynx-gqlite/health.svg)

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

###  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)[catfan/medoo

The lightweight PHP database framework to accelerate development

4.9k1.5M194](/packages/catfan-medoo)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M36](/packages/scienta-doctrine-json-functions)[nette/database

💾 Nette Database: layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.

5656.7M234](/packages/nette-database)[usmanhalalit/pixie

A lightweight, expressive, framework agnostic query builder for PHP.

6872.2M15](/packages/usmanhalalit-pixie)[dibi/dibi

Dibi is Database Abstraction Library for PHP

5013.8M120](/packages/dibi-dibi)

PHPackages © 2026

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