Skip to content

0xLeif/FLiteLaterPOC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FLite and Later POC

FLiteStore

class FLiteStore: ObservableObject {
    public var memory = FLite(loggerLabel: "memory-FLITE")
    public var persist = FLite(configuration: .file("\(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path ?? "")/default.sqlite"), loggerLabel: "persisted-FLITE")
}

FLiteLaterPOCApp

@main
struct FLiteLaterPOCApp: App {
    let store = FLiteStore()

    var body: some Scene {
        WindowGroup {
            NavigationView {
                ContentView()
                    .environmentObject(store)
            }
            .onAppear {
                print("Starting to prepare...")
                try? store.persist.prepare(migration: Planet.self).wait()
                print("Prepared Migrations")
            }
        }
    }
}

Later Usage

.navigationBarItems(
    leading: Button("Delete All") {
        Later.whenAllSucceed(
            items.map {
                store.persist.delete(model: $0)
            }
        )
        .flatMap { _ in store.persist.all(model: Planet.self) }
        .whenSuccess { items = $0 }
    },
    trailing: Button("100") {
        Later.whenAllSucceed(
            (0 ... 99).map { _ in
                store.persist.add(model: Planet.random)
            }
        )
        .flatMap { _ in store.persist.all(model: Planet.self) }
        .whenSuccess { items = $0 }
    }
)

Example Video

About

FLite and Later POC

Topics

Resources

License

Stars

Watchers

Forks

Languages