snapshot of https://github.com/sqlc-dev/sqlc.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
Some checks failed
kotlin / test (push) Has been skipped
python / test (push) Has been skipped
typescript / test (push) Has been skipped
go / build darwin/amd64 (push) Has been cancelled
go / build linux/amd64 (push) Has been cancelled
go / build windows/amd64 (push) Has been cancelled
go / build darwin/arm64 (push) Has been cancelled
go / build linux/arm64 (push) Has been cancelled
go / build windows/arm64 (push) Has been cancelled
go / test (push) Has been cancelled
go / vuln_check (push) Has been cancelled
This commit is contained in:
59
internal/sql/ast/locking_clause.go
Normal file
59
internal/sql/ast/locking_clause.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package ast
|
||||
|
||||
import "github.com/sqlc-dev/sqlc/internal/sql/format"
|
||||
|
||||
type LockingClause struct {
|
||||
Tag NodeTag[LockingClause] `json:"tag"`
|
||||
|
||||
LockedRels *List `json:"locked_rels,omitempty"`
|
||||
Strength LockClauseStrength `json:"strength"`
|
||||
WaitPolicy LockWaitPolicy `json:"wait_policy"`
|
||||
}
|
||||
|
||||
func (n *LockingClause) Pos() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// LockClauseStrength values (matching pg_query_go)
|
||||
const (
|
||||
LockClauseStrengthUndefined LockClauseStrength = 0
|
||||
LockClauseStrengthNone LockClauseStrength = 1
|
||||
LockClauseStrengthForKeyShare LockClauseStrength = 2
|
||||
LockClauseStrengthForShare LockClauseStrength = 3
|
||||
LockClauseStrengthForNoKeyUpdate LockClauseStrength = 4
|
||||
LockClauseStrengthForUpdate LockClauseStrength = 5
|
||||
)
|
||||
|
||||
// LockWaitPolicy values
|
||||
const (
|
||||
LockWaitPolicyBlock LockWaitPolicy = 1
|
||||
LockWaitPolicySkip LockWaitPolicy = 2
|
||||
LockWaitPolicyError LockWaitPolicy = 3
|
||||
)
|
||||
|
||||
func (n *LockingClause) Format(buf *TrackedBuffer, d format.Dialect) {
|
||||
if n == nil {
|
||||
return
|
||||
}
|
||||
buf.WriteString("FOR ")
|
||||
switch n.Strength {
|
||||
case LockClauseStrengthForKeyShare:
|
||||
buf.WriteString("KEY SHARE")
|
||||
case LockClauseStrengthForShare:
|
||||
buf.WriteString("SHARE")
|
||||
case LockClauseStrengthForNoKeyUpdate:
|
||||
buf.WriteString("NO KEY UPDATE")
|
||||
case LockClauseStrengthForUpdate:
|
||||
buf.WriteString("UPDATE")
|
||||
}
|
||||
if items(n.LockedRels) {
|
||||
buf.WriteString(" OF ")
|
||||
buf.join(n.LockedRels, d, ", ")
|
||||
}
|
||||
switch n.WaitPolicy {
|
||||
case LockWaitPolicySkip:
|
||||
buf.WriteString(" SKIP LOCKED")
|
||||
case LockWaitPolicyError:
|
||||
buf.WriteString(" NOWAIT")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user