Пример #1
0
def test_postgres_sqlalchemy_uri(monkeypatch: MonkeyPatch) -> None:
    environment = {"DB_BACKEND": "postgresql", "DB_USER": "******", "DB_PASSWORD": "******", "DB_HOST": "c", "db_db": "d"}
    for k, v in environment.items():
        monkeypatch.setenv(k, v)

    clear_caches()
    assert get_database_settings().sqlalchemy_uri == "postgresql://*****:*****@c/d"
Пример #2
0
def pk_column(id_type: Optional[Type[IdentifierT]] = None) -> "Union[sa.Column[IdentifierT], sa.Column[UUID]]":
    """
    The server-default value should be updated in the metadata later
    """
    using_postgres = get_database_settings().backend == DatabaseBackend.postgresql
    default_kwargs: Dict[str, Any] = {"default": uuid4} if not using_postgres else {
        "server_default": sa.text("gen_random_uuid()")
    }
    return sa.Column(GUID, primary_key=True, index=True, **default_kwargs)
Пример #3
0
def json_column(*, nullable: bool) -> "sa.Column[Dict[str, Any]]":
    using_postgres = get_database_settings().backend == DatabaseBackend.postgresql
    column_type = JSONB() if using_postgres else sa.JSON()
    return sa.Column(column_type, nullable=nullable)  # type: ignore
Пример #4
0
def get_engine() -> sa.engine.Engine:
    db_settings = get_database_settings()
    uri = db_settings.sqlalchemy_uri
    log_sqlalchemy_sql_statements = db_settings.log_sqlalchemy_sql_statements
    database_backend = db_settings.backend
    return get_new_engine(uri, log_sqlalchemy_sql_statements, database_backend)
Пример #5
0
def test_db_settings(monkeypatch: MonkeyPatch, sqlalchemy_database_uri: str) -> None:
    monkeypatch.setenv("DB_SQLALCHEMY_URI", sqlalchemy_database_uri)

    clear_caches()
    assert get_database_settings().sqlalchemy_uri == sqlalchemy_database_uri