ios – Establishing a Learn-Write connection to a database in SQLite.swift


I am working a undertaking the place I want to make use of a SQLite database to learn, create , and edit completely different objects. I believed I had established the connection correctly however, it seems I had solely established a learn solely connection. How do I modify this code to be a read-write connection utilizing SQLite.swift

import Basis
import SQLite
import UIKit

let path = Bundle.fundamental.path(forResource: "Assignment2", ofType: "sqlite3")
//Array of buyer structs to populate the desk
var customerArray: [Customer] = []

class CustomerPageVC: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var addCustButton: UIButton!

override func viewDidLoad() {
    //Further Setup
    do {
        //Seek for DB in paperwork listing
        let db = attempt Connection(path!)
        let clients = Desk("Clients")
        //Outline the columns of the desk as expressions
        let id = Expression<Int64>("CustomerID")
        let title = Expression<String>("CustomerName")
        let contactName = Expression<String>("ContactName")
        let deal with = Expression<String>("Handle")
        let metropolis = Expression<String>("Metropolis")
        let postalCode = Expression<String>("PostalCode")
        let nation = Expression<String>("Nation")
        //Load the info from db file into customerArray
        for buyer in attempt db.put together(clients) {
            let cust = Buyer(Int(customer, buyer[name], buyer[contactName], buyer[address], buyer[city], buyer[postalCode], buyer[country])
    catch {
    tableView.delegate = self
    tableView.dataSource = self

You could find the documentation for SQLite.swift right here


Please enter your comment!
Please enter your name here