Coder Social home page Coder Social logo

incorrect namespace about data HOT 9 CLOSED

yiisoft avatar yiisoft commented on July 18, 2024
incorrect namespace

from data.

Comments (9)

kamarton avatar kamarton commented on July 18, 2024

and \Yiisoft\Data\Reader\OffsetableDataInterface: mongodb support inserting at position (see $position). I can imagine that there is an API endpoint that can write to a position similarly.

from data.

samdark avatar samdark commented on July 18, 2024

While such SQL makes sense, I see no use for filtering in case of writer. We have data we want to write already, it's easier and more efficient to filter data with simple foreach than by passing unfiltered data array to writer along with saving criteria.

from data.

rob006 avatar rob006 commented on July 18, 2024

Example SQL update:

This looks like MySQL-specific. AFAIK limit and order are not directly supported in update queries by most of DBMS.

from data.

kamarton avatar kamarton commented on July 18, 2024

@rob006 This is a generic Writer layer, if you have the opportunity somewhere, it is advisable to plan into the layer.

from data.

samdark avatar samdark commented on July 18, 2024

I still don't see any practical application for using filters with a data writer. We have our data, we can prepare it right away before sending it to writer. That has both simplicity and performance benefits.

from data.

kamarton avatar kamarton commented on July 18, 2024

I can't really see what the Writer interface is all about. I assumed that ActiveRecord would use this too, hiding the write layer, e.g. so that I can swap one NoSQL under it for another NoSQL without changing ActiveRecord class.

$ar->field2 = '22';
$ar->save();

// $ar->save() --> $db->writer() -> writer->write();
$db->writer->withFilters(new Equals('id',  $ar->id))->write($ar->changedAttributes());

I implemented more database server under yii2, and I find this solution easier to implement and more flexible.

from data.

samdark avatar samdark commented on July 18, 2024

I can't really see what the Writer interface is all about.

Having array of data items, persist all of them:

$data = [
    [
        'id' => 1,
        'name' => 'Somogyi',
    ],
    [
         'id' => 2,
         'name' => 'Alex',
    ],
];

$writer = new ActiveRecordDataWriter(User::class);
$writer->write($data);

$db->writer->withFilters(new Equals('id', $ar->id))->write($ar->changedAttributes());

Why do you need withFilters here? Also, changed attributes isn't writer concern. That's internal thing of a possible AR specific implementation.

from data.

kamarton avatar kamarton commented on July 18, 2024

It's ok, if run INSERT, but if require UPDATE?

$writer = new ActiveRecordDataWriter(User::class);
$writer->write($data);

I don't really see why Writer filters are provided wit AR, whereas Reader filters are not.

$db->writer->withFilters(new LessThan('id',  88))->write($attributes);
// === yii2 AR->updateAll($attributes, ['<', 'id', 88]);

If I use simple types, I just need to replace the Writer and write to almost any target destination (RDBMS, NoSQL, Redis), eg with custom BasicActiveRecord. If ActiveRecord does this (why?), Then I need to create a N versions of class because they must extends from different classes.

Nonetheless, I already understand that this is not a real Writer layer, but some very simplified implementation, and I probably need to see the rest of the system to understand why.

from data.

samdark avatar samdark commented on July 18, 2024

Yes, that wasn't meant to replace AR or provide full-featured abstraction over any storage. Let's assume it won't be needed to reuse filters for writer.

from data.

Related Issues (20)

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.