Skip to content
Open
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
24 changes: 13 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ on:
jobs:
label-gate:
uses: AustralianCancerDataNetwork/cava-devops/.github/workflows/label-gate.yml@main
build-test:
uses: AustralianCancerDataNetwork/cava-devops/.github/workflows/build-test-postgres.yml@main
build-test-sqlite:
uses: AustralianCancerDataNetwork/cava-devops/.github/workflows/build-test.yml@main
build-test-postgres:
uses: AustralianCancerDataNetwork/cava-devops/.github/workflows/build-test-postgres-v2.yml@main
with:
postgres-db: orm_loader_test
setup-commands: |
uv run omop-config configure orm_loader \
--set test_orm_db.kind=cdm \
--set test_orm_db.connection.dialect=postgresql+psycopg \
--set test_orm_db.connection.host=localhost \
--set test_orm_db.connection.port=5432 \
--set test_orm_db.connection.user=test \
--set test_orm_db.connection.password=test \
--set test_orm_db.connection.database_name=orm_loader_test \
--set test_orm_db.connection.test_only=true \
--set test_orm_db.schema_name=public
--set test_orm_db_pg.kind=cdm \
--set test_orm_db_pg.connection.dialect=postgresql+psycopg \
--set test_orm_db_pg.connection.host=localhost \
--set test_orm_db_pg.connection.port=5432 \
--set test_orm_db_pg.connection.user=test \
--set test_orm_db_pg.connection.password=test \
--set test_orm_db_pg.connection.database_name=orm_loader_test \
--set test_orm_db_pg.connection.test_only=true \
--set test_orm_db_pg.schema_name=public
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ testpaths = ["tests"]
python_files = ["test_*.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = "-ra"
addopts = "-ra -m 'not db_dialect'"

[tool.pyright]
reportMissingTypeStubs = false
9 changes: 7 additions & 2 deletions src/orm_loader/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from .postgres import PostgresBackend
from .resolve import resolve_backend
from .sqlite import SQLiteBackend
from .base import BackendCapabilities, DatabaseBackend, STAGING_SCHEMA, Dialect
from .base import (
BackendCapabilities,
DatabaseBackend,
Dialect,
STAGING_SCHEMA,
)

__all__ = [
"BackendCapabilities",
"DatabaseBackend",
"STAGING_SCHEMA",
"Dialect",
"PostgresBackend",
"STAGING_SCHEMA",
"SQLiteBackend",
"resolve_backend",
]
29 changes: 16 additions & 13 deletions src/orm_loader/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from abc import ABC, abstractmethod
from contextlib import AbstractContextManager, contextmanager, nullcontext
from dataclasses import dataclass
from enum import Enum
from collections.abc import Generator
from typing import TYPE_CHECKING, Type, Any

Expand All @@ -12,6 +11,8 @@
from sqlalchemy.engine import Connection, Engine
from sqlalchemy.sql.compiler import IdentifierPreparer

from oa_configurator import Dialect

if TYPE_CHECKING:
from ..loaders.data_classes import LoaderContext
from ..tables.typing import CSVTableProtocol
Expand All @@ -32,13 +33,6 @@ class BackendCapabilities:
supports_materialized_views: bool = False


class Dialect(str, Enum):
"""Supported SQLAlchemy dialect names."""

SQLITE = "sqlite"
POSTGRESQL = "postgresql"


STAGING_SCHEMA: str = "staging"


Expand Down Expand Up @@ -239,7 +233,6 @@ def merge_replace(
self,
table_cls: Type["CSVTableProtocol"],
session: so.Session,
target_name: str,
pk_cols: list[str],
*,
merge_batch_size: int | None = None,
Expand All @@ -251,7 +244,6 @@ def merge_upsert(
self,
table_cls: Type["CSVTableProtocol"],
session: so.Session,
target_name: str,
pk_cols: list[str],
*,
merge_batch_size: int | None = None,
Expand All @@ -263,7 +255,6 @@ def merge_insert(
self,
table_cls: Type["CSVTableProtocol"],
session: so.Session,
target_name: str,
*,
merge_batch_size: int | None = None,
) -> None:
Expand Down Expand Up @@ -315,13 +306,25 @@ def create_materialized_view(
bind: "Engine | Connection",
name: str,
selectable: sa.sql.Select[Any],
*,
schema: str | None = None,
) -> None:
"""Create a materialized view for the supplied selectable."""
"""Create a materialized view for the supplied selectable.

*schema* defaults to the bind's own ``schema_translate_map`` (via
``oa_configurator.schema_of``) when not given explicitly.
"""

@abstractmethod
def refresh_materialized_view(
self,
bind: "Engine | Connection",
name: str,
*,
schema: str | None = None,
) -> None:
"""Refresh a materialized view."""
"""Refresh a materialized view.

*schema* defaults to the bind's own ``schema_translate_map`` (via
``oa_configurator.schema_of``) when not given explicitly.
"""
Loading