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
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ jobs:
unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
secrets: inherit
with:
with_android: true

pure-fluent-integration-test:
if: ${{ !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.10-jammy
container: swift:6.1-noble
steps:
- name: Check out sql-kit
uses: actions/checkout@v4
Expand Down Expand Up @@ -48,7 +50,7 @@ jobs:
strategy:
fail-fast: false
matrix:
swift-image: ['swift:5.10-jammy']
swift-image: ['swift:6.1-noble']
driver:
- { sqlkit: 'sqlite-kit', fluent: 'fluent-sqlite-driver' }
- { sqlkit: 'mysql-kit', fluent: 'fluent-mysql-driver' }
Expand Down
11 changes: 7 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.8
// swift-tools-version:5.10
import PackageDescription

let package = Package(
Expand All @@ -14,18 +14,18 @@ let package = Package(
.library(name: "SQLKitBenchmark", targets: ["SQLKitBenchmark"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
],
targets: [
.target(
name: "SQLKit",
dependencies: [
.product(name: "Collections", package: "swift-collections"),
.product(name: "Logging", package: "swift-log"),
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "Collections", package: "swift-collections"),
],
swiftSettings: swiftSettings
),
Expand All @@ -48,6 +48,9 @@ let package = Package(
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
56 changes: 0 additions & 56 deletions Package@swift-5.9.swift

This file was deleted.

8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/sql-kit/assets/1130717/b5828634-c1a1-4d91-b25d-20e033b77269">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/sql-kit/assets/1130717/f45e4b01-0579-4011-8b06-0f159e0d386f">
<img src="https://github.com/vapor/sql-kit/assets/1130717/f45e4b01-0579-4011-8b06-0f159e0d386f" height="96" alt="SQLKit">
</picture>
<img src="https://design.vapor.codes/images/vapor-sqlkit.svg" height="96" alt="SQLKit">
<br>
<br>
<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/sql-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/sql-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/sql-kit"><img src="https://img.shields.io/codecov/c/github/vapor/sql-kit?style=plastic&logo=codecov&label=codecov"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift58up.svg" alt="Swift 5.8+"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
</p>

<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ public final class SQLAlterTableBuilder: SQLQueryBuilder {
return self
}

/// Drop an existing column from the table
/// Drop an existing column from the table.
@inlinable
@discardableResult
public func dropColumn(_ column: String) -> Self {
self.dropColumn(SQLIdentifier(column))
}

/// Drop an existing column from the table
/// Drop an existing column from the table.
@inlinable
@discardableResult
public func dropColumn(_ column: any SQLExpression) -> Self {
Expand All @@ -146,6 +146,12 @@ extension SQLDatabase {
/// Create a new ``SQLAlterTableBuilder``.
@inlinable
public func alter(table: SQLIdentifier) -> SQLAlterTableBuilder {
.init(.init(name: table), on: self)
self.alter(table: table as any SQLExpression)
}

/// Create a new ``SQLAlterTableBuilder``.
@inlinable
public func alter(table: any SQLExpression) -> SQLAlterTableBuilder {
.init(.init(name: table), on: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public final class SQLInsertBuilder: SQLQueryBuilder, SQLReturningBuilder/*, SQL
/// - Parameters:
/// - models: Array of values of a given type to insert. The given type may be any encodable type which
/// represents an aggregate value.
/// - encodder: A preconfigured ``SQLQueryEncoder`` to use for encoding.
/// - encoder: A preconfigured ``SQLQueryEncoder`` to use for encoding.
@discardableResult
public func models(
_ models: [some Encodable],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ extension SQLCommonTableExpressionBuilder {
/// This is the common "funnel" method invoked by all other methods provided by
/// ``SQLCommonTableExpressionBuilder``. Most users will not need to call this method directly.
///
/// See ``with(_:columns:as)`` and ``with(recursive:_:columns:as:)`` for usage examples.
/// See ``with(_:columns:as:)-28k4r`` and ``with(recursive:columns:as:)-6yef`` for usage examples.
///
/// > Warning: As with ``SQLCommonTableExpression``, ``SQLCommonTableExpressionBuilder`` does _NOT_ validate
/// > that a recursive CTE's query takes the proper form, nor that a non-recursive CTE's query is not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extension SQLCommonUnionBuilder {
try self.union(all: predicate(SQLSubqueryBuilder()).select)
}

/// Alias ``union(distinct:)-1ert0`` so it acts as the "default".
/// Alias ``union(distinct:)-921p6`` so it acts as the "default".
@inlinable
public func union(_ predicate: (any SQLSubqueryClauseBuilder) throws -> any SQLSubqueryClauseBuilder) rethrows -> Self {
try self.union(distinct: predicate)
Expand All @@ -107,7 +107,7 @@ extension SQLCommonUnionBuilder {
try self.intersect(all: predicate(SQLSubqueryBuilder()).select)
}

/// Alias ``intersect(distinct:)-47w8a`` so it acts as the "default".
/// Alias ``intersect(distinct:)-8f71m`` so it acts as the "default".
@inlinable
public func intersect(_ predicate: (any SQLSubqueryClauseBuilder) throws -> any SQLSubqueryClauseBuilder) rethrows -> Self {
try self.intersect(distinct: predicate)
Expand All @@ -125,7 +125,7 @@ extension SQLCommonUnionBuilder {
try self.except(all: predicate(SQLSubqueryBuilder()).select)
}

/// Alias ``except(distinct:)-6vhbz`` so it acts as the "default".
/// Alias ``except(distinct:)-62w7q`` so it acts as the "default".
@inlinable
public func except(_ predicate: (any SQLSubqueryClauseBuilder) throws -> any SQLSubqueryClauseBuilder) rethrows -> Self {
try self.except(distinct: predicate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension SQLPartialResultBuilder {

/// Adds a `OFFSET` clause to the query. If called more than once, the last call wins.
///
/// - Parameter max: Optional offset. If `nil`, any existing offset is removed. The value may not be negative.
/// - Parameter n: Optional offset. If `nil`, any existing offset is removed. The value may not be negative.
/// - Returns: `self` for chaining.
@inlinable
@discardableResult
Expand Down
16 changes: 8 additions & 8 deletions Sources/SQLKit/Docs.docc/BasicUsage.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SELECT "id", "name" FROM "planets" WHERE "name" = ?1
SELECT `id`, `name` FROM `planets` WHERE `name` = ?
```

## Databases, Expressions, and Builders
### Databases, Expressions, and Builders

Instances of ``SQLDatabase`` are capable of executing arbitrary ``SQLExpression``s:

Expand Down Expand Up @@ -108,7 +108,7 @@ WHERE "column1" = $1 AND "column2" IS NULL

Of course, this is an _awful_ lot of code to achieve such a relatively straightforward result, which is why SQLKit provides query builders.

### Rows
#### Rows

For query builders that support returning results (e.g. any builder conforming to the ``SQLQueryFetcher`` protocol), there are additional methods for handling the database output:

Expand All @@ -124,7 +124,7 @@ let name = try row.decode(column: "name", as: String.self)
print(name) // String
```

### Codable
#### Codable

``SQLRow`` also supports decoding `Codable` models directly:

Expand All @@ -144,7 +144,7 @@ let planets: [Planet] = try await db.select()
.all(decoding: Planet.self)
```

## Select
### Select

The ``SQLDatabase/select()`` method creates a `SELECT` query builder:

Expand Down Expand Up @@ -204,7 +204,7 @@ This code generates the following SQL when used with the SQLite driver:
WHERE "name" <> NULL AND ("name" = ?1 OR "name" = ?2) -- bindings: ["Milky Way", "Andromeda"]
```

## Insert
### Insert

The ``SQLDatabase/insert(into:)-67oqt`` and ``SQLDatabase/insert(into:)-5n3gh`` methods create an `INSERT` query builder:

Expand Down Expand Up @@ -234,7 +234,7 @@ try builder.model(Galaxy(name: "Milky Way"))

This code generates the same SQL as would `builder.columns("name").values("Milky Way")`.

## Update
### Update

The ``SQLDatabase/update(_:)-2tf1c`` and ``SQLDatabase/update(_:)-80964`` methods create an `UPDATE` query builder:

Expand All @@ -253,7 +253,7 @@ UPDATE `planets` SET `name` = ? WHERE `name` = ? -- bindings: ["Jupiter", "Jupit

The update builder supports the same `where()` and `orWhere()` methods as the select builder, via the ``SQLPredicateBuilder`` protocol.

## Delete
### Delete

The ``SQLDatabase/delete(from:)-3tx4f`` and ``SQLDatabase/delete(from:)-4bqlu`` methods create a `DELETE` query builder:

Expand All @@ -271,7 +271,7 @@ DELETE FROM "planets" WHERE "name" = ?1 -- bindings: ["Jupiter"]

The delete builder also conforms to ``SQLPredicateBuilder``.

## Raw
### Raw

The ``SQLDatabase/raw(_:)`` method allows passing custom SQL query strings, with support for parameterized bindings and correctly-quoted identifiers:

Expand Down
4 changes: 2 additions & 2 deletions Sources/SQLKit/Docs.docc/SQLQueryFetcher+ExtensionDocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- ``SQLQueryFetcher/run(_:)-40swz``
- ``SQLQueryFetcher/run(decoding:_:)-476q1``
- ``SQLQueryFetcher/run(decoding:prefix:keyDecodingStrategy:userInfo:_:)-3q92a``
- ``SQLQueryFetcher/run(decoding:prefix:keyDecodingStrategy:userInfo:_:)-583ot``
- ``SQLQueryFetcher/run(decoding:with:_:)-8y7ux``

### Getting All Rows
Expand All @@ -29,7 +29,7 @@

- ``SQLQueryFetcher/run(_:)-542bs``
- ``SQLQueryFetcher/run(decoding:_:)-6z89k``
- ``SQLQueryFetcher/run(decoding:prefix:keyDecodingStrategy:userInfo:_:)-6axmo``
- ``SQLQueryFetcher/run(decoding:prefix:keyDecodingStrategy:userInfo:_:)-2cp56``
- ``SQLQueryFetcher/run(decoding:with:_:)-4tte7``
- ``SQLQueryFetcher/all()-5j67e``
- ``SQLQueryFetcher/all(decoding:)-6q02f``
Expand Down
5 changes: 4 additions & 1 deletion Sources/SQLKit/Docs.docc/theme-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
"sqlkit": { "dark": "hsl(32, 77%, 63%)", "light": "hsl(32, 80%, 60%)" },
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-sqlkit) 30%, #000 100%)",
"documentation-intro-accent": "var(--color-sqlkit)",
"documentation-intro-eyebrow": "white",
"documentation-intro-figure": "white",
"documentation-intro-title": "white",
"logo-base": { "dark": "#fff", "light": "#000" },
"logo-shape": { "dark": "#000", "light": "#fff" },
"fill": { "dark": "#000", "light": "#fff" }
},
"icons": { "technology": "/sqlkit/images/vapor-sqlkit-logo.svg" }
"icons": { "technology": "/sqlkit/images/SQLKit/vapor-sqlkit-logo.svg" }
},
"features": {
"quickNavigation": { "enable": true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct SQLColumnDefinition: SQLExpression {
/// Create a new columm definition from a name, data type, and zero or more constraints.
///
/// - Parameters:
/// - column: The column name to create or alter.
/// - name: The column name to create or alter.
/// - dataType: The desired data type of the column.
/// - constraints: The constraints to apply to the column, if any.
@inlinable
Expand Down
8 changes: 4 additions & 4 deletions Sources/SQLKit/Expressions/Syntax/SQLFunction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ extension SQLFunction {
/// .all()
/// ```
///
/// - Parameter exprs: A list of expressions to coalesce.
/// - Parameter expressions: A list of expressions to coalesce.
/// - Returns: An appropriately-constructed ``SQLFunction``.
@inlinable
public static func coalesce(_ exprs: any SQLExpression...) -> SQLFunction {
self.coalesce(exprs)
public static func coalesce(_ expressions: any SQLExpression...) -> SQLFunction {
self.coalesce(expressions)
}

/// A factory method to simplify use of the standard `COALESCE()` function.
Expand All @@ -108,7 +108,7 @@ extension SQLFunction {
/// .all()
/// ```
///
/// - Parameter exprs: A list of expressions to coalesce.
/// - Parameter expressions: A list of expressions to coalesce.
/// - Returns: An appropriately-constructed ``SQLFunction``.
@inlinable
public static func coalesce(_ expressions: [any SQLExpression]) -> SQLFunction {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SQLKit/Rows/SQLQueryEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public struct SQLQueryEncoder: Sendable {
}

/// Encode an `Encodable` value to an array of key/expression pairs suitable for use as input to
/// ``SQLInsertBuilder/values(_:)-1pro8``, ``SQLUpdateBuilder/set(_:to:)-8mvob``, and other related APIs.
/// ``SQLInsertBuilder/values(_:)-1pro8``, ``SQLColumnUpdateBuilder/set(_:to:)-dnbq``, and other related APIs.
///
/// - Parameter encodable: The value to encode.
/// - Returns: A sequence of (column name, value expression) pairs representing an output row. The order of the
Expand Down