Skip to content

Commit

Permalink
Some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
horia141 committed Feb 26, 2024
1 parent 9fa0864 commit f0fdd71
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/cli/jupiter/cli/migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ async def main() -> None:
# ],
# )

ModuleExplorerRealmCodecRegistry.build_from_module_root(
jupiter.core.domain
)
ModuleExplorerRealmCodecRegistry.build_from_module_root(jupiter.core.domain)

global_properties = build_global_properties()

Expand Down
52 changes: 50 additions & 2 deletions src/core/jupiter/core/repository/sqlite/domain/storage_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import (
AsyncIterator,
Final,
Generic,
Iterator,
Optional,
Type,
Expand Down Expand Up @@ -171,6 +172,27 @@ def get_for(
)


class _StandardSqliteRootEntityRepository(
Generic[_RootEntityT],
SqliteEntityRepository[_RootEntityT],
RootEntityRepository[_RootEntityT],
):
"""A standard repository for root entities."""

_the_type: type[_RootEntityT]

def __init__(
self,
realm_codec_registry: RealmCodecRegistry,
connection: AsyncConnection,
metadata: MetaData,
the_type: type[_RootEntityT],
) -> None:
"""Constructor."""
super().__init__(realm_codec_registry, connection, metadata)
self._the_type = the_type


class SqliteDomainStorageEngine(DomainStorageEngine):
"""An Sqlite specific engine."""

Expand Down Expand Up @@ -332,6 +354,19 @@ def extract_repositories(
)
yield abstract_repository_type, obj

def extract_entities(
the_module: ModuleType,
) -> Iterator[type[Entity]]:
for _name, obj in the_module.__dict__.items():
if not (isinstance(obj, type) and issubclass(obj, Entity)):
continue

if obj.__module__ != the_module.__name__:
# This is an import, and not a definition!
continue

yield obj

entity_repository_factories = {}
repository_factories: dict[type[Repository], type[SqliteRepository]] = {}

Expand Down Expand Up @@ -369,8 +404,21 @@ def extract_repositories(
] = concrete_repository_type

# look at all entities and build repositories for them

# look at all records and build repositories for them
for entity_type in extract_entities(m):
if entity_type in entity_repository_factories:
continue
if issubclass(entity_type, RootEntity):
entity_repository_factories[entity_type] = type(
f"_StandardSqliteRootEntityRepository_{entity_type.__name__}",
(_StandardSqliteRootEntityRepository,),
{
"__init__": lambda self, realm_codec_registry, connection, metadata: super(
_StandardSqliteRootEntityRepository, self
).__init__(
realm_codec_registry, connection, metadata, entity_type
)
},
)

return SqliteDomainStorageEngine(
realm_codec_registry,
Expand Down

0 comments on commit f0fdd71

Please sign in to comment.