mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-03 09:34:51 +02:00
Added realm
This commit is contained in:
parent
2f4b3050fd
commit
c0ac3b7bb5
14 changed files with 19001 additions and 377 deletions
32
ios/App/Shared/util/Database.swift
Normal file
32
ios/App/Shared/util/Database.swift
Normal file
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue