Closed mattdowdell closed 10 months ago
Hi @mattdowdell,
OF
is not supported currently, but it makes sense to add it.
@go-jet Is there a workaround I can use to inject OF <table name>
into the locking clause? The best I thought of was emitting the SQL, doing a find/replace and then creating a raw statement to be executed by jet. But that seemed particularly clunky. I couldn't see any obvious hook to arbitrarily mutate the query before execution.
No, I don't see other workaround.
@go-jet I had a stab at implementing this, but got myself mixed up trying to figure out how. As it stands, RowLock's are part of the internal jet package, so extending the implementation there seems to be simplest. Particularly as that's where serialisation occurs today. I also added an extra interface/constructor (RowLockOf) so the method did not leak to the mysql or sqlite packages, e.g.
package jet
type RowLockOf interface {
RowLock
OF(table ...X) RowLock
}
func NewRowLockOf(name string) func() RowLockOf {
// ...
}
The problem came when figuring out how to pass the tables into the OF clause. I assume I want postgres.ReadableTable as an argument, but that would cause a circular import. Would you be able provide some advice on how to tie it off and/or whether it's a viable implementation?
As it stands, RowLock's are part of the internal jet package, so extending the implementation there seems to be simplest. Particularly as that's where serialisation occurs today.
Agree.
I also added an extra interface/constructor (RowLockOf) so the method did not leak to the mysql or sqlite packages, e.g.
There is no need for new interface. We want OF
method to be accessible from mysql
package, because mysql
also supports naming a locking table.
The problem came when figuring out how to pass the tables into the OF clause. I assume I want postgres.ReadableTable as an argument, but that would cause a circular import. Would you be able provide some advice on how to tie it off and/or whether it's a viable implementation?
You don't need the whole postgres.ReadableTable
interface, just TableName()
and Alias()
method for serialization purposes. You can use jet.Table
interface as a parameter.
Is your feature request related to a problem? Please describe. I have a query doing LEFT JOIN across 2 tables modeled on a many-to-many relationship and locking rows to prevent concurrent updates.
My schema is as follows, minus some rows I trimmed out for simplification:
In essence I can have multiple resources and each resource can have multiple groups associated with it.
I then have an update API that executes a SQL query as follows:
This produces an error:
This in itself seems to be expected per https://www.postgresql.org/message-id/21634.1160151923@sss.pgh.pa.us. And it's likely I need to rethink my use of joins in general.
On the plus side, I found that adjusting the locking clause to:
Allows the query to work. However, this does not seem to be supported in jet, potentially becaise this seems to be a PostgeSQL specific feature.
Describe the solution you'd like Support the use of
OF
inpostgres.RowLock
to allow outer joins to use locks.In testing the revised query, I found that the table in the
OF
clause had to be justresources
and the use ofpublic.resources
as used in theFROM
clause did not work.