Git Product home page Git Product logo

php-document-store's People

Contributors

codeliner avatar heiglandreas avatar jsor avatar martin-schilling avatar sandrokeil avatar zluiten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

php-document-store's Issues

Add a countDocs method

A way to count (filtered) documents without actually loading them would be useful: public function countDocs(string $collectionName, Filter $filter): int

Add name() method to Index interface

It would be useful, if Index defines a name() method. This allows only one instanceof check e.g. in dropIndex to get the name of the index, instead of checking for FieldIndex and MutliFieldIndex.

How to query for content inside an array

Given a document inside the document store with the following content:

{
  "state" : {
    "key1" : "value1",
    "key2" : [{
      "subkey" : "value 1"
    }, {
      "subkey" : "value 2"
    }],
    "key3" : "value3"
    }
}

How can I retrieve that document from the document store using value 2 for subkey inside key2?

For key1 and key3 i'd use the following code:

$filter = new EqFilter('state.key1', 'value1');
$filter = new EqFilter('state.key3', 'value3');

But how would I go for value 2?

I tried the following to no avail:

$filter = new EqFilter('state.key2.subkey', 'value 1');
$filter = new EqFilter('state.key2.[].subkey', 'value 1');

What am I missing? Do I by chance need to use the ArrayFilter instead?

Allow to return raw json data

With #21 we will have a BC break. So we should also think about an interface to allow to return the raw json data. Something like getDocRaw without json_decode.

Clarify how associative arrays as document values should be updated.

Assuming the following:

        $this->documentStore->updateDoc(
            $collection,
            $event->get(Payload::USER_ID),
            [
                Payload::USER_VALIDATIONS   => [
                    $event->get(Payload::USER_EMAIL_ADDRESS) => $event->createdAt(),
                ],
            ],
        );

The InMemoryDocumentStore would merge the Payload::USER_VALIDATIONS arrays recursively, adding additional values. This provides no way of removing a nested key. There is even a test to enforce this behaviour: https://github.com/event-engine/php-document-store/blob/1e980c8e8e3f7b48428740e109692440dffa3a2b/tests/InMemoryDocumentStoreTest.php#L88-112

Further, the event-engine/php-postgres-document-store handles this differently, where merges are NOT recursive: https://github.com/event-engine/php-postgres-document-store/blob/e9721e21f42a648a79eb9865b5656c6949bf1c42/src/PostgresDocumentStore.php#L366

For more on how the || operator is used: https://www.postgresql.org/docs/13/functions-json.html

I have submitted the following PRs for changes:

  • Add tests to event-engine/php-postgres-document-store to confirm that associative arrays are not merged recursively (event-engine/php-postgres-document-store#15).
  • Modify the tests on this repository, and the behaviour of InMemoryDocumentStore to conform to the behaviour of event-engine/php-postgres-document-store (#18).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.