mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-27 20:01:27 +01:00
Support typed errors. Misc formatting
This commit is contained in:
@@ -17,6 +17,12 @@ class Animal: CoreStoreObject {
|
||||
var master: Person?
|
||||
}
|
||||
|
||||
class Dog: Animal {
|
||||
|
||||
@Field.Stored("name")
|
||||
var name: String = ""
|
||||
}
|
||||
|
||||
class Person: CoreStoreObject {
|
||||
|
||||
@Field.Stored("name")
|
||||
@@ -33,16 +39,20 @@ let dataStack = DataStack(
|
||||
modelVersion: "V1",
|
||||
entities: [
|
||||
Entity<Animal>("Animal"),
|
||||
Entity<Person>("Person")
|
||||
],
|
||||
Entity<Person>("Person"),
|
||||
Entity<Dog>("Dog")
|
||||
]/*,
|
||||
versionLock: [
|
||||
"Animal": [0x4a201cc685d53c0a, 0x16e6c3b561577875, 0xb032e2da61c792a0, 0xa133b801051acee4],
|
||||
"Person": [0xca938eea1af4bd56, 0xbca30994506356ad, 0x7a7cc655898816ef, 0x1a4551ffedc9b214]
|
||||
]
|
||||
]*/
|
||||
)
|
||||
)
|
||||
dataStack.addStorage(
|
||||
SQLiteStore(fileName: "data.sqlite"),
|
||||
SQLiteStore(
|
||||
fileName: "data.sqlite",
|
||||
localStorageOptions: .recreateStoreOnModelMismatch
|
||||
),
|
||||
completion: { result in
|
||||
|
||||
switch result {
|
||||
@@ -73,8 +83,8 @@ dataStack.addStorage(
|
||||
case .success:
|
||||
/// Accessing Objects =====
|
||||
let bird = try! dataStack.fetchOne(
|
||||
From<Animal>()
|
||||
.where(\.$species == "Sparrow")
|
||||
From<Dog>()
|
||||
.where(\Dog.$species == "Sparrow")
|
||||
)!
|
||||
print(bird.species)
|
||||
print(bird.color as Any)
|
||||
|
||||
Reference in New Issue
Block a user