Closed capcom6 closed 3 weeks ago
Thanks for your work.
I only have a rough understanding of the background for now and don’t have any well-developed ideas yet. But I have some simple ideas:
@j2gg0s , thanks for your comment.
I apologize for not mentioning the background earlier. The syntax DELETE ... ORDER BY ... LIMIT ... RETURNING ...
can be used to implement the Transactional outbox pattern, allowing for reading messages in a single query with deletion and specified order. Additionally, ORDER BY...
in DELETE
and UPDATE
statements can be helpful when working with relations to control the order of changes and prevent foreign key constraint violations.
Regarding your ideas:
UPDATE
statement and introduced feature flags for syntax support in both UPDATE
and DELETE
.SelectQuery
to orderLimitOffsetQuery
.P.S. For now, I've created distinct commits for changes to simplify the review process. I'll edit the commit history later.
Looking forward to you squashing the commits and officially submitting the changes.
This PR adds support for
ORDER BY
andLIMIT
clauses inDELETE
statements specifically for MySQL and MariaDB databases.Changes:
orderQuery
andlimitOffsetQuery
fromSelectQuery
, seequery_base.go
andquery_select.go
orderQuery
andlimitOffsetQuery
inDeleteQuery
, seequery_delete.go
Order
andLimit
methods onDeleteQuery
, seequery_delete.go
query_test.go
Example usage:
This feature enhances the flexibility of
DELETE
operations in MySQL and MariaDB, allowing for more precise control over which rows are deleted and in which order.Questions: I have some questions about which I'm unsure:
PR #1009 has allowed
Limit
withoutOrder
for MSSQL. As a side effect, it has introduced a dependency between these parts of the query, which in my PR is separated. Before #1009, my implementations fully movedORDER
andLIMIT...OFFSET
parts into reusable and independent parts. Now I had to "override"appendQuery
inSelectQuery
to support this MSSQL behavior.Because only MySQL/MariaDB supports syntax with
LIMIT
andORDER BY
forDELETE
, I'm unsure where to return an error for other dialects. For now, I seterr
inOrder
,OrderExpr
, andLimit
methods ofDeleteQuery
.This syntax can't be used with multiple tables. The only place to validate this that I found is
AppendQuery
. Is this correct?Additional context:
References: