Skip to content

Sharing database classes across modules feels improvable #23

@DrewLazzeriKitware

Description

@DrewLazzeriKitware

Both the file database and the key database are used throughout the app, and both depend on the output of the CommandValidator for instantiation.

Current approach

Both databases use this singleton decorator to make their instance available to all modules like this:

from FileDatabase import FileDatabase
FileDatabase().foo()

Except in app.py, where it's defined like:

FILEDB = None
...
FILEDB = FileDatabase(data_dir)

Cons

We must be careful to instantiate the FileDatabase() with its parameters before any of these calls happen or we'll get a confusing error.

We reference the database in different ways in different modules.

Other approaches

  1. Attach to trame state object state._filedb = FileDatabase(work_dir) throws error on attempting serialization
  2. Inject databases into widgets that need them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions