November 2018
Intermediate to advanced
404 pages
10h 16m
English
In Application.swift, create an instance of PostgreSQL data in the postInit() method:
func postInit() throws { //... let poolOptions = ConnectionPoolOptions(initialCapacity: 1, maxCapacity: 5, timeout: 10000) // Set up database connection let psqlPool = PostgreSQLConnection.createPool(host: "localhost", port: 5432, options: [.databaseName("journalbook")], poolOptions: poolOptions) Database.default = Database(psqlPool) do { try JournalItem.createTableSync() } catch let error { Log.error("Failed to create table in database: \(error)") }}
You've used the same database code before, in Chapter 8, Employing Storage Framework. The preceding code will attempt to create a table for JournalItem. If there is an existing table ...
Read now
Unlock full access