Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CAT-295] Database 테이블 존재 여부 확인 #49

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
/// Use delete<T: Object>(_ type:).
public var deleteAllTable: @Sendable () async throws -> Void

public var checkHasTable: @Sendable () async throws -> Bool

public func create<T: Persistable>(object: T) async throws {
try await create(object)
}
Expand Down Expand Up @@ -67,14 +69,14 @@
public static var realmActor: RealmActor?

public actor RealmActor {
public var realm: Realm!

Check warning on line 72 in Projects/Core/DatabaseClient/Interface/DatabaseClientInterface.swift

View workflow job for this annotation

GitHub Actions / Run Swiftlint

Implicitly unwrapped optionals should be avoided when possible (implicitly_unwrapped_optional)

public init(configuration: Realm.Configuration) async throws {
realm = try await Realm(configuration: configuration, actor: self)
}

func convertToPersistable<T: Persistable>(type: T.Type, objects: [Object]) -> [T] {
return objects.compactMap { type.init(managedObject: $0 as! T.ManagedObject) }

Check warning on line 79 in Projects/Core/DatabaseClient/Interface/DatabaseClientInterface.swift

View workflow job for this annotation

GitHub Actions / Run Swiftlint

Force casts should be avoided (force_cast)
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions Projects/Core/DatabaseClient/Sources/DatabaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
read: { type in
if let realmActor {
let results = await realmActor.read(type as! Object.Type)

Check warning on line 34 in Projects/Core/DatabaseClient/Sources/DatabaseClient.swift

View workflow job for this annotation

GitHub Actions / Run Swiftlint

Force casts should be avoided (force_cast)
return results
} else {
throw(NSError(domain: "Realm is not initialized", code: 0))
Expand Down Expand Up @@ -79,6 +79,13 @@
} else {
throw(NSError(domain: "Realm is not initialized", code: 0))
}
},
checkHasTable: {
if let realmActor {
await realmActor.checkHasTable()
} else {
throw(NSError(domain: "Realm is not initialized", code: 0))
}
}
)
}
Expand Down Expand Up @@ -135,4 +142,8 @@
realm.deleteAll()
}
}

public func checkHasTable() -> Bool{

Check warning on line 146 in Projects/Core/DatabaseClient/Sources/DatabaseClient.swift

View workflow job for this annotation

GitHub Actions / Run Swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
return !realm.isEmpty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public struct MyPageCore {
@Dependency(APIClient.self) var apiClient
@Dependency(UserService.self) var userService
@Dependency(UserDefaultsClient.self) var userDefaultsClient
@Dependency(NetworkTracking.self) var networkTracking

public init() {}

Expand Down
Loading