|
19 | 19 |
|
20 | 20 | Download the appropriate pre-built binary for your platform from the [Releases](https://github.com/sqliteai/sqlite-agent/releases) page: we do support **Linux**, **macOS**, **Windows**, **Android** and **iOS**. |
21 | 21 |
|
| 22 | +#### Swift Package |
| 23 | + |
| 24 | +You can [add this repository as a package dependency to your Swift project](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app#Add-a-package-dependency). After adding the package, you'll need to set up SQLite with extension loading by following steps 4 and 5 of [this guide](https://github.com/sqliteai/sqlite-extensions-guide/blob/main/platforms/ios.md#4-set-up-sqlite-with-extension-loading). |
| 25 | + |
| 26 | +Here's an example of how to use the package: |
| 27 | +```swift |
| 28 | +import agent |
| 29 | + |
| 30 | +... |
| 31 | + |
| 32 | +var db: OpaquePointer? |
| 33 | +sqlite3_open(":memory:", &db) |
| 34 | +sqlite3_enable_load_extension(db, 1) |
| 35 | +var errMsg: UnsafeMutablePointer<Int8>? = nil |
| 36 | +sqlite3_load_extension(db, agent.path, nil, &errMsg) |
| 37 | +var stmt: OpaquePointer? |
| 38 | +sqlite3_prepare_v2(db, "SELECT agent_version()", -1, &stmt, nil) |
| 39 | +defer { sqlite3_finalize(stmt) } |
| 40 | +sqlite3_step(stmt) |
| 41 | +log("agent_version(): \(String(cString: sqlite3_column_text(stmt, 0)))") |
| 42 | +sqlite3_close(db) |
| 43 | +``` |
| 44 | + |
| 45 | +#### Android Package |
| 46 | + |
| 47 | +Add the [following](https://central.sonatype.com/artifact/ai.sqlite/agent) to your Gradle dependencies: |
| 48 | + |
| 49 | +```gradle |
| 50 | +implementation 'ai.sqlite:agent:0.1.1' |
| 51 | +``` |
| 52 | + |
| 53 | +Here's an example of how to use the package: |
| 54 | +```java |
| 55 | +SQLiteCustomExtension agentExtension = new SQLiteCustomExtension(getApplicationInfo().nativeLibraryDir + "/agent", null); |
| 56 | +SQLiteDatabaseConfiguration config = new SQLiteDatabaseConfiguration( |
| 57 | + getCacheDir().getPath() + "/agent_test.db", |
| 58 | + SQLiteDatabase.CREATE_IF_NECESSARY | SQLiteDatabase.OPEN_READWRITE, |
| 59 | + Collections.emptyList(), |
| 60 | + Collections.emptyList(), |
| 61 | + Collections.singletonList(agentExtension) |
| 62 | +); |
| 63 | +SQLiteDatabase db = SQLiteDatabase.openDatabase(config, null, null); |
| 64 | +``` |
| 65 | + |
| 66 | +**Note:** Additional settings and configuration are required for a complete setup. For full implementation details, see the [complete Android example](https://github.com/sqliteai/sqlite-extensions-guide/blob/main/examples/android/README.md). |
| 67 | + |
22 | 68 | ### Basic Usage |
23 | 69 |
|
24 | 70 | ```sql |
|
0 commit comments