Refactor `Command` and `Query` for DB 3.0
Open
Nobody has claimed this yet.
severity:BC breaking
- Dominant language
- PHP
- Stars
- 216
- Forks
- 51
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 2
Description
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()
}
- The current
Queryneeds to be split intoSelectCommandandSelectQuery; - Everything related to
Queryshould be moved fromCommandtoSelectCommand; SelectCommandcontainsSelectQueryand acts as a proxy;- Parts related to
Queryshould be moved fromQueryBuildertoSelectQueryBuilderand should work withSelectQuery; SelectQuerymust not depend onConnectionInterface;- The remaining
InsertCommand,UpdateCommand,DeleteCommandcommands are done similarly, but with their own executing methods, for exampleInsertCommand::retuning()similar to the currentCommand::insertReturning(); InsertQuery,SelectQuery,UpdateQuery,DeleteQueryshould follow to #714- The corresponding methods for creating the commands should be added to
ConnectionInterface; - 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing Command, Query, and QueryBuilder implementations together with ConnectionInterface. Compare their current responsibilities with the proposed command/query split and review issue #714 before deciding the migration scope. Done means the four command families and their builders expose the stated examples without SelectQuery depending on ConnectionInterface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- databases
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100