To use Swift-Kuery-SQLite you must install SQLite.
You can install SQLite with Homebrew:
$ brew install sqlite
Or, if you prefer MacPorts, you can use that too, though note that you need to symlink a file into the place that Homebrew installs it:
$ port install sqlite3 $ mkdir -p /usr/local/opt/sqlite/include $ ln -s /opt/local/include/sqlite3.h /usr/local/opt/sqlite/include/
$ sudo apt-get install sqlite3 libsqlite3-dev
Swift-Kuery-SQLite package to the dependencies within your application’s
Package.swift file. Substitute
"x.x.x" with the latest
.package(url: "https://github.com/IBM-Swift/Swift-Kuery-SQLite.git", from: "x.x.x")
SwiftKuerySQLite to your target's dependencies:
.target(name: "example", dependencies: ["SwiftKuerySQLite"]),
First create an instance of
Swift-Kuery-SQLite by calling:
let connection = SQLiteConnection(filename: "myDB.db")
You don't have to pass a filename, if you choose not to pass in a filename then your database will be in-memory.
To establish a connection call:
connection.connect(onCompletion: (QueryError?) -> ())
If you want to have multiple connections to your database you can create a
ConnectionPool as follows:
let pool = SQLiteConnection.createPool(filename: "myDB.db", poolOptions: ConnectionPoolOptions(initialCapacity: 10, maxCapacity: 30, timeout: 10000)) let connection = pool.getConnection()
Note, you don't have to pass a filename to the
createPool method, if you choose not to pass in a filename then your pool will be shared in-memory.
You now have a connection that can be used to execute SQL queries created using Swift-Kuery. View the Kuery documentation for more information, or see the Database Connectivity with Kuery chapter of the Kitura Until Dawn guidebook/tutorial.
For more information visit our API reference.
We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!
This library is licensed under Apache 2.0. Full license text is available in LICENSE.