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: sqlite-cloud/sdks/swift/introduction.mdx
+28-42Lines changed: 28 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,71 +6,59 @@ status: publish
6
6
slug: sdk-swift-introduction
7
7
---
8
8
9
-
This powerful package provides methods that perform DB operations and enables real-time notifications in Swift apps, making it easier than ever to work with SQLite in the cloud. We encourage all users to log encountered issues in the [SDK's issues backlog](https://github.com/sqlitecloud/sqlitecloud-swift/issues).
9
+
This powerful package provides methods that perform DB operations, and enables real-time notifications in Swift apps, making it easier than ever to work with SQLite in the cloud. We encourage all users to log encountered issues in the [SDK's issues backlog](https://github.com/sqlitecloud/sqlitecloud-swift/issues).
10
10
11
11
## Install
12
12
13
-
- In `Package.swift`, add the `swift` package to `dependencies`.
14
-
- The following example snippet is from a Swift app using the Vapor framework.
13
+
- In `Package.swift`, add the `swift` package to `dependencies`.
let sqliteCloud: SQLiteCloud =SQLiteCloud(config: configuration)
51
-
52
-
do {
53
-
tryawait sqliteCloud.connect()
54
-
debugPrint("connected")
33
+
let configuration =SQLiteCloudConfig(connectionString: "<your-connection-string>")
34
+
```
55
35
56
-
let sqlQuery: String="USE DATABASE chinook.sqlite; SELECT albums.AlbumId as id, albums.Title as title, artists.name as artist FROM albums INNER JOIN artists WHERE artists.ArtistId = albums.ArtistId LIMIT 20;"
36
+
2. Use a parameterized connection string.
57
37
58
-
let result: SQLiteCloudResult =tryawait sqliteCloud.execute(query: sqlQuery)
38
+
- In your SQLite Cloud account dashboard, click on a Node, copy the Deployment string, and replace `{hostname}` below.
39
+
- In your dashboard left nav, select Settings, then Users. Copy your username and replace `{username}`.
40
+
- In your User's row, click the down chevron, then Edit. Enter a Password and Save. Replace `{password}`.
41
+
- The provided port and database will query the sample dataset that comes pre-loaded with SQLite Cloud. Replace both for your own datasets.
59
42
60
-
tryawait sqliteCloud.disconnect()
43
+
```swift
44
+
let configuration =SQLiteCloudConfig(connectionString: "sqlitecloud://{username}:{password}@{hostname}:8860/chinook.sqlite")
45
+
```
46
+
47
+
3. Pass each connection string parameter.
61
48
62
-
return result.stringValue!
63
-
} catch {
64
-
return"Connection error: \(error)"
65
-
}
49
+
```swift
50
+
let configuration =SQLiteCloudConfig(hostname: {hostname}, username: {username}, password: {password}, port: .default)
66
51
```
67
52
68
-
-2. Using a connection string: `SQLiteCloudConfig(connectionString: "sqlitecloud://{username}:{password}@{hostname}:{port}/{database})`
53
+
## Connect and query
54
+
55
+
- The following snippet includes variable types, which may be optional for your app.
56
+
- Once you've incorporated the following, build and run your app!
69
57
70
58
```swift
71
59
importSQLiteCloud
72
60
73
-
let configuration: SQLiteCloudConfig?=SQLiteCloudConfig(connectionString: "sqlitecloud://{username}:{password}@{hostname}:8860/chinook.sqlite")
61
+
let configuration: SQLiteCloudConfig?=SQLiteCloudConfig(connectionString: "<your-connection-string>")
74
62
75
63
let sqliteCloud: SQLiteCloud =SQLiteCloud(config: configuration!)
76
64
@@ -86,12 +74,10 @@ do {
86
74
87
75
return result.stringValue!
88
76
} catch {
89
-
return"Connection error: \(error)"
77
+
return"Connection error"
90
78
}
91
79
```
92
80
93
-
- The above snippets include variable types, which may be optional for your app.
94
-
95
81
## Troubleshooting
96
82
97
83
- If you get errors indicating SQLite Cloud-specific constructs are out of scope (i.e. `error: cannot find 'SQLiteCloudConfig' in scope`), verify the `SQLiteCloud` package is correctly imported.
0 commit comments