Download the PHP package visorcraft/mongreldb-php without Composer
On this page you can find all versions of the php package visorcraft/mongreldb-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download visorcraft/mongreldb-php
More information about visorcraft/mongreldb-php
Files in visorcraft/mongreldb-php
Package mongreldb-php
Short Description Pure PHP client for MongrelDB - a fast embedded+server database with SQL, vector search, full-text search, and AI-native retrieval.
License MIT OR Apache-2.0
Homepage https://github.com/visorcraft/MongrelDB-PHP
Informations about the package mongreldb-php
MongrelDB PHP Client
Pure PHP client for MongrelDB - embedded+server database with SQL, vector search, full-text search, and AI-native retrieval.
Package
| Surface | Package | Install |
|---|---|---|
| PHP client | visorcraft/mongreldb-php |
composer require visorcraft/mongreldb-php |
Requirements
- PHP 8.4 or newer (PHP 8.5 supported with opt-in performance features)
- ext-curl (default HTTP transport) and ext-json (always required)
- A running
mongreldb-serverdaemon
What It Provides
- Typed CRUD over the Kit transaction endpoint:
put,upsert(insert-or-update on PK conflict),deleteby row id or primary key, with idempotency keys for safe retries. - Fluent query builder that pushes conditions down to the engine's specialized indexes for sub-millisecond lookups: bitmap equality/IN, learned-range, null checks, FM-index full-text search, HNSW vector similarity (
ann), and sparse vector match. - Idempotent batch transactions - all operations staged locally and committed atomically, with the engine enforcing unique, foreign key, and check constraints at commit time. Idempotency keys return the original response on duplicate commits, even after a crash.
- Full SQL access through the DataFusion-backed
/sqlendpoint: recursive CTEs, window functions,CREATE TABLE AS SELECT, materialized views, multi-statement execution, and themongreldb_fts_rankrelevance-scoring UDF. - Schema management: typed table creation, full schema catalog, and per-table descriptors.
- User/role/credentials management: Argon2id-hashed catalog users, roles,
GRANT/REVOKEtable-level permissions, daemon HTTP Basic + Bearer auth, and a client-side permission validator that blocks SQL injection in grant strings. - Stored procedures: install, list, drop, and call with typed arguments.
- Maintenance: compaction (all tables or per-table).
- Pluggable HTTP transport: cURL by default (with keep-alive connection pooling), a stream-based fallback, and a
TransportInterfacefor custom adapters (e.g. a Guzzle/PSR-18 bridge). - Typed exception hierarchy:
AuthException(401/403),NotFoundException(404),ConstraintException(409, with error code + op index),ConnectionException(network), andQueryException(everything else). - Robust JSON handling: malformed UTF-8 is substituted rather than rejecting the whole request; INF/NAN and recursive structures raise a clear
QueryExceptioninstead of corrupting data.
Examples
Runnable, commented examples live in examples/:
- Basic CRUD - connect, create a table, insert, query, count.
- Authentication - users, roles, table-level permissions, credential verification.
- Transactions - batch commits, idempotency keys, constraint handling.
- SQL queries - recursive CTEs, window functions, advanced SQL.
Quick Example
Authentication
Batch transactions
Operations are staged locally and committed atomically. The engine enforces unique, foreign key, and check constraints at commit time.
Native query builder
Conditions push down to the engine's specialized indexes. The builder accepts
friendly aliases that are translated to the server's on-wire keys: column
(-> column_id), min/max (-> lo/hi). The canonical keys are also
accepted directly.
SQL
ANN index backends
The engine's ann index is swappable across three backends - hnsw (the default), diskann, and ivf - selected with the algorithm option. Quantization is independently configurable: dense, binary_sign, or product (product quantization, with num_subvectors, bits_per_subvector, pq_training_samples, pq_seed, and pq_rerank_factor). These are ordinary DDL strings run through sql, so no client changes are needed.
User & role management
Performance: persistent cURL sharing (PHP 8.5+)
By default the client pools keep-alive connections within a single PHP request. On PHP 8.5+, opt in to sharing DNS resolution, TLS sessions, and the connection pool across requests (e.g. between PHP-FPM invocations) for further latency reductions on the same daemon host:
Off by default; silently degrades to per-request pooling on PHP 8.4.
CURL_LOCK_DATA_COOKIE is rejected - it would leak cookies across requests and
is unsafe for a stateless database client.
Custom HTTP transport
Error handling
Enum-domain failures and regex/check-constraint failures are reported by the
server as ConstraintException with $e->errorCode === 'CHECK_VIOLATION'.
API reference
Database class
| Method | Description |
|---|---|
health(): bool |
Check daemon health |
historyRetentionEpochs(): int |
Current history-retention window (epochs) |
earliestRetainedEpoch(): int |
Oldest epoch still queryable with AS OF EPOCH |
setHistoryRetentionEpochs(int $epochs): array |
Set the history-retention window; requires admin |
tables(): array |
List table names |
createTable(string $name, array $columns, array $constraints = [], array $indexes = []): int |
Create a table with all index definitions |
dropTable(string $name): void |
Drop a table |
count(string $table): int |
Row count |
put(string $table, array $cells, ?string $idempotencyKey): array |
Insert a row |
upsert(string $table, array $cells, ?array $updateCells, ?string $idempotencyKey): array |
Upsert a row |
delete(string $table, int $rowId): void |
Delete by row ID |
deleteByPk(string $table, mixed $pk): void |
Delete by primary key |
query(string $table): QueryBuilder |
Start a native query |
sql(string $sql): array |
Execute SQL |
schema(): array |
Full schema catalog |
schemaFor(string $table): array |
Single table schema |
createUser(string $user, string $pw): void |
Create a user |
dropUser(string $user): void |
Drop a user |
alterPassword(string $user, string $pw): void |
Change a password |
verifyUser(string $user, string $pw): bool |
Verify credentials |
setUserAdmin(string $user, bool $isAdmin): void |
Grant/revoke admin |
users(): array |
List users (row objects with a username key) |
createRole(string $name): void |
Create a role |
dropRole(string $name): void |
Drop a role |
roles(): array |
List roles (row objects with a role key) |
grantRole(string $user, string $role): void |
Grant role to user |
revokeRole(string $user, string $role): void |
Revoke role from user |
grantPermission(string $role, string $perm): void |
Grant permission |
revokePermission(string $role, string $perm): void |
Revoke permission |
procedures(): array |
List procedures |
procedure(string $name): array |
Get a procedure |
createProcedure(array $proc): array |
Install/replace a procedure |
dropProcedure(string $name): void |
Drop a procedure |
callProcedure(string $name, array $args): mixed |
Call a procedure |
compact(): array |
Compact all tables |
compactTable(string $name): array |
Compact one table |
beginTransaction(): Transaction |
Start a batch |
createTable() forwards each column array unchanged in the columns payload.
Column specs accept the standard keys (id, name, ty, primary_key,
nullable, auto_increment, encrypted, encrypted_indexable) plus:
| Column key | Description |
|---|---|
enum_variants |
String variants for ty => 'enum'; required and non-empty for enum columns |
default_value |
Static JSON scalar default filled in when a row omits the column. Explicit null stays a static null; a missing key means no default. Literal strings "now" or "uuid" here are static, not dynamic. |
default_expr |
Dynamic default expression; only "now" and "uuid" are accepted by the server. Use this instead of default_value for dynamic defaults. |
All supported static-default shapes pass through with their original JSON types:
Table-level check constraints are passed as the optional third argument under
constraints.checks:
QueryBuilder class
| Method | Description |
|---|---|
where(string $type, array $params): static |
Add a native condition |
projection(array $columnIds): static |
Set column projection |
limit(int $limit): static |
Set row limit |
offset(int $offset): static |
Skip matching rows before the limit |
build(): array |
Build the request payload |
execute(): array |
Run the query |
Transaction class
| Method | Description |
|---|---|
put(string $table, array $cells): static |
Stage an insert |
upsert(string $table, array $cells, ?array $updateCells): static |
Stage an upsert |
delete(string $table, int $rowId): static |
Stage a delete |
deleteByPk(string $table, mixed $pk): static |
Stage a delete by PK |
commit(?string $idempotencyKey): array |
Commit atomically |
rollback(): void |
Discard all operations |
count(): int |
Number of staged operations |
Building and testing
The project uses PHPUnit 12 and has two testsuites:
unit— fast offline conformance tests using a mock HTTP transport.live— integration tests against a realmongreldb-server. They skip automatically whenMONGRELDB_URLis unset or unreachable.
The unit suite exercises the HTTP contract, SQL-injection hardening, JSON edge cases (INF/NAN, malformed UTF-8, recursion), transport behavior, transaction state machines, and the optional persistent-sharing feature.
Contributing
Contributions are welcome. Please:
- Open an issue first for non-trivial changes.
- Add focused tests near your change - the suite must stay green.
- Keep PHP 8.4 as the minimum supported version (PHP 8.5-only features must
degrade gracefully, detected at runtime via
function_exists/defined). - Match the existing style: strict types,
declare(strict_types=1), tabs,readonlyproperties where applicable, and#[\Override]on overridden methods.
History retention
History retention controls how far back AS OF EPOCH time-travel queries can
read. Use these methods with mongreldb-server 0.48.0+:
Related tools
- Mongrel — Commercial multi-system workbench with native MongrelDB support.
- MongrelDB Viewer — Free, open-source MongrelDB GUI and MCP server.
License
Dual-licensed under the MIT License or the Apache License, Version 2.0, at your option. See Apache-2.0 for the full text.
SPDX-License-Identifier: MIT OR Apache-2.0
All versions of mongreldb-php with dependencies
ext-curl Version *
ext-json Version *