gloss-ios/ScrollStateRequest.swift

37 lines
1.2 KiB
Swift
Raw Normal View History

2023-04-21 17:06:30 -07:00
import Combine
import GRDB
import GRDBQuery
struct ScrollStateRequest: Queryable {
// enum Ordering {
// case byScore
// case byName
// }
/// The ordering used by the player request.
// var ordering: Ordering
static var defaultValue: [Ribbon] { [] }
func publisher(in appDatabase: AppDatabase) -> AnyPublisher<[Ribbon], Error> {
// Build the publisher from the general-purpose read-only access
// granted by `appDatabase.reader`.
// Some apps will prefer to call a dedicated method of `appDatabase`.
ValueObservation
.tracking(fetchValue(_:))
.publisher(
in: appDatabase.reader,
// The `.immediate` scheduling feeds the view right on
// subscription, and avoids an undesired animation when the
// application starts.
scheduling: .immediate)
.eraseToAnyPublisher()
}
// This method is not required by Queryable, but it makes it easier
func fetchValue(_ db: Database) throws -> [Ribbon] {
var ret = try Ribbon.fetchAll(db, sql: "SELECT * FROM ScrollState LIMIT 1") // [Player]
// print(ret)
return ret
}
}