Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undoctrine doctrine specification #150

Draft
wants to merge 103 commits into
base: master
Choose a base branch
from

Conversation

peter-gribanov
Copy link
Member

@peter-gribanov peter-gribanov commented Apr 22, 2017

Reopen PR #82

This is not the final implementation. So far this is only a concept.

Benefits:

  • Specifications do not know anything about Doctrine;
  • You can implement your transformers of specifications;
  • For example, I added transformers for Doctrine ODM MongoDB;
  • You can write a transformer for a specific function of the database. For example for a map/reduce functions.

Doctrine ODM MongoDB docs.

Disadvantages:

  • We break back compatibility;
  • For each custom specification, you need to write your own transformer.

Usage

Join

Join condition can be used only from parameters of specification:

$spec = new SpecificationCollection([
    new Equals('published', false),
    new InnerJoin('user', 'u', InnerJoin::ON, new AndX(
        new Equals('banned', false),
        new LessOrEqualThan('birthday', new \DateTime('-18 year'))
    ))
]);

Map Reduce

Example specification:

class Foo implements Map, Reduce
{
    /**
     * @return string
     */
    public function getMap()
    {
        return 'function() {
            emit(this.userId, 1);
        }';
    }

    /**
     * @return string
     */
    public function getReduce()
    {
        return 'function(k, vals) {
            var sum = 0;
            for (var i in vals) {
                sum += vals[i];
            }
            return sum;
        }';
    }
}

@peter-gribanov
Copy link
Member Author

If we want to divide the structure of the specifications and apply them to queries, then it is better to make additional repositories which, as plugins, expand the basic functionality.

There is a problem with the fact that the query interface for ORM and ODM is very different. Accordingly, the structure of the specifications will also differ. Perhaps, it is worth concentrating only on ORM.

@Nyholm are you interested in developing this idea?

@peter-gribanov
Copy link
Member Author

Also, i think it's better to make this change as a separate repository.
I believe that this repository should remain connected with Doctrine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant