Skip to content

Commit

Permalink
[CAT-295] Database 테이블 존재 여부 확인 (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
devMinseok authored Aug 21, 2024
1 parent c88b8d9 commit 5460b83
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public struct DatabaseClient {
/// 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
11 changes: 11 additions & 0 deletions Projects/Core/DatabaseClient/Sources/DatabaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ extension DatabaseClient: DependencyKey {
} 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 @@ extension DatabaseClient.RealmActor {
realm.deleteAll()
}
}

public func checkHasTable() -> Bool{
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

0 comments on commit 5460b83

Please sign in to comment.