Skip to content

Refactor Command and Query for DB 3.0 #1046

Description

@Tigrov
classDiagram
    Connection --> InsertCommand
    Connection --> SelectCommand
    Connection --> UpdateCommand
    Connection --> DeleteCommand
    
    InsertCommand --> InsertQuery
    SelectCommand --> SelectQuery
    UpdateCommand --> UpdateQuery
    DeleteCommand --> DeleteQuery

    InsertQuery -- InsertQueryBuilder
    SelectQuery -- SelectQueryBuilder
    UpdateQuery -- UpdateQueryBuilder
    DeleteQuery -- DeleteQueryBuilder

    class Connection {
        insert()
        select()
        update()
        delete()
    }

    class InsertCommand {
        execute()
        onConflict() / upsert()
        returning()
        batch()
    }

    class SelectCommand {
        all()
        one()
        column()
        scalar()
    }

    class UpdateCommand {
        execute()
    }

    class DeleteCommand {
        execute()
    }
Loading
  1. The current Query needs to be split into SelectCommand and SelectQuery;
  2. Everything related to Query should be moved from Command to SelectCommand;
  3. SelectCommand contains SelectQuery and acts as a proxy;
  4. Parts related to Query should be moved from QueryBuilder to SelectQueryBuilder and should work with SelectQuery;
  5. SelectQuery must not depend on ConnectionInterface;
  6. The remaining InsertCommand, UpdateCommand, DeleteCommand commands are done similarly, but with their own executing methods, for example InsertCommand::retuning() similar to the current Command::insertReturning();
  7. InsertQuery, SelectQuery, UpdateQuery, DeleteQuery should follow to Remove methods replacing query condition #714
  8. The corresponding methods for creating the commands should be added to ConnectionInterface;
  9. Examples of how it will work after the changes:
$db->insert($table, $values)->execute();
$db->insert($table, $values)->onConflict($newValues)->returning(['id']);
$db->insert($table, $values)->batch();
$db->select($columns)->from($table)->where($condition)->all(); // as now
$db->update($table, $values, $condition)->execute();
$db->update($table, $values)->from($from)->where($condition)->execute();
$db->delete($table, $condition)->execute();

This will allow to add more options to commands and build more complex queries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions