You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Documentation/Index.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,7 @@ To use SQLite.swift classes or structures in your target’s source file, first
81
81
82
82
```swift
83
83
importSQLite
84
-
```
84
+
```
85
85
86
86
87
87
### Connecting to a Database
@@ -237,7 +237,7 @@ The `create(table:)` function has several default parameters we can override.
237
237
db.create(table: users, temporary: true) { t in/* ... */ }
238
238
// CREATE TEMPORARY TABLE "users" -- ...
239
239
```
240
-
240
+
241
241
- `ifNotExists` adds an `IF NOT EXISTS` clause to the `CREATE TABLE` statement (which will bail out gracefully if the table already exists). Default: `false`.
242
242
243
243
``` swift
@@ -266,21 +266,21 @@ The `column` function is used for a single column definition. It takes an [expre
266
266
t.column(email, unique: true)
267
267
// "email" TEXT UNIQUE NOT NULL
268
268
```
269
-
269
+
270
270
- `check` attaches a `CHECK` constraint to a column definition in the form of a boolean expression (`Expression<Bool>`). Boolean expressions can be easily built using [filter operators and functions](#filter-operators-and-functions). (See also the `check` function under [Table Constraints](#table-constraints).)
271
271
272
272
``` swift
273
273
t.column(email, check: like("%@%", email))
274
274
// "email" TEXT NOT NULL CHECK ("email" LIKE '%@%')
275
275
```
276
-
276
+
277
277
- `defaultValue` adds a `DEFAULT` clause to a column definition and _only_ accepts a value (or expression) matching the column’s type. This value is used if none is explicitly provided during [an `INSERT`](#inserting-rows).
278
278
279
279
``` swift
280
280
t.column(name, defaultValue: "Anonymous")
281
281
// "name" TEXT DEFAULT 'Anonymous'
282
282
```
283
-
283
+
284
284
> _Note:_ The `defaultValue` parameter cannot be used alongside `primaryKey` and `references`. If you need to create a column that has a default value and is also a primary and/or foreign key, use the `primaryKey` and `foreignKey` functions mentioned under [Table Constraints](#table-constraints).
285
285
286
286
- `collate` adds a `COLLATE` clause to `Expression<String>` (and `Expression<String?>`) column definitions with [a collating sequence](https://www.sqlite.org/datatype3.html#collation) defined in the `Collation` enumeration.
@@ -289,7 +289,7 @@ The `column` function is used for a single column definition. It takes an [expre
289
289
t.column(email, collate: .NoCase)
290
290
// "email" TEXT NOT NULL COLLATE NOCASE
291
291
```
292
-
292
+
293
293
- `references` adds a `REFERENCES` clause to `Expression<Int>` (and `Expression<Int?>`) column definitions and accepts a table (`Query`) or namespaced column expression. (See the `foreignKey` function under [Table Constraints](#table-constraints) for non-integer foreign key support.)
294
294
295
295
``` swift
@@ -314,14 +314,14 @@ Additional constraints may be provided outside the scope of a single column usin
314
314
t.primaryKey(email.asc, name)
315
315
// PRIMARY KEY("email" ASC, "name")
316
316
```
317
-
317
+
318
318
- `unique` adds a `UNIQUE` constraint to the table. Unlike [the column constraint, above](#column-constraints), it supports composite (multiple column) constraints.
319
319
320
320
``` swift
321
321
t.unique(local, domain)
322
322
// UNIQUE("local", "domain")
323
323
```
324
-
324
+
325
325
- `check` adds a `CHECK` constraint to the table in the form of a boolean expression (`Expression<Bool>`). Boolean expressions can be easily built using [filter operators and functions](#filter-operators-and-functions). (See also the `check` parameter under [Column Constraints](#column-constraints).)
326
326
327
327
``` swift
@@ -358,7 +358,7 @@ The `insert` function can return several different types that are useful in diff
The [`update`](#updating-rows) and [`delete`](#deleting-rows) functions follow similar patterns.
400
400
401
401
> _Note:_ If `insert` is called without any arguments, the statement will run with a `DEFAULT VALUES` clause. The table must not have any constraints that aren’t fulfilled by default values.
402
-
>
402
+
>
403
403
> ``` swift
404
404
> timestamps.insert()!
405
405
>// INSERT INTO "timestamps" DEFAULT VALUES
@@ -790,7 +790,7 @@ Like [`insert`](#inserting-rows) (and [`delete`](#updating-rows)), `update` can
The `alter` function shares several of the same [`column` function parameters](#column-constraints) used when [creating tables](#creating-a-table).
898
-
898
+
899
899
- `check` attaches a `CHECK` constraint to a column definition in the form of a boolean expression (`Expression<Bool>`). (See also the `check` function under [Table Constraints](#table-constraints).)
900
900
901
901
``` swift
@@ -904,14 +904,14 @@ The `alter` function shares several of the same [`column` function parameters](#
904
904
// ALTER TABLE "users"
905
905
// ADD COLUMN "suffix" TEXT CHECK ("suffix" IN ('JR', 'SR'))
906
906
```
907
-
907
+
908
908
- `defaultValue` adds a `DEFAULT` clause to a column definition and _only_ accepts a value matching the column’s type. This value is used if none is explicitly provided during [an `INSERT`](#inserting-rows).
// ALTER TABLE "users" ADD COLUMN "suffix" TEXT DEFAULT 'SR'
913
913
```
914
-
914
+
915
915
> _Note:_ Unlike the [`CREATE TABLE` constraint](#table-constraints), default values may not be expression structures (including `CURRENT_TIME`, `CURRENT_DATE`, or `CURRENT_TIMESTAMP`).
916
916
917
917
<!-- FIXME
@@ -935,7 +935,7 @@ The `alter` function shares several of the same [`column` function parameters](#
935
935
```
936
936
937
937
938
-
### Indexes
938
+
### Indexes
939
939
940
940
941
941
#### Creating Indexes
@@ -1303,4 +1303,4 @@ We can log SQL using the database’s `trace` function.
0 commit comments