mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-06 20:08:48 +02:00
Added realm
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Database.swift
|
||||
// App
|
||||
//
|
||||
// Created by Rasmus Krämer on 11.04.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RealmSwift
|
||||
|
||||
class Database {
|
||||
public static let realmQueue = DispatchQueue(label: "realm-queue")
|
||||
|
||||
public static func setServerConnectionConfig(config: ServerConnectionConfig) {
|
||||
let realm = try! Realm(queue: realmQueue)
|
||||
let existing = realm.objects(ServerConnectionConfig.self)
|
||||
|
||||
try! realm.write {
|
||||
realm.delete(existing)
|
||||
realm.add(config)
|
||||
}
|
||||
}
|
||||
public static func getServerConnectionConfig() -> ServerConnectionConfig {
|
||||
let realm = try! Realm(queue: realmQueue)
|
||||
guard let config = realm.objects(ServerConnectionConfig.self).first else {
|
||||
let fallback = ServerConnectionConfig()
|
||||
return fallback
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Store.swift
|
||||
// App
|
||||
//
|
||||
// Created by Rasmus Krämer on 11.04.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RealmSwift
|
||||
|
||||
class Store {
|
||||
public static var serverConfig: ServerConnectionConfig {
|
||||
get {
|
||||
return Database.getServerConnectionConfig()
|
||||
}
|
||||
set(updated) {
|
||||
Database.setServerConnectionConfig(config: updated)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user