Skip to content

Commit f854c20

Browse files
committed
Started Swift Introduction
1 parent 6681662 commit f854c20

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

sqlite-cloud/_nav.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ const sidebarNav: SidebarNavStruct = [
163163
{ title: 'Introduction', type: "inner", filePath: "sdk-php-introduction", level: 1 },
164164
{ title: "Methods", filePath: "sdk-php-methods", type: "inner", level: 1 },
165165

166+
{ title: "Swift", type: "inner", level: 0 },
167+
{ title: 'Introduction', type: "inner", filePath: "sdk-swift-introduction", level: 1 },
168+
166169
{ title: "Reference", type: "secondary", icon: "docs-ref" },
167170
{ title: "Server-side Commands", type: "inner", level: 0 },
168171
{ title: "Introduction", filePath: "server-side-commands", type: "inner", level: 1 },
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: Swift SDK Introduction
3+
description: Get started with SQLite Cloud using Swift.
4+
category: sdks
5+
status: publish
6+
slug: sdk-swift-introduction
7+
---
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.
10+
11+
## Install
12+
13+
- In `Package.swift`, add the `swift` package to `dependencies`. The following example snippet is from a project using the Vapor framework.
14+
15+
```swift
16+
let package = Package(
17+
...
18+
dependencies: [
19+
...
20+
.package(url: "https://github.com/sqlitecloud/swift.git", from: "0.2.1")
21+
],
22+
targets: [
23+
.executableTarget(
24+
...
25+
dependencies: [
26+
...
27+
.product(name: "SQLiteCloud", package: "swift")
28+
],
29+
...
30+
),
31+
]
32+
)
33+
```
34+
35+
## Basic Usage
36+
37+
-
38+
39+
```swift
40+
import SQLiteCloud
41+
42+
# explicit
43+
let configuration = SQLiteCloudConfig(hostname: "<see-project-deployment>", username: "<see-settings-users>", password: "<edit-your-user>", port: .default)
44+
```
45+
46+
```python
47+
import sqlitecloud
48+
49+
# Open the connection to SQLite Cloud
50+
conn = sqlitecloud.connect("sqlitecloud://myhost.sqlite.cloud:8860?apikey=myapikey")
51+
52+
# You can autoselect the database during the connect call
53+
# by adding the database name as path of the SQLite Cloud
54+
# connection string, eg:
55+
# conn = sqlitecloud.connect("sqlitecloud://myhost.sqlite.cloud:8860/mydatabase?apikey=myapikey")
56+
db_name = "chinook.sqlite"
57+
conn.execute(f"USE DATABASE {db_name}")
58+
59+
cursor = conn.execute("SELECT * FROM albums WHERE AlbumId = ?", (1, ))
60+
result = cursor.fetchone()
61+
62+
print(result)
63+
64+
conn.close()
65+
```

0 commit comments

Comments
 (0)