forked from m-barthelemy/vapor-queues-fluent-driver
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
30 additions
and
22 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @gwynne |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
import SQLKit | ||
|
||
enum SQLSkipLocked: SQLExpression { | ||
case forUpdateSkipLocked | ||
case forShareSkipLocked | ||
enum SQLLockingClauseWithSkipLocked: SQLExpression { | ||
/// Request an exclusive "writer" lock, skipping rows that are already locked. | ||
case updateSkippingLocked | ||
|
||
/// Request a shared "reader" lock, skipping rows that are already locked. | ||
/// | ||
/// > Note: This is the "lightest" locking that is supported by both Postgres and MySQL. | ||
case shareSkippingLocked | ||
|
||
// See `SQLExpression.serialize(to:)`. | ||
func serialize(to serializer: inout SQLSerializer) { | ||
guard serializer.dialect.name != "sqlite" else { | ||
return | ||
} | ||
|
||
switch self { | ||
case .forUpdateSkipLocked: | ||
serializer.write("FOR UPDATE SKIP LOCKED") | ||
case .forShareSkipLocked: | ||
// This is the "lightest" locking that is supported by both Postgres and Mysql | ||
serializer.write("FOR SHARE SKIP LOCKED") | ||
serializer.statement { | ||
switch self { | ||
case .updateSkippingLocked: | ||
guard $0.dialect.exclusiveSelectLockExpression != nil else { return } | ||
$0.append(SQLLockingClause.update) | ||
case .shareSkippingLocked: | ||
guard $0.dialect.sharedSelectLockExpression != nil else { return } | ||
$0.append(SQLLockingClause.share) | ||
} | ||
$0.append("SKIP LOCKED") | ||
} | ||
} | ||
} |