So I was able to do a tutorial to create one table but when I try to create another one, it doesn't show up in the DB Browser for SQLite which makes me think that it is not created.
Is there a way to make multiple tables within the same DB Management class?
// Creating DB connection
db = try Connection("/blahblahblah/harmonyMoodDB.sqlite3")
// Creating table object
meds = Table("medications")
// Create instances of each column
medID = Expression<Int64>("id")
name = Expression<String>("name")
dosage = Expression<Int64>("dosage")
if (!UserDefaults.standard.bool(forKey: "is_db_created")) {
// If not, then create the table
try db.run(meds.create { (t) in
t.column(medID, primaryKey: true)
t.column(name)
t.column(dosage)
})
// Set the value to true, so it will not attempt to create the table again
UserDefaults.standard.set(true, forKey: "is_db_created")
}
// Creating table object
users = Table("users")
// Create instances of each column
userID = Expression<Int64>("userID")
userName = Expression<String>("userName")
if (!UserDefaults.standard.bool(forKey: "is_db_created")) {
// If not, then create the table
try db.run(users.create { (t) in
t.column(userID, primaryKey: true)
t.column(userName)
})
// Set the value to true, so it will not attempt to create the table again
UserDefaults.standard.set(true, forKey: "is_db_created")
}
}
catch {
// Show error message (if any)
print(error.localizedDescription)
}
} // End of init
Where am I going wrong here?