Giter VIP home page Giter VIP logo

data's Issues

DSQL - Feature Check!

We must have the following features, all documented, tested and coded.

  • get()
  • raw query
  • execute multiple statements
  • where
  • count(), exists()
  • min,max()
  • sum,avg()
  • distinct atk4/dsql#62
  • calc found rows atk4/dsql#62
  • raw expressions
  • join
  • union
  • union all
  • or
  • between
  • where in
  • where null
  • where ( .. or .. ) and ..
  • where exists ( select .. from .. )
  • having
  • having raw
  • insert one
  • insert multiple
  • insert delayed atk4/dsql#62
  • insert on duplicate key
  • get id of inserted record
  • replace
  • update where
  • increment / decrement
  • delete
  • truncate
  • lock
  • transaction
  • atomic
  • get query
  • get bindings
  • get pdo
  • support mysqli (wordpress, and some other libs are stuck with it)
  • change fetch mode
  • "case" support atk4/dsql#74

Reverse Join fails to update record

It appears that the use of $join->id in reveres join is incorrect.

Look at this file: https://github.com/atk4/data/blob/develop/src/Join_SQL.php#L211

With reverse join you are joining like this:

$db->join('contact.user_id');

foreign_field is user_id, and suppose user_id is 2. When you add new record, $join->id is set to lastInsertID:

$this->id = $insert->connection->lastInsertID();

so it holds the value of contact.id, let's say it's 1 for our new record. If you execute delete after, the where() clause can cause deletion of incorrect record:

$delete->where($this->foreign_field, $this->id);

which would render to "where user_id = 1".

  • create failing test-case for this bug
  • implement a fix

Add a usable join array model interface.

In my example I have table "Nominal" which is hierarchical. When I load it, I create an array like this:

"id" -> "path"

This is handy for be because now that when I'm reading from another model and it contain "id" value, I can look up full nominal path without worrying about number of selects.

I believe Agile Data can do this for me special join type. Here is how I'd like it to work:

$n = new Model_Nominal($db);
$assoc = $n->getPathAssociations();  // returns "id" -> "path"

// Next create a model
$nar = new Model($assoc));

// Test it
$nar->load(183);
echo $nar[$nar->title_field];  // will output path

$m = new Model_Report_Activity($db);
$m->join($nar, 'nominal_id')->addField('nominal_path');

foreach($m as $row) {
    var_dump($row); // includes 'nominal_path' now
}

Refactor code duplication in load, loadBy and loadAny()

i need to refactor load(), loadBy() and loadAny() to merge them with tryLoad, tryLoadBy an tryLoadAny. But there are some considerations:

  • tryLoad must throw and discard exception if the record is not found. It's CPU-expensive operation.
  • exception from load() must include Query as it currently does
  • tryLoad() failure should cause model to unload()
  • load() should throw exception but not unload the model.

Given these conditions, I'm not sure who should call what. I'm thinking there should be an extra argument to Persistence->loadX that will indicate if the exception should be generated or if [] should be simply returned.

Add support for Validators

There are many validators out there. Here is one example: https://github.com/Respect/Validation

We need to provide a way how a user can integrate a validator package into his model. I'm sure it's done through hooks, but this needs to be tested.

Especially when we integrate with the UI library, validators would typically give you true/false values but it needs to appear as an error on the form.

Agile Data needs to have a well-defined way how to define validations that would be compatible with 3rd party validators.

Implement Active Record

Model object can target DataSet but one of those records can be active. Even before we implement link with the database drivers, we can implement work with current (active) record.

  • set / get and array access to 'data' property

Basic support for Actions

We will need actions in order to handle load() save() operations:

$m->saveAction()->execute(); // same as save();

Model would populate save action with modified (dirty) fields.

Improving on relations

  • implement deep traversal
  • take examples from docs and convert them into tests
  • implement field importing and aggregates

add implementation for MongoDB()

I have focused my effort on Array and SQL implementation, but MongoDB implementation is not even started. We should get it started and implement all the features that we have already added for MongoDB.

hasOne - pass options to field

$this->hasOne('company_id', ['CompanyType', 'default'=>1]);

This does not properly pass default to the field. Worakround:

$this->hasOne('company_id', 'CompanyType');
$this->getElement('company_id')->default=1;

