Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b69f427

Browse files
authored
Add Postgres support for nested subpath (JSON) expressions (#246)
Implement the new SQLDialect.nestedSubpathExpression(in:for:) method for Postgres syntax.
1 parent a88d025 commit b69f427

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

‎Package.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
],
1515
dependencies: [
1616
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.14.2"),
17-
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.26.0"),
17+
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.28.0"),
1818
.package(url: "https://github.com/vapor/async-kit.git", from: "1.14.0"),
1919
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.1.0")
2020
],

‎Sources/PostgresKit/PostgresDialect.swift‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,19 @@ public struct PostgresDialect: SQLDialect {
5454
public var sharedSelectLockExpression: (any SQLExpression)? { SQLRaw("FOR SHARE") }
5555

5656
public var exclusiveSelectLockExpression: (any SQLExpression)? { SQLRaw("FOR UPDATE") }
57+
58+
public func nestedSubpathExpression(in column: any SQLExpression, for path: [String]) -> (any SQLExpression)? {
59+
guard !path.isEmpty else { return nil }
60+
61+
let descender = SQLList(
62+
[column] + path.dropLast().map(SQLLiteral.string(_:)),
63+
separator: SQLRaw("->")
64+
)
65+
let accessor = SQLList(
66+
[descender, SQLLiteral.string(path.last!)],
67+
separator: SQLRaw("->>")
68+
)
69+
70+
return SQLGroupExpression(accessor)
71+
}
5772
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /