Skip to content

Commit baf0d86

Browse files
authored
Add the missing SQLDatabase.alter(table: any SQLExpression) method (#188)
* Bump Swift minimum to 5.10 and update README accordingly. * Fix a number of minor API docs issues found by the latest DocC * Add the missing `SQLDatabase.alter(table: any SQLExpression)` method * Update CI
1 parent e0b35ff commit baf0d86

15 files changed

Lines changed: 48 additions & 94 deletions

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ jobs:
1313
unit-tests:
1414
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
1515
secrets: inherit
16+
with:
17+
with_android: true
1618

1719
pure-fluent-integration-test:
1820
if: ${{ !(github.event.pull_request.draft || false) }}
1921
runs-on: ubuntu-latest
20-
container: swift:5.10-jammy
22+
container: swift:6.1-noble
2123
steps:
2224
- name: Check out sql-kit
2325
uses: actions/checkout@v4
@@ -48,7 +50,7 @@ jobs:
4850
strategy:
4951
fail-fast: false
5052
matrix:
51-
swift-image: ['swift:5.10-jammy']
53+
swift-image: ['swift:6.1-noble']
5254
driver:
5355
- { sqlkit: 'sqlite-kit', fluent: 'fluent-sqlite-driver' }
5456
- { sqlkit: 'mysql-kit', fluent: 'fluent-mysql-driver' }

Package.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version:5.10
22
import PackageDescription
33

44
let package = Package(
@@ -14,18 +14,18 @@ let package = Package(
1414
.library(name: "SQLKitBenchmark", targets: ["SQLKitBenchmark"]),
1515
],
1616
dependencies: [
17-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
18-
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
1917
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.0"),
18+
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
19+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
2020
],
2121
targets: [
2222
.target(
2323
name: "SQLKit",
2424
dependencies: [
25+
.product(name: "Collections", package: "swift-collections"),
2526
.product(name: "Logging", package: "swift-log"),
2627
.product(name: "NIO", package: "swift-nio"),
2728
.product(name: "NIOCore", package: "swift-nio"),
28-
.product(name: "Collections", package: "swift-collections"),
2929
],
3030
swiftSettings: swiftSettings
3131
),
@@ -48,6 +48,9 @@ let package = Package(
4848
)
4949

5050
var swiftSettings: [SwiftSetting] { [
51+
.enableUpcomingFeature("ExistentialAny"),
5152
.enableUpcomingFeature("ConciseMagicFile"),
5253
.enableUpcomingFeature("ForwardTrailingClosures"),
54+
.enableUpcomingFeature("DisableOutwardActorInference"),
55+
.enableExperimentalFeature("StrictConcurrency=complete"),
5356
] }

Package@swift-5.9.swift

Lines changed: 0 additions & 56 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
<p align="center">
2-
<picture>
3-
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/sql-kit/assets/1130717/b5828634-c1a1-4d91-b25d-20e033b77269">
4-
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/sql-kit/assets/1130717/f45e4b01-0579-4011-8b06-0f159e0d386f">
5-
<img src="https://github.com/vapor/sql-kit/assets/1130717/f45e4b01-0579-4011-8b06-0f159e0d386f" height="96" alt="SQLKit">
6-
</picture>
2+
<img src="https://design.vapor.codes/images/vapor-sqlkit.svg" height="96" alt="SQLKit">
73
<br>
84
<br>
95
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
106
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
117
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
128
<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>
139
<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>
14-
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift58up.svg" alt="Swift 5.8+"></a>
10+
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift510up.svg" alt="Swift 5.10+"></a>
1511
</p>
1612

1713
<br>

Sources/SQLKit/Builders/Implementations/SQLAlterTableBuilder.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ public final class SQLAlterTableBuilder: SQLQueryBuilder {
120120
return self
121121
}
122122

123-
/// Drop an existing column from the table
123+
/// Drop an existing column from the table.
124124
@inlinable
125125
@discardableResult
126126
public func dropColumn(_ column: String) -> Self {
127127
self.dropColumn(SQLIdentifier(column))
128128
}
129129

130-
/// Drop an existing column from the table
130+
/// Drop an existing column from the table.
131131
@inlinable
132132
@discardableResult
133133
public func dropColumn(_ column: any SQLExpression) -> Self {
@@ -146,6 +146,12 @@ extension SQLDatabase {
146146
/// Create a new ``SQLAlterTableBuilder``.
147147
@inlinable
148148
public func alter(table: SQLIdentifier) -> SQLAlterTableBuilder {
149-
.init(.init(name: table), on: self)
149+
self.alter(table: table as any SQLExpression)
150+
}
151+
152+
/// Create a new ``SQLAlterTableBuilder``.
153+
@inlinable
154+
public func alter(table: any SQLExpression) -> SQLAlterTableBuilder {
155+
.init(.init(name: table), on: self)
150156
}
151157
}

Sources/SQLKit/Builders/Implementations/SQLInsertBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public final class SQLInsertBuilder: SQLQueryBuilder, SQLReturningBuilder/*, SQL
186186
/// - Parameters:
187187
/// - models: Array of values of a given type to insert. The given type may be any encodable type which
188188
/// represents an aggregate value.
189-
/// - encodder: A preconfigured ``SQLQueryEncoder`` to use for encoding.
189+
/// - encoder: A preconfigured ``SQLQueryEncoder`` to use for encoding.
190190
@discardableResult
191191
public func models(
192192
_ models: [some Encodable],

Sources/SQLKit/Builders/Prototypes/SQLCommonTableExpressionBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ extension SQLCommonTableExpressionBuilder {
284284
/// This is the common "funnel" method invoked by all other methods provided by
285285
/// ``SQLCommonTableExpressionBuilder``. Most users will not need to call this method directly.
286286
///
287-
/// See ``with(_:columns:as)`` and ``with(recursive:_:columns:as:)`` for usage examples.
287+
/// See ``with(_:columns:as:)-28k4r`` and ``with(recursive:columns:as:)-6yef`` for usage examples.
288288
///
289289
/// > Warning: As with ``SQLCommonTableExpression``, ``SQLCommonTableExpressionBuilder`` does _NOT_ validate
290290
/// > that a recursive CTE's query takes the proper form, nor that a non-recursive CTE's query is not

Sources/SQLKit/Builders/Prototypes/SQLCommonUnionBuilder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ extension SQLCommonUnionBuilder {
8989
try self.union(all: predicate(SQLSubqueryBuilder()).select)
9090
}
9191

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

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

128-
/// Alias ``except(distinct:)-6vhbz`` so it acts as the "default".
128+
/// Alias ``except(distinct:)-62w7q`` so it acts as the "default".
129129
@inlinable
130130
public func except(_ predicate: (any SQLSubqueryClauseBuilder) throws -> any SQLSubqueryClauseBuilder) rethrows -> Self {
131131
try self.except(distinct: predicate)

Sources/SQLKit/Builders/Prototypes/SQLPartialResultBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extension SQLPartialResultBuilder {
2626

2727
/// Adds a `OFFSET` clause to the query. If called more than once, the last call wins.
2828
///
29-
/// - Parameter max: Optional offset. If `nil`, any existing offset is removed. The value may not be negative.
29+
/// - Parameter n: Optional offset. If `nil`, any existing offset is removed. The value may not be negative.
3030
/// - Returns: `self` for chaining.
3131
@inlinable
3232
@discardableResult

Sources/SQLKit/Docs.docc/BasicUsage.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ SELECT "id", "name" FROM "planets" WHERE "name" = ?1
4646
SELECT `id`, `name` FROM `planets` WHERE `name` = ?
4747
```
4848

49-
## Databases, Expressions, and Builders
49+
### Databases, Expressions, and Builders
5050

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

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

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

111-
### Rows
111+
#### Rows
112112

113113
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:
114114

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

127-
### Codable
127+
#### Codable
128128

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

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

147-
## Select
147+
### Select
148148

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

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

207-
## Insert
207+
### Insert
208208

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

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

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

237-
## Update
237+
### Update
238238

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

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

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

256-
## Delete
256+
### Delete
257257

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

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

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

274-
## Raw
274+
### Raw
275275

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

0 commit comments

Comments
 (0)