Create a standard way for specifying UI-related field properties

When Agile Data is used in UI frameworks, then model definition will sometimes include UI properties. This is because Model and UI binding is often a seamless one-line process:

$grid->setModel(new Model_User($db));

and $grid needs to populate information based on model fields only. Here are a couple of things that UI framework will expect to be difined in the field:

  • caption
  • type
  • ui-specific options
$m->addField('birthdate', ['type'=>'date', 'ui'=>'DatePicker', 'caption'=>'Birth Date']);

We need a document explaining what is the standard way to implement UI properties.

Create test: insert into related entity with reloading

  1. Create model instance
  2. Add condition
  3. reference hasOne() relation
  4. make sure reloading is ON for this related model
  5. save new record (it will be reloaded)
  6. main model instance should contain id auto-filled.

The point of this test is to make sure that insert works well and not failing randomly. Note that relations in AD are optional.

add support for normalization

In most cases when user is trying to save " John Smith" he actually means "John Smith". It's just an accidental space, but that can cause trouble.

The same can be said for the numbers "394,283.03" and booleans "Y" / "N".

The process of converting user-supplied values that are "almost good" into an actually good input is called Normalisation. Agile Data needs to have a well-defined way to handle normalization.

add ability to create simple relations with addRelation()

Currently using hasOne() and hasMany() you can define related models. That's cool, but sometimes you want to add a custom relation.

Basically when calling $m->ref('AuditLog'); it would respond with a related model. Technically you could create a method $m->getAuditLog(); but we want to keep all relations separate in case we want to iterate through them (for example by visualising in UI or exploring relations).

Here is invocation:

$m->addRelation('AuditLog', function($m) {
    return (new Model_Audit($big_data_db))->addCondition('user_id', $m->id);
});

And usage after:

$log = $m->load(123)->ref('AuditLog');
$log->addAction(..);

or in UI framework:

$crud->addRef('AuditLog');

Cloning of model is unsafe.

I defined model like this:

class Model_Transfer extends Model {
    public $table='doc';
    function init() {
        parent::init();

        $this->addField('amount');
        $this->pmt = $this->join('payment.doc_id');

        $this->pmt->hasOne('account_id', 'Model_Account');
        $this->pmt->hasOne('tronsfer_payment_id', 'Model_Transfer');        
    }

    function createPayment($account2, $amount)
    {
        $leg2 = clone $this;
        $leg2['account_id'] = $account2->id;
        $leg2['amount'] = $amount;
        $leg2->save();

        $this['amount'] = -$amount;
        $this['transfer_payment_id'] = $leg2->id;
        $this->save();

        $leg2['transfer_payment_id'] = $this->id;
        $leg2->save();  // BUG IN THIS LINE
    }
}

The bug happens in the last save. It appears due to the cloning of a model, the related record ID gets messed up and instead of updating leg2's transfer_payment_id AD actually updates the other record.

If `clone` is replaced with 'new' then no problems appear. 

Clone must be made safe.

 - [ ] Implement a tes-case for thi scase
 - [ ] fix

Create standard type set

Types such as 'string', 'date', 'int' and 'boolean' (or bool) should be standart and all persistences should know how to deal with those types.

  • define list of types on a wiki page
  • define normalisation rules and write documentation
  • create test-script
  • implement for SQL persistence
  • imlpement for Array persistence

https://github.com/atk4/data/wiki/Type-Normalization

Review DSQL terms consistency

Currently we use some terms randomly.

  • parameter
  • argument
  • option
  • tag
  • property

etc. We should clean up our vocabulary and review the software to make sure it's all clean.

Implement detection of modified fields

Either Dirty or comparing with the original values. Not sure which one yet

Dirty: will fail if same value is written back.

Original: need to store original value and needlessly compare.

Perhaps a combination can be used, e.g. copy-on-modify.

$m['name'] = 'John';
var_dump($m->saveAction());

^^ the query should only update 'name' and not 'surname'

Implement arbitrary field meta-data

As framework extend the base Model class, they may want to use their own "Field" class also, which will be more handy for storing some UI-related fields (e.g. hint, caption, etc). As we are not concerned with those, we should make it possible to extend.

On other hand, we do want certain properties to be stored such as type, length, enum.

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.