Skip to content

Commit

Permalink
Add SQLite support for nested subpath (JSON) expressions (#104)
Browse files Browse the repository at this point in the history
Implement the new SQLDialect.nestedSubpathExpression(in:for:) method for SQLite syntax.
  • Loading branch information
gwynne authored Jul 11, 2023
1 parent 54e651f commit 2b20fc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/vapor/sqlite-nio.git", from: "1.2.0"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.19.0"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.28.0"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.14.0"),
],
targets: [
Expand Down
9 changes: 9 additions & 0 deletions Sources/SQLiteKit/SQLiteDialect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public struct SQLiteDialect: SQLDialect {
return nil
}

public func nestedSubpathExpression(in column: any SQLExpression, for path: [String]) -> (any SQLExpression)? {
guard !path.isEmpty else { return nil }

return SQLFunction("json_extract", args: [
column,
SQLLiteral.string("$.\(path.joined(separator: "."))")
])
}

public init() { }

private func isAtLeastVersion(_ major: Int, _ minor: Int, _ patch: Int) -> Bool {
Expand Down

0 comments on commit 2b20fc0

Please sign in to comment.