morris/lessql

Why not return a Row instead of a PDOStatement on insert?

Closed this issue · 4 comments

Wouldn't it be useful to return a \LessQL\Row instead of a \PDOStatement when inserting a row?

Because I wanted to keep Database clean of Row functionality. In most cases you'd better use Row/save, which updates the primary key and allows for nested data:

$row = $db->createRow( $table, $data )->save();
// $row is a Row instance and will have the generated primary key
// also $data may be a nested structure

Think of Database/insert as a raw insertion facility; it's not designed to update primary keys or handle complex data. It's good at inserting batches of simple (flat) rows, though.

I see. Thanks for pointing that out. It's just that is seems more natural to be able to have the createRow functionality (or a simpler one that doesn't accept nested data) accessible from the table. Maybe something like:

$row = $db->my_table()->createRow($data) 

What's your take on that?

That makes sense, since there is also $db->my_table()->insert() and such which just defer to the database. Will add this soon - thanks :-)

Added in v0.3.2