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
+52-19Lines changed: 52 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,12 @@ status: publish
6
6
slug: sdk-swift-introduction
7
7
---
8
8
9
-
This powerful package provides methods that perform database operations and enable real-time notifications in Swift apps, making it easier than ever to work with SQLite in the cloud.
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`. The following example snippet is from a project using the Vapor framework.
13
+
- In `Package.swift`, add the `swift` package to `dependencies`.
14
+
- The following example snippet is from a Swift app using the Vapor framework.
14
15
15
16
```swift
16
17
letpackage=Package(
@@ -34,32 +35,64 @@ let package = Package(
34
35
35
36
## Basic Usage
36
37
37
-
-
38
+
- Currently, there are 2 ways to configure your database connection:
let sqliteCloud: SQLiteCloud =SQLiteCloud(config: configuration)
51
+
52
+
do {
53
+
tryawait sqliteCloud.connect()
54
+
debugPrint("connected")
55
+
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;"
57
+
58
+
let result: SQLiteCloudResult =tryawait sqliteCloud.execute(query: sqlQuery)
59
+
60
+
tryawait sqliteCloud.disconnect()
61
+
62
+
return result.stringValue!
63
+
} catch {
64
+
return"Connection error: \(error)"
65
+
}
44
66
```
45
67
46
-
```python
47
-
import sqlitecloud
68
+
-2. Using a connection string: `SQLiteCloudConfig(connectionString: "sqlitecloud://{username}:{password}@{hostname}:{port}/{database})`
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;"
58
82
59
-
cursor = conn.execute("SELECT * FROM albums WHERE AlbumId = ?", (1, ))
60
-
result = cursor.fetchone()
83
+
let result: SQLiteCloudResult =tryawait sqliteCloud.execute(query: sqlQuery)
61
84
62
-
print(result)
85
+
tryawait sqliteCloud.disconnect()
63
86
64
-
conn.close()
87
+
return result.stringValue!
88
+
} catch {
89
+
return"Connection error: \(error)"
90
+
}
65
91
```
92
+
93
+
- The above snippets include variable types, which may be optional for your app.
94
+
95
+
## Troubleshooting
96
+
97
+
- 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.
98
+
- Confirm `https://github.com/sqlitecloud/swift` package is listed in `Package.resolved`.
0 commit comments