-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS][Local catalog] Create local database when POS tab is shown #16054
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
Changes from 5 commits
94c3625
283d7f6
9c6ce60
56fd217
79ce459
9790bd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,34 @@ | ||
| import Foundation | ||
| import GRDB | ||
|
|
||
| // TODO: remove ignore when we start using this | ||
| // periphery: ignore | ||
| public final class GRDBManager { | ||
| public protocol GRDBManagerProtocol { | ||
| var databaseConnection: GRDBDatabaseConnection { get } | ||
| } | ||
|
|
||
| let databaseQueue: DatabaseQueue | ||
| private let databasePath: String | ||
| public protocol GRDBDatabaseConnection: DatabaseReader & DatabaseWriter {} | ||
|
|
||
| public init(databasePath: String) throws { | ||
| self.databasePath = databasePath | ||
| public final class GRDBManager: GRDBManagerProtocol { | ||
|
|
||
| public var databaseConnection: GRDBDatabaseConnection | ||
|
|
||
| public init(databasePath: String) throws { | ||
| let databaseURL = URL(fileURLWithPath: databasePath) | ||
| let directoryURL = databaseURL.deletingLastPathComponent() | ||
|
|
||
| try FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: true, attributes: nil) | ||
|
|
||
| self.databaseQueue = try DatabaseQueue(path: databasePath) | ||
| self.databaseConnection = try DatabaseQueue(path: databasePath) | ||
|
Comment on lines
-19
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just curious, is this renaming to make it more flexible if we ever decide to switch to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, and to make it mockable – the protocol requirement is |
||
|
|
||
| try migrateIfNeeded() | ||
| } | ||
|
|
||
| // Creates an in-memory database, intended for use in tests. | ||
| init() throws { | ||
| self.databasePath = "in-memory" | ||
| self.databaseQueue = try DatabaseQueue() | ||
| self.databaseConnection = try DatabaseQueue() | ||
| try migrateIfNeeded() | ||
| } | ||
| } | ||
|
|
||
| // TODO: remove ignore when we start using this | ||
| // periphery: ignore | ||
| private extension GRDBManager { | ||
| func migrateIfNeeded() throws { | ||
| var migrator = DatabaseMigrator() | ||
|
|
@@ -43,6 +42,8 @@ private extension GRDBManager { | |
| try V001InitialSchema.migrate(db) | ||
| } | ||
|
|
||
| try migrator.migrate(databaseQueue) | ||
| try migrator.migrate(databaseConnection) | ||
| } | ||
| } | ||
|
|
||
| extension DatabaseQueue: GRDBDatabaseConnection {} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could this be let? do we plan to change the connection once it's initialized?