To use Swift-Kuery-SQLite you need to first install SQLite:
On macOS we can use Homebrew to install SQLite:
brew install sqlite
On Linux we can use
apt-get to install SQLite:
sudo apt-get install sqlite3 libsqlite3-dev
Now that we have SQLite installed we can create a database file.
In terminal return to your home directory:
Use the SQL command line to create your database:
Remaining in the command line, create an SQL table:
CREATE TABLE BookTable ( id varchar(100) primary key, title text, price real, genre text );
Control-d to exit SQLite.
Now we're ready to connect to our database from our Kitura server.
Inside the file which defines the routes,
KueryRoutes.swift, import the SwiftKuery and SwiftKuerySQLite packages:
import SwiftKuery import SwiftKuerySQLite
App extension, create a connection pool by passing in the path to your database file:
static let path = NSString(string: "~/bookstoredb.sqlite").expandingTildeInPath static let poolOptions = ConnectionPoolOptions(initialCapacity: 1, maxCapacity: 5) static let pool = SQLiteConnection.createPool(filename: String(path), poolOptions: poolOptions) // Create table instance here
This creates a pool of connections for us to use to make requests to our database.
Now you can return to the Swift-Kuery guide.