Skip to content

Commit

Permalink
Merge pull request #5 from byjg/4.9
Browse files Browse the repository at this point in the history
Upgrading library
  • Loading branch information
byjg committed Jan 7, 2024
2 parents b0ea47b + b5308be commit b437e0e
Show file tree
Hide file tree
Showing 22 changed files with 367 additions and 239 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/phpunit.yml
@@ -0,0 +1,73 @@
name: PHPUnit
on:
push:
branches:
- master
tags:
- "*.*.*"
pull_request:
branches:
- master

jobs:
Build:
runs-on: 'ubuntu-latest'
container: 'byjg/php:${{ matrix.php-version }}-cli'
strategy:
matrix:
php-version:
- "8.2"
- "8.1"
- "8.0"
- "7.4"

services:
mongodb:
image: mongo:3
env:
TZ: America/Winnipeg
ports:
- 27017:27017

dynamodb:
image: amazon/dynamodb-local
ports:
- 8000:8000

s3:
image: localstack/localstack
ports:
- "4566:4566"
env:
SERVICES: s3
DEFAULT_REGION: us-west-1
AWS_DEFAULT_REGION: us-west-1
HOSTNAME: s3
HOSTNAME_EXTERNAL: s3
USE_SSL: false
DEBUG: 1
options: >-
--health-cmd "awslocal s3 ls"
--health-interval 5s
--health-timeout 10s
--health-retries 5
env:
MONGODB_CONNECTION: "mongodb://mongodb/test"
S3_CONNECTION: "s3://aaa:12345678@us-east-1/mybucket?create=true&endpoint=http://s3:4566"
DYNAMODB_CONNECTION: "dynamodb://aaa:123456@us-east-1/tablename?endpoint=http://dynamodb:8000"

steps:
- uses: actions/checkout@v4
- run: composer install
- run: ./vendor/bin/phpunit

Documentation:
if: github.ref == 'refs/heads/master'
needs: Build
uses: byjg/byjg.github.io/.github/workflows/add-doc.yaml@master
with:
folder: php
project: ${{ github.event.repository.name }}
secrets: inherit

3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -6,4 +6,5 @@ vendor
.idea

node_modules
.usdocker
.usdocker
/.phpunit.result.cache
4 changes: 2 additions & 2 deletions .run/Test Project.run.xml
Expand Up @@ -2,9 +2,9 @@
<configuration default="false" name="Test Project" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
<CommandLine>
<envs>
<env name="DYNAMODB_CONNECTION" value="dynamodb://access_key:secret_key@us-east-1/tablename?endpoint=http://127.0.0.1:8000" />
<env name="DYNAMODB_CONNECTION" value="dynamodb://aaa:123456@us-east-1/tablename?endpoint=http://127.0.0.1:8000" />
<env name="MONGODB_CONNECTION" value="mongodb://127.0.0.1/test" />
<env name="S3_CONNECTION" value="s3://aaa:12345678@us-east-1/mybucket?create=true&amp;endpoint=http://127.0.0.1:9000" />
<env name="S3_CONNECTION" value="s3://aaa:12345678@us-east-1/mybucket?create=true&amp;endpoint=http://localhost:4566" />
</envs>
</CommandLine>
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml.dist" scope="XML" use_alternative_configuration_file="true" />
Expand Down
37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

60 changes: 50 additions & 10 deletions README.md
@@ -1,15 +1,40 @@
# AnyDataset-NoSql

[![Build Status](https://github.com/byjg/php-anydataset-nosql/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/php-anydataset-nosql/actions/workflows/phpunit.yml)
[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/anydataset-nosql/)
[![GitHub license](https://img.shields.io/github/license/byjg/anydataset-nosql.svg)](https://opensource.byjg.com/opensource/licensing.html)
[![GitHub release](https://img.shields.io/github/release/byjg/anydataset-nosql.svg)](https://github.com/byjg/anydataset-nosql/releases/)
[![Build Status](https://travis-ci.com/byjg/anydataset-nosql.svg?branch=master)](https://travis-ci.com/byjg/anydataset-nosql)
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/php-anydataset-nosql/)
[![GitHub license](https://img.shields.io/github/license/byjg/php-anydataset-nosql.svg)](https://opensource.byjg.com/opensource/licensing.html)
[![GitHub release](https://img.shields.io/github/release/byjg/php-anydataset-nosql.svg)](https://github.com/byjg/php-anydataset-nosql/releases/)

Anydataset NoSQL standardize the access to non-relational databases/repositories and treat them as Key/Value.
The implementation can work with:

NoSql abstraction dataset. Anydataset is an agnostic data source abstraction layer in PHP.
- MongoDB
- Cloudflare KV
- S3
- DynamoDB

Anydataset is an agnostic data source abstraction layer in PHP. See more about Anydataset [here](https://opensource.byjg.com/php/anydataset).

## Features

- Access as Key/Value repositories different datasource
- Allow put and get data
- Simplified way to connect to the datasources

## Connection Based on URI

The connection string for databases is based on URL.

See below the current implemented drivers:

| Datasource | Connection String |
|---------------------------------------------|----------------------------------------------------------|
| [MongoDB](docs/MongoDB.md) | mongodb://username:password@hostname:port/database |
| [Cloudflare KV](docs/CloudFlareKV.md) | kv://username:password@accountid/namespaceid |
| [S3](docs/AwsS3KeyValue.md) | s3://accesskey:secretkey@region/bucket?params |
| [AWS DynamoDB](docs/AwsDynamoDbKeyValue.md) | dynamodb://accesskey:secretkey@hostname/tablename?params |

See more about Anydataset [here](https://opensource.byjg.com/php/anydataset).

## Examples

Expand All @@ -20,12 +45,16 @@ Check implementation examples on [https://opensource.byjg.com/php/anydataset-nos
Just type:

```bash
composer require "byjg/anydataset-nosql=4.1.*"
composer require "byjg/anydataset-nosql"
```

## Running Unit tests

```bash
docker-compose up -d
export MONGODB_CONNECTION="mongodb://127.0.0.1/test"
export S3_CONNECTION="s3://aaa:12345678@us-east-1/mybucket?create=true&endpoint=http://127.0.0.1:4566"
export DYNAMODB_CONNECTION="dynamodb://accesskey:secretkey@us-east-1/tablename?endpoint=http://127.0.0.1:8000"
vendor/bin/phpunit
```

Expand All @@ -40,13 +69,13 @@ Set the environment variable:

Set the environment variable:

- DYNAMODB_CONNECTION = "dynamodb://access_key:secret_key@region/tablename"
- DYNAMODB_CONNECTION = "dynamodb://accesskey:secretkey@region/tablename"

### Setup AWS S3 for the unit test

Set the environment variable:

- S3_CONNECTION = "s3://access_key:secret_key@region/bucketname"
- S3_CONNECTION = "s3://accesskey:secretkey@region/bucketname"


### Cloudflare KV
Expand All @@ -55,7 +84,18 @@ Set the environment variable:

- CLOUDFLAREKV_CONNECTION = "kv://email:authkey@accountid/namespaceid"


## Dependencies

```mermaid
flowchart TD
byjg/anydataset-nosql --> ext-curl
byjg/anydataset-nosql --> aws/aws-sdk-php
byjg/anydataset-nosql --> byjg/anydataset
byjg/anydataset-nosql --> byjg/anydataset-array
byjg/anydataset-nosql --> byjg/serializer
byjg/anydataset-nosql --> byjg/webrequest
byjg/anydataset-nosql --> ext-json
```

----
[Open source ByJG](http://opensource.byjg.com)
14 changes: 7 additions & 7 deletions composer.json
Expand Up @@ -9,21 +9,21 @@
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"php": ">=5.6.0",
"php": ">=7.4",
"ext-curl": "*",
"aws/aws-sdk-php": "3.*",
"byjg/anydataset": "4.1.*",
"byjg/anydataset-array": "4.1.*",
"byjg/serializer": "1.0.*",
"byjg/webrequest": "2.0.*",
"byjg/anydataset": "4.9.*",
"byjg/anydataset-array": "4.9.*",
"byjg/serializer": "4.9.*",
"byjg/webrequest": "4.9.*",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "5.7.*|7.4.*"
"phpunit/phpunit": "5.7.*|7.4.*|^9.6"
},
"suggest": {
"ext-mongodb": "*",
"byjg/cache-engine": "4.0.*"
"byjg/cache-engine": "4.9.*"
},
"license": "MIT"
}
31 changes: 22 additions & 9 deletions docker-compose.yml
@@ -1,4 +1,4 @@
version: '2.0'
version: '3.0'
services:

mongodb:
Expand All @@ -7,20 +7,33 @@ services:
environment:
TZ: America/Winnipeg
ports:
- 27017:27017
- "27017:27017"

dynanodb:
container_name: anydataset_nosql_dynamodb
image: amazon/dynamodb-local
ports:
- 8000:8000
- "8000:8000"

# s3:
# container_name: anydataset_nosql_s3
# image: minio/minio
# environment:
# MINIO_ACCESS_KEY: aaa
# MINIO_SECRET_KEY: 12345678
## command: ["server", "/data"]
# ports:
# - 9000:9000

s3:
container_name: anydataset_nosql_s3
image: minio/minio
environment:
MINIO_ACCESS_KEY: aaa
MINIO_SECRET_KEY: 12345678
command: ["server", "/data"]
image: localstack/localstack
ports:
- 9000:9000
- "4566:4566"
environment:
- SERVICES=s3
- DEFAULT_REGION=us-west-1
- AWS_DEFAULT_REGION=us-west-1
- HOSTNAME_EXTERNAL=localhost
- USE_SSL=false
- DEBUG=1
14 changes: 7 additions & 7 deletions docs/AwsDynamoDbKeyValue.md
Expand Up @@ -2,7 +2,7 @@

```php
<?php
$dynamodb = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('dynamodb://access_key:secret_key@region/tablename');
$dynamodb = \ByJG\AnyDataset\NoSql\Factory::getInstance('dynamodb://access_key:secret_key@region/tablename');
```

The full connection string can be:
Expand All @@ -26,7 +26,7 @@ s3://AKA12345678899:aaaaaaaaaaaaaaaaaaaaaaaaa@us-east-1/tablename?endpoint=http:

## Preparing to use DynamoDb

DynamoDb stores the information slightly different than a model dto structure.
DynamoDb stores the information slightly different from a model dto structure.

Here an example how DynamoDb requires a model:

Expand All @@ -50,7 +50,7 @@ and a definition more usual is to have :
]
```

We will use the second definition. However, every put/get/remove method we will need to setup
We will use the second definition. However, every put/get/remove method we will need to set up
a list of options to define this data model.

basically we have to create an array with 2 keys:
Expand All @@ -77,7 +77,7 @@ The examples below will use this definition.

```php
<?php
$dynamodb = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('dynamodb://....');
$dynamodb = \ByJG\AnyDataset\NoSql\Factory::getInstance('dynamodb://....');
$dynamodb->put(
1201,
[
Expand All @@ -93,7 +93,7 @@ $dynamodb->put(

```php
<?php
$dynamodb = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('dynamodb://....');
$dynamodb = \ByJG\AnyDataset\NoSql\Factory::getInstance('dynamodb://....');
$value = $dynamodb->get(1201, $options);

/* Should Return:
Expand All @@ -110,7 +110,7 @@ $value = $dynamodb->get(1201, $options);

```php
<?php
$dynamodb = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('dynamodb://....');
$dynamodb = \ByJG\AnyDataset\NoSql\Factory::getInstance('dynamodb://....');
$dynamodb->remove(1201);
```

Expand All @@ -123,7 +123,7 @@ Example:

```php
<?php
$dynamodb = \ByJG\AnyDataset\NoSql\Factory::getKeyValueInstance('dynamodb://....');
$dynamodb = \ByJG\AnyDataset\NoSql\Factory::getInstance('dynamodb://....');

$options = [
"KeyConditions" => [
Expand Down

0 comments on commit b437e0e

Please sign in to comment.