Giter VIP home page Giter VIP logo

harp's People

Contributors

hkdobrev avatar ivank avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

harp's Issues

Refactor

I've decided to go with a Session "object" instead of numerous "Repo" objects.
Some thoughts about this:

  • Moves us away from static classes and more into the realm of objects - greater testability, and more decoupled objects.
  • Would be very nice for the pimple or other dependancy container.
  • Follows more closely SQLAlchemy (Which I consider the state-of-the-art in ORM tech)

Things not to forget.

  • Implement transactions on commit
  • Expire identity map across transaction boundaries.

After looking into SQLAlchemy's source code, I've had some revelations:

  • it uses a significant amount of magic and late binding, so if executed right, our thing can be quite a lot faster.
  • each model has a reference to the session, but to avaid the var-dump problem (as well as probably general memory consumption) they use "session id" instead of a direct reference to the session in the model object. This is an approach I think we should also adopt.

Simplify interface to common operations

Here is an example from the readme:

$user = Repo\User::get()->find(1);

How about something like:

$user = Model\User::find(8);

It would be just an alias to getRepo()->find(1).

Example implementation:

<?php

trait FindShortcuts {

    public static function find($id)
    {
        // static interface to `getRepo()` is to be implemented
        return static::getRepo()->find($id);
    }
}

This could make the interface very much like the Laravel's Eloquent ORM: http://laravel.com/docs/eloquent

Another change is the repo is more hidden from the end user for common operations.

I think it's good to expose the repo and make the interface explicit for persisting and operating on multiple records. But getting an instance of a single model could be so much easier.

What do you think?

External Model Graph

External Graphs

I think the code should be much more understandable if all relationships are represented as links external to the model itself.

Reasons:

  • Separate code for "links" outside of model, making the Model Class more decoupled
  • More efficient aggregation - if it is a proper graph, then we can try to use known mathematical algos to solve problems
  • "var_dump" will be far safer operation
  • experiment with new concept

Requirements:

  • get all affected once a model is loaded, all other models, loaded as relations to this model should be recorded as such and you should be able to easily get all "affected" models
  • load related models on a single association - this for use of the default functionality of loading related models
  • eager loading - load all models related to other given models, based on schema rel.
  • eager loading - assign edges to the graph based on the loaded related models so that each model has its rels pre-loaded

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.