Skip to content

Commit

Permalink
Handle JSON better (#107)
Browse files Browse the repository at this point in the history
* General package cleanup
* Send JSON to SQLite as TEXT, not BLOB. This restores compatibility with SQLite 3.45.0 and above, due to the new JSONB support changing the interpretation of JSON data in BLOB form (and is what should've been happening all along regardless).
* Some tests cleanup
* Add AnyExistential correctness.
* Quick and dirty fix for yet another of Tanner's disastrous misuses of Codable.
  • Loading branch information
gwynne authored Jan 18, 2024
1 parent 3be417e commit e9fd69b
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 265 deletions.
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ let package = Package(
.library(name: "SQLiteKit", targets: ["SQLiteKit"]),
],
dependencies: [
.package(url: "https://github.com/vapor/sqlite-nio.git", from: "1.6.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.62.0"),
.package(url: "https://github.com/vapor/sqlite-nio.git", from: "1.8.4"),
.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"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"),
],
targets: [
.target(name: "SQLiteKit", dependencies: [
.product(name: "NIOFoundationCompat", package: "swift-nio"),
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "SQLiteNIO", package: "sqlite-nio"),
.product(name: "SQLKit", package: "sql-kit"),
Expand Down
46 changes: 46 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// swift-tools-version:5.9
import PackageDescription

let swiftSettings: [SwiftSetting] = [
.enableUpcomingFeature("ExistentialAny"),
.enableExperimentalFeature("StrictConcurrency=complete"),
]

let package = Package(
name: "sqlite-kit",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.watchOS(.v6),
.tvOS(.v13),
],
products: [
.library(name: "SQLiteKit", targets: ["SQLiteKit"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.62.0"),
.package(url: "https://github.com/vapor/sqlite-nio.git", from: "1.8.4"),
.package(url: "https://github.com/vapor/sql-kit.git", from: "3.28.0"),
.package(url: "https://github.com/vapor/async-kit.git", from: "1.19.0"),
],
targets: [
.target(
name: "SQLiteKit",
dependencies: [
.product(name: "NIOFoundationCompat", package: "swift-nio"),
.product(name: "AsyncKit", package: "async-kit"),
.product(name: "SQLiteNIO", package: "sqlite-nio"),
.product(name: "SQLKit", package: "sql-kit"),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "SQLiteKitTests",
dependencies: [
.product(name: "SQLKitBenchmark", package: "sql-kit"),
.target(name: "SQLiteKit"),
],
swiftSettings: swiftSettings
),
]
)
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/1130717/268050157-c372aab8-fe28-4f08-a4bb-270673253a80.png">
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/1130717/268050207-3275e0a5-9c59-40e0-b854-4ee0af3ebc5c.png">
<img src="https://user-images.githubusercontent.com/1130717/268050207-3275e0a5-9c59-40e0-b854-4ee0af3ebc5c.png" height="96" alt="SQLiteKit">
</picture>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/sqlite-kit/assets/1130717/2d99c0b9-35e5-4f04-bb6c-8d59ff6e78c6">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/sqlite-kit/assets/1130717/cb36f94d-3ac3-4fba-b801-fe19eac7dbc2">
<img src="https://github.com/vapor/sqlite-kit/assets/1130717/cb36f94d-3ac3-4fba-b801-fe19eac7dbc2" height="96" alt="SQLiteKit">
</picture>
<br>
<br>
<a name=""><img src="https://img.shields.io/badge/sswg-incubating-green.svg" alt="SSWG Incubation"></a>
<a href="https://api.vapor.codes/sqlitekit/documentation/sqlitekit/"><img src="https://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Documentation"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/sqlite-kit/actions/workflows/test.yml"><img src="https://github.com/vapor/sqlite-kit/actions/workflows/test.yml/badge.svg" alt="Continuous Integration"></a>
<a href="https://swift.org"><img src="https://img.shields.io/badge/swift-5.7-brightgreen.svg" alt="Swift 5.7"></a>
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/sqlite-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/sqlite-kit/test.yml?event=push&style=plastic&logo=github&label=test&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/sqlite-kit"><img src="https://img.shields.io/codecov/c/github/vapor/sqlite-kit?style=plastic&logo=codecov&label=Codecov"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift57up.svg" alt="Swift 5.7+"></a>
<a href="https://www.swift.org/sswg/incubation-process.html"><img src="https://design.vapor.codes/images/sswg-graduated-white.svg" alt="SSWG Incubation Level: Graduated"></a>
</p>

<br>

SQLiteKit is a library providing an [SQLKit] driver for [SQLiteNIO].

> [!NOTE]
> The [FluentKit] driver for SQLite is provided by the [FluentSQLiteDriver] package.
[SQLKit]: https://swiftpackageindex.com/vapor/sql-kit
[SQLiteNIO]: https://swiftpackageindex.com/vapor/sqlite-nio
[Fluent]: https://swiftpackageindex.com/vapor/fluent-kit
[FluentSQLiteDriver]: https://swiftpackageindex.com/vapor/fluent-sqlite-driver
1 change: 0 additions & 1 deletion Sources/SQLiteKit/Docs.docc/images/article.svg

This file was deleted.

58 changes: 0 additions & 58 deletions Sources/SQLiteKit/Docs.docc/images/vapor-sqlite-logo.svg

This file was deleted.

22 changes: 22 additions & 0 deletions Sources/SQLiteKit/Docs.docc/images/vapor-sqlitekit-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 18 additions & 43 deletions Sources/SQLiteKit/Docs.docc/theme-settings.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,21 @@
{
"theme": {
"aside": {
"border-radius": "6px",
"border-style": "double",
"border-width": "3px"
},
"border-radius": "0",
"button": {
"border-radius": "16px",
"border-width": "1px",
"border-style": "solid"
},
"code": {
"border-radius": "16px",
"border-width": "1px",
"border-style": "solid"
},
"color": {
"fill": {
"dark": "rgb(0, 0, 0)",
"light": "rgb(255, 255, 255)"
},
"sqlite-teal": "hsl(215, 45%, 58%)",
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-documentation-intro-accent) 30%, #000 100%)",
"documentation-intro-accent": "var(--color-sqlite-teal)",
"documentation-intro-accent-outer": {
"dark": "rgb(255, 255, 255)",
"light": "rgb(0, 0, 0)"
},
"documentation-intro-accent-inner": {
"dark": "rgb(0, 0, 0)",
"light": "rgb(255, 255, 255)"
}
},
"icons": {
"technology": "/sqlitekit/images/vapor-sqlite-logo.svg",
"article": "/sqlitekit/images/article.svg"
}
"theme": {
"aside": { "border-radius": "6px", "border-style": "double", "border-width": "3px" },
"border-radius": "0",
"button": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
"code": { "border-radius": "16px", "border-width": "1px", "border-style": "solid" },
"color": {
"sqlite": "hsl(215, 45%, 58%)",
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-sqlite) 30%, #000 100%)",
"documentation-intro-accent": "var(--color-sqlite)",
"logo-base": { "dark": "#fff", "light": "#000" },
"logo-shape": { "dark": "#000", "light": "#fff" },
"fill": { "dark": "#000", "light": "#fff" }
},
"features": {
"quickNavigation": {
"enable": true
}
}
"icons": { "technology": "/sqlitekit/images/vapor-sqlitekit-logo.svg" }
},
"features": {
"quickNavigation": { "enable": true },
"i18n": { "enable": true }
}
}
4 changes: 2 additions & 2 deletions Sources/SQLiteKit/SQLiteConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import struct Foundation.UUID

public struct SQLiteConfiguration {
public enum Storage {
public struct SQLiteConfiguration: Sendable {
public enum Storage: Sendable {
/// Stores the SQLite database in memory.
///
/// Uses a randomly generated identifier. See `memory(identifier:)`.
Expand Down
15 changes: 8 additions & 7 deletions Sources/SQLiteKit/SQLiteConnection+SQLKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal struct _SQLiteDatabaseVersion: SQLDatabaseReportedVersion {
}

private struct _SQLiteSQLDatabase: SQLDatabase {
let database: SQLiteDatabase
let database: any SQLiteDatabase

var eventLoop: any EventLoop {
self.database.eventLoop
Expand All @@ -109,17 +109,18 @@ private struct _SQLiteSQLDatabase: SQLDatabase {
let binds: [SQLiteData]
do {
binds = try serializer.binds.map { encodable in
return try SQLiteDataEncoder().encode(encodable)
try SQLiteDataEncoder().encode(encodable)
}
} catch {
return self.eventLoop.makeFailedFuture(error)
}
return self.database.query(
serializer.sql,
binds,
logger: self.logger
) { row in

// This temporary silliness silences a Sendable capture warning whose correct resolution
// requires updating SQLKit itself to be fully Sendable-compliant.
@Sendable func onRowWorkaround(_ row: any SQLRow) {
onRow(row)
}
return self.database.query(serializer.sql, binds, logger: self.logger, onRowWorkaround)
}
}

2 changes: 1 addition & 1 deletion Sources/SQLiteKit/SQLiteConnectionSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import NIOPosix
import SQLiteNIO
import NIOCore

public struct SQLiteConnectionSource: ConnectionPoolSource {
public struct SQLiteConnectionSource: ConnectionPoolSource, Sendable {
private let configuration: SQLiteConfiguration
private let actualURL: URL
private let threadPool: NIOThreadPool
Expand Down
Loading

0 comments on commit e9fd69b

Please sign in to comment.