Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ builder:
- documentation_targets:
- StructuredQueriesCore
- StructuredQueries
- StructuredQueriesSQLiteCore
- StructuredQueriesSQLite
custom_documentation_parameters:
- '--enable-experimental-overloaded-symbol-presentation'
# - '--enable-experimental-combined-documentation'
62 changes: 46 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ let package = Package(
targets: ["StructuredQueriesCore"]
),
.library(
name: "StructuredQueriesTestSupport",
targets: ["StructuredQueriesTestSupport"]
name: "StructuredQueriesSQLite",
targets: ["StructuredQueriesSQLite"]
),
.library(
name: "_StructuredQueriesSQLite",
targets: ["StructuredQueriesSQLite"]
name: "StructuredQueriesSQLiteCore",
targets: ["StructuredQueriesSQLiteCore"]
),
.library(
name: "StructuredQueriesTestSupport",
targets: ["StructuredQueriesTestSupport"]
),
],
traits: [
Expand All @@ -46,6 +50,13 @@ let package = Package(
.package(url: "https://github.com/swiftlang/swift-syntax", "600.0.0"..<"602.0.0"),
],
targets: [
.target(
name: "StructuredQueries",
dependencies: [
"StructuredQueriesCore",
"StructuredQueriesMacros",
]
),
.target(
name: "StructuredQueriesCore",
dependencies: [
Expand All @@ -58,13 +69,6 @@ let package = Package(
],
exclude: ["Symbolic Links/README.md"]
),
.target(
name: "StructuredQueries",
dependencies: [
"StructuredQueriesCore",
"StructuredQueriesMacros",
]
),
.macro(
name: "StructuredQueriesMacros",
dependencies: [
Expand All @@ -73,12 +77,30 @@ let package = Package(
],
exclude: ["Symbolic Links/README.md"]
),

.target(
name: "StructuredQueriesSQLite",
dependencies: [
"StructuredQueries"
"StructuredQueries",
"StructuredQueriesSQLiteCore",
"StructuredQueriesSQLiteMacros",
]
),
.target(
name: "StructuredQueriesSQLiteCore",
dependencies: [
"StructuredQueriesCore",
.product(name: "IssueReporting", package: "xctest-dynamic-overlay")
]
),
.macro(
name: "StructuredQueriesSQLiteMacros",
dependencies: [
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
]
),

.target(
name: "StructuredQueriesTestSupport",
dependencies: [
Expand All @@ -90,8 +112,8 @@ let package = Package(
.testTarget(
name: "StructuredQueriesMacrosTests",
dependencies: [
"StructuredQueries",
"StructuredQueriesMacros",
"StructuredQueriesSQLiteMacros",
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
.product(name: "MacroTesting", package: "swift-macro-testing"),
]
Expand All @@ -102,11 +124,19 @@ let package = Package(
"StructuredQueries",
"StructuredQueriesSQLite",
"StructuredQueriesTestSupport",
"_StructuredQueriesSQLite",
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
]
),

.target(
name: "_StructuredQueriesSQLite",
dependencies: [
"StructuredQueriesSQLite"
]
),
],
swiftLanguageModes: [.v6]
)
Expand All @@ -128,14 +158,14 @@ for index in package.targets.indices {
#if !canImport(Darwin)
package.targets.append(
.systemLibrary(
name: "StructuredQueriesSQLite3",
name: "_StructuredQueriesSQLite3",
providers: [.apt(["libsqlite3-dev"])]
)
)

for index in package.targets.indices {
if package.targets[index].name == "StructuredQueriesSQLite" {
package.targets[index].dependencies.append("StructuredQueriesSQLite3")
if package.targets[index].name == "_StructuredQueriesSQLite" {
package.targets[index].dependencies.append("_StructuredQueriesSQLite3")
}
}
#endif
Expand Down
62 changes: 48 additions & 14 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ let package = Package(
targets: ["StructuredQueriesTestSupport"]
),
.library(
name: "_StructuredQueriesSQLite",
name: "StructuredQueriesSQLite",
targets: ["StructuredQueriesSQLite"]
),
.library(
name: "StructuredQueriesSQLiteCore",
targets: ["StructuredQueriesSQLiteCore"]
),
.library(
name: "StructuredQueriesTestSupport",
targets: ["StructuredQueriesTestSupport"]
),
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"),
Expand All @@ -38,20 +46,20 @@ let package = Package(
.package(url: "https://github.com/swiftlang/swift-syntax", "600.0.0"..<"602.0.0"),
],
targets: [
.target(
name: "StructuredQueriesCore",
dependencies: [
.product(name: "IssueReporting", package: "xctest-dynamic-overlay")
],
exclude: ["Symbolic Links/README.md"]
),
.target(
name: "StructuredQueries",
dependencies: [
"StructuredQueriesCore",
"StructuredQueriesMacros",
]
),
.target(
name: "StructuredQueriesCore",
dependencies: [
.product(name: "IssueReporting", package: "xctest-dynamic-overlay")
],
exclude: ["Symbolic Links/README.md"]
),
.macro(
name: "StructuredQueriesMacros",
dependencies: [
Expand All @@ -60,12 +68,30 @@ let package = Package(
],
exclude: ["Symbolic Links/README.md"]
),

.target(
name: "StructuredQueriesSQLite",
dependencies: [
"StructuredQueries"
"StructuredQueries",
"StructuredQueriesSQLiteCore",
"StructuredQueriesSQLiteMacros",
]
),
.target(
name: "StructuredQueriesSQLiteCore",
dependencies: [
"StructuredQueriesCore",
.product(name: "IssueReporting", package: "xctest-dynamic-overlay")
]
),
.macro(
name: "StructuredQueriesSQLiteMacros",
dependencies: [
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
]
),

.target(
name: "StructuredQueriesTestSupport",
dependencies: [
Expand All @@ -74,11 +100,12 @@ let package = Package(
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
]
),

.testTarget(
name: "StructuredQueriesMacrosTests",
dependencies: [
"StructuredQueries",
"StructuredQueriesMacros",
"StructuredQueriesSQLiteMacros",
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
.product(name: "MacroTesting", package: "swift-macro-testing"),
]
Expand All @@ -87,13 +114,20 @@ let package = Package(
name: "StructuredQueriesTests",
dependencies: [
"StructuredQueries",
"StructuredQueriesSQLite",
"StructuredQueriesTestSupport",
"_StructuredQueriesSQLite",
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
]
),

.target(
name: "_StructuredQueriesSQLite",
dependencies: [
"StructuredQueriesSQLite"
]
),
],
swiftLanguageModes: [.v6]
)
Expand All @@ -115,14 +149,14 @@ for index in package.targets.indices {
#if !os(Darwin)
package.targets.append(
.systemLibrary(
name: "StructuredQueriesSQLite3",
name: "_StructuredQueriesSQLite3",
providers: [.apt(["libsqlite3-dev"])]
)
)

for index in package.targets.indices {
if package.targets[index].name == "StructuredQueriesSQLite" {
package.targets[index].dependencies.append("StructuredQueriesSQLite3")
if package.targets[index].name == "_StructuredQueriesSQLite" {
package.targets[index].dependencies.append("_StructuredQueriesSQLite3")
}
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions Sources/StructuredQueriesCore/Optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ extension Optional: QueryBindable where Wrapped: QueryBindable {
public var queryBinding: QueryBinding {
self?.queryBinding ?? .null
}

public init?(queryBinding: QueryBinding) {
self = Wrapped(queryBinding: queryBinding)
}
}

extension Optional: QueryDecodable where Wrapped: QueryDecodable {
Expand Down
32 changes: 32 additions & 0 deletions Sources/StructuredQueriesCore/QueryBindable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@ public protocol QueryBindable: QueryRepresentable, QueryExpression where QueryVa

/// A value that can be bound to a parameter of a SQL statement.
var queryBinding: QueryBinding { get }

/// Initializes a bindable type from a binding.
init?(queryBinding: QueryBinding)
}

extension QueryBindable {
public var queryFragment: QueryFragment { "\(queryBinding)" }

public init?(queryBinding: QueryBinding) {
guard let queryValue = QueryValue(queryBinding: queryBinding) else { return nil }
self.init(queryBinding: queryValue.queryBinding)
}
}

extension [UInt8]: QueryBindable, QueryExpression {
public var queryBinding: QueryBinding { .blob(self) }
public init?(queryBinding: QueryBinding) {
guard case .blob(let value) = queryBinding else { return nil }
self = value
}
}

extension Bool: QueryBindable {
Expand All @@ -25,10 +37,18 @@ extension Bool: QueryBindable {

extension Double: QueryBindable {
public var queryBinding: QueryBinding { .double(self) }
public init?(queryBinding: QueryBinding) {
guard case .double(let value) = queryBinding else { return nil }
self = value
}
}

extension Date: QueryBindable {
public var queryBinding: QueryBinding { .date(self) }
public init?(queryBinding: QueryBinding) {
guard case .date(let value) = queryBinding else { return nil }
self = value
}
}

extension Float: QueryBindable {
Expand All @@ -53,10 +73,18 @@ extension Int32: QueryBindable {

extension Int64: QueryBindable {
public var queryBinding: QueryBinding { .int(self) }
public init?(queryBinding: QueryBinding) {
guard case .int(let value) = queryBinding else { return nil }
self = value
}
}

extension String: QueryBindable {
public var queryBinding: QueryBinding { .text(self) }
public init?(queryBinding: QueryBinding) {
guard case let .text(value) = queryBinding else { return nil }
self = value
}
}

extension UInt8: QueryBindable {
Expand All @@ -83,6 +111,10 @@ extension UInt64: QueryBindable {

extension UUID: QueryBindable {
public var queryBinding: QueryBinding { .uuid(self) }
public init?(queryBinding: QueryBinding) {
guard case .uuid(let value) = queryBinding else { return nil }
self = value
}
}

extension DefaultStringInterpolation {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ``StructuredQueriesSQLite``

Core SQLite extensions to StructuredQueries.

## Overview

The core functionality of this library is defined in
[`StructuredQueriesSQLiteCore`](<doc:/StructuredQueriesSQLiteCore>), which this module automatically
exports.

This module also contains all of the macros that support the core functionality of the library.

See [`StructuredQueriesSQLiteCore`](<doc:/StructuredQueriesSQLiteCore>) for general library usage.

## Topics

### Macros

- ``DatabaseFunction(_:isDeterministic:)``
2 changes: 2 additions & 0 deletions Sources/StructuredQueriesSQLite/Exports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@_exported import StructuredQueries
@_exported import StructuredQueriesSQLiteCore
18 changes: 18 additions & 0 deletions Sources/StructuredQueriesSQLite/Macros.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import StructuredQueriesSQLiteCore

/// Defines and implements a conformance to the ``/StructuredQueriesSQLiteCore/DatabaseFunction``
/// protocol.
///
/// - Parameters
/// - name: The function's name. Defaults to the name of the function the macro is applied to.
/// - isDeterministic: Whether or not the function is deterministic (or "pure" or "referentially
/// transparent"), _i.e._ given an input it will always return the same output.
@attached(peer, names: overloaded, prefixed(`$`))
public macro DatabaseFunction(
_ name: String = "",
isDeterministic: Bool = false
) =
#externalMacro(
module: "StructuredQueriesSQLiteMacros",
type: "DatabaseFunctionMacro"
)
Loading