ITADN

`join` with `delete` queries

#168Closedrichwolf 创建于 2023-05-12
enhancement
R
richwolfcommented
It seems that `join` cannot be added to a delete query. For example, this works in my desktop MySQL client (Querious) but cannot be coded: ``` DELETE choices FROM choices JOIN elections ON choices.election_uuid = elections.uuid WHERE choices.uuid = UUID_TO_BIN('B337E365F02F11EDB0B50A07A8932707') AND elections.author = "richwolf"; ``` into something like this: ``` let queryBuilder = sqlDatabase.delete(from: choicesTable) .join( electionsTable, on: electionUUIDColumn, .equal, choiceElectionUUIDColumn ) .where(choiceUUIDColumn, .equal, SQLBind(id)) .where(electionAuthorColumn, .equal, SQLBind(author)) ``` Of course, an obvious workaround is simply to code a raw query, but I was hoping to hack something together. In my reading of the sources, I kind of gather that joins work for `select` queries because `SQLSelectBuilder` conforms to the `SQLSubqueryClauseBuilder` protocol. I tried to replicate that in `SQLDeleteBuilder` ... and my `join()` does get called ... but it doesn't seem to write to the `joins` array that I hacked into the `SQLDelete` query struct. `join` does find the predicates in my code ... but it doesn't write anything to the `self.joins` in the query object and is (therefore) not serialized (I was also careful to amend the `serialize` method in the `SQLDelete` query struct to look for a non-empty joins array and write out the join in a way similar to the way the `SQLSelect` `serialize` method does things). I feel like I'm kinda close, but not quite there. I guess what I'm looking for here (assuming I explained it anywhere near clearly 😄) is a "you're on the right track" or "no, you wanna look at this" or even, "not ever gonna be a thing if you P/R, just go with the raw query."
关闭于 2023-07-05 2 条评论