Added realm

This commit is contained in:
Rasmus Krämer 2022-04-11 16:29:19 +02:00
parent 2f4b3050fd
commit c0ac3b7bb5
No known key found for this signature in database
GPG key ID: EC9E510611BFDAA2
14 changed files with 19001 additions and 377 deletions

View file

@ -0,0 +1,31 @@
//
// ServerConnectionConfig.swift
// App
//
// Created by Rasmus Krämer on 11.04.22.
//
import Foundation
import RealmSwift
class ServerConnectionConfig: Object {
@Persisted var id: String
@Persisted var index: Int = 0
@Persisted var name: String
@Persisted var address: String
@Persisted var userId: String
@Persisted var username: String
@Persisted var token: String
}
func serverConnectionConfigToJSON(config: ServerConnectionConfig) -> Dictionary<String, Any> {
return [
"id": config.id,
"name": config.name,
"index": config.index,
"address": config.address,
"userId": config.userId,
"username": config.username,
"token": config.token,
]
}

View file

@ -0,0 +1,17 @@
//
// PlayerHandler.swift
// App
//
// Created by Rasmus Krämer on 11.04.22.
//
import Foundation
class PlayerHandler {
private static var player: AudioPlayer?
// private static var item: any
public static func setItem() {
}
}

View 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
}
}

View file

@ -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)
}
}
}