Skip to main content

NoSQL Database Abstraction

One interface for document databases and one for key/value stores, whatever the service behind them. The implementation supports:

Sponsor Build Status Opensource ByJG Install MCP Server GitHub source GitHub license GitHub release

  • MongoDB (document-based)
  • AWS DynamoDB (key/value)
  • S3-Like Storage (key/value)
  • Cloudflare KV (key/value)

Anydataset is an agnostic data source abstraction layer in PHP. See more about Anydataset here.

Why​

MongoDB, DynamoDB, S3 and Cloudflare KV each come with their own SDK and their own way to read, write and list. Storing a file in S3 today and in Cloudflare KV tomorrow means rewriting every call.

Anydataset NoSQL defines two contracts, NoSqlInterface for documents and KeyValueInterface for key/value stores, and picks the service from the connection URI:

$store = Factory::getInstance('s3://key:secret@us-east-1/my-bucket'); // AWS S3
$store = Factory::getInstance('kv://user:token@account/namespace'); // Cloudflare KV
$store = Factory::getInstance('dynamodb://key:secret@host/table'); // DynamoDB

$store->put('invoice-42', $pdf);
$pdf = $store->get('invoice-42');
  • Change the service with the URI, not the code that uses it.
  • Same iterator as the rest of AnyDataset. getIterator() returns the same rows as a database or a file, and document queries use the same IteratorFilter.

Features​

  • Access both document-based and key/value repositories with consistent interfaces
  • NoSQL document-based databases accessed through NoSqlInterface
  • Key/Value stores accessed through KeyValueInterface
  • Unified connection string format based on URIs
  • Type-safe DynamoDB attribute definitions using enums

Connection Based on URI​

The connection string for databases is based on URL.

See below the current implemented drivers:

DatasourceConnection String
MongoDBmongodb://username:password@hostname:port/database
S3s3://accesskey:secretkey@region/bucket?params
Cloudflare KVkv://username:password@accountid/namespaceid
AWS DynamoDBdynamodb://accesskey:secretkey@hostname/tablename?params

Documentation​

NoSQL Drivers​

  • MongoDB - Document-based NoSQL database

Key/Value Drivers​

  • AWS DynamoDB - Key/Value store with type-safe attribute definitions
  • AWS S3 - Object storage as Key/Value store
  • Cloudflare KV - Cloudflare Workers KV storage

Additional Features​

Installation​

Just type:

composer require "byjg/anydataset-nosql"

Running Tests​

docker compose up -d
vendor/bin/phpunit

More details are in Running Tests.


Open source ByJG