Skip to content

Commit

Permalink
Rename YDB dialect&driver names
Browse files Browse the repository at this point in the history
  • Loading branch information
vgvoleg committed Dec 17, 2024
1 parent ff06640 commit 0ddabfe
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Functional tests](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/tests.yml/badge.svg)](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/tests.yml)
[![Style checks](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/style.yml/badge.svg)](https://github.com/ydb-platform/ydb-sqlalchemy/actions/workflows/style.yml)

This repository contains YQL dialect for SqlAlchemy 2.0.
This repository contains YDB dialect for SqlAlchemy 2.0.

**Note**: Dialect also works with SqlAlchemy 1.4, but it is not fully tested.

Expand All @@ -24,7 +24,7 @@ Connect to local YDB using SqlAlchemy:
import sqlalchemy as sa


engine = sa.create_engine("yql+ydb://localhost:2136/local")
engine = sa.create_engine("ydb://localhost:2136/local")

with engine.connect() as conn:
rs = conn.execute(sa.text("SELECT 1 AS value"))
Expand Down
2 changes: 1 addition & 1 deletion examples/alembic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ from alembic.ddl.impl import DefaultImpl
class YDBImpl(DefaultImpl):
__dialect__ = "yql"
__dialect__ = "ydb"
```

Secondly, since `YDB` do not support updating primary key columns, we have to update alembic table structure.
Expand Down
2 changes: 1 addition & 1 deletion examples/alembic/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = yql+ydb://localhost:2136/local
sqlalchemy.url = ydb+ydb_sync://localhost:2136/local


[post_write_hooks]
Expand Down
2 changes: 1 addition & 1 deletion examples/alembic/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


class YDBImpl(DefaultImpl):
__dialect__ = "yql"
__dialect__ = "ydb"


def run_migrations_offline() -> None:
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def run_example_core(engine):


def main():
engine = sa.create_engine("yql+ydb://localhost:2136/local")
engine = sa.create_engine("ydb+ydb_sync://localhost:2136/local")

logging.basicConfig(level=logging.INFO)
logging.getLogger("_sqlalchemy.engine").setLevel(logging.INFO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@
"source": [
"import sqlalchemy as sa\n",
"\n",
"engine = sa.create_engine(\"yql+ydb://localhost:2136/local\")\n",
"engine = sa.create_engine(\"ydb+ydb_sync://localhost:2136/local\")\n",
"conn = engine.connect()"
]
},
Expand Down Expand Up @@ -933,10 +933,10 @@
{
"data": {
"text/html": [
"<span style=\"None\">Running query in &#x27;yql+ydb://localhost:2136/local&#x27;</span>"
"<span style=\"None\">Running query in &#x27;ydb+ydb_sync://localhost:2136/local&#x27;</span>"
],
"text/plain": [
"Running query in 'yql+ydb://localhost:2136/local'"
"Running query in 'ydb+ydb_sync://localhost:2136/local'"
]
},
"metadata": {},
Expand Down Expand Up @@ -1078,10 +1078,10 @@
{
"data": {
"text/html": [
"<span style=\"None\">Running query in &#x27;yql+ydb://localhost:2136/local&#x27;</span>"
"<span style=\"None\">Running query in &#x27;ydb+ydb_sync://localhost:2136/local&#x27;</span>"
],
"text/plain": [
"Running query in 'yql+ydb://localhost:2136/local'"
"Running query in 'ydb+ydb_sync://localhost:2136/local'"
]
},
"metadata": {},
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ requirement_cls=ydb_sqlalchemy.sqlalchemy.requirements:Requirements
profile_file=test/profiles.txt

[db]
default=yql+ydb://localhost:2136/local
ydb=yql+ydb://localhost:2136/local
ydb_async=yql+ydb_async://localhost:2136/local
default=ydb+ydb_sync://localhost:2136/local
ydb=ydb+ydb_sync://localhost:2136/local
ydb_async=ydb+ydb_async://localhost:2136/local
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@
},
entry_points={
"sqlalchemy.dialects": [
"yql.ydb=ydb_sqlalchemy.sqlalchemy:YqlDialect",
"yql.ydb_async=ydb_sqlalchemy.sqlalchemy:AsyncYqlDialect",
"ydb_async=ydb_sqlalchemy.sqlalchemy:AsyncYqlDialect",
"ydb=ydb_sqlalchemy.sqlalchemy:YqlDialect",
"yql=ydb_sqlalchemy.sqlalchemy:YqlDialect",
"ydb=ydb_sqlalchemy.sqlalchemy:YDBDialect",
"ydb.ydb_sync=ydb_sqlalchemy.sqlalchemy:YDBDialect",
"ydb_async=ydb_sqlalchemy.sqlalchemy:AsyncYDBDialect",
"ydb.ydb_async=ydb_sqlalchemy.sqlalchemy:AsyncYDBDialect",
]
},
)
9 changes: 4 additions & 5 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import pytest
from sqlalchemy.dialects import registry

registry.register("yql.ydb", "ydb_sqlalchemy.sqlalchemy", "YqlDialect")
registry.register("yql.ydb_async", "ydb_sqlalchemy.sqlalchemy", "AsyncYqlDialect")
registry.register("ydb_async", "ydb_sqlalchemy.sqlalchemy", "AsyncYqlDialect")
registry.register("ydb", "ydb_sqlalchemy.sqlalchemy", "YqlDialect")
registry.register("yql", "ydb_sqlalchemy.sqlalchemy", "YqlDialect")
registry.register("ydb", "ydb_sqlalchemy.sqlalchemy", "YDBDialect")
registry.register("ydb.ydb_sync", "ydb_sqlalchemy.sqlalchemy", "YDBDialect")
registry.register("ydb_async", "ydb_sqlalchemy.sqlalchemy", "AsyncYDBDialect")
registry.register("ydb.ydb_async", "ydb_sqlalchemy.sqlalchemy", "AsyncYDBDialect")
pytest.register_assert_rewrite("sqlalchemy.testing.assertions")

from sqlalchemy.testing.plugin.pytestplugin import * # noqa: E402, F401, F403
4 changes: 2 additions & 2 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def test_connection_set(self, connection_no_trans):

class TestEngine(TestBase):
__backend__ = True
__only_on__ = "yql+ydb"
__only_on__ = "ydb+ydb_sync"

@pytest.fixture(scope="class")
def ydb_driver(self):
Expand Down Expand Up @@ -649,7 +649,7 @@ def test_sa_null_pool_with_ydb_shared_session_pool(self, ydb_driver, ydb_pool):


class TestAsyncEngine(TestEngine):
__only_on__ = "yql+ydb_async"
__only_on__ = "ydb+ydb_async"

@pytest.fixture(scope="class")
def ydb_driver(self):
Expand Down
2 changes: 1 addition & 1 deletion ydb_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._version import VERSION # noqa: F401
from ydb_dbapi import IsolationLevel # noqa: F401
from .sqlalchemy import Upsert, types, upsert # noqa: F401
import ydb_dbapi as dbapi
import ydb_dbapi as dbapi # noqa: F401
14 changes: 7 additions & 7 deletions ydb_sqlalchemy/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ def _get_column_info(t):


class YdbRequestSettingsCharacteristic(characteristics.ConnectionCharacteristic):
def reset_characteristic(self, dialect: "YqlDialect", dbapi_connection: ydb_dbapi.Connection) -> None:
def reset_characteristic(self, dialect: "YDBDialect", dbapi_connection: ydb_dbapi.Connection) -> None:
dialect.reset_ydb_request_settings(dbapi_connection)

def set_characteristic(
self, dialect: "YqlDialect", dbapi_connection: ydb_dbapi.Connection, value: ydb.BaseRequestSettings
self, dialect: "YDBDialect", dbapi_connection: ydb_dbapi.Connection, value: ydb.BaseRequestSettings
) -> None:
dialect.set_ydb_request_settings(dbapi_connection, value)

def get_characteristic(
self, dialect: "YqlDialect", dbapi_connection: ydb_dbapi.Connection
self, dialect: "YDBDialect", dbapi_connection: ydb_dbapi.Connection
) -> ydb.BaseRequestSettings:
return dialect.get_ydb_request_settings(dbapi_connection)


class YqlDialect(StrCompileDialect):
name = "yql"
driver = "ydb"
class YDBDialect(StrCompileDialect):
name = "ydb"
driver = "ydb_sync"

supports_alter = False
max_identifier_length = 63
Expand Down Expand Up @@ -441,7 +441,7 @@ def do_execute(
cursor.execute(operation, parameters)


class AsyncYqlDialect(YqlDialect):
class AsyncYDBDialect(YDBDialect):
driver = "ydb_async"
is_async = True
supports_statement_cache = True
Expand Down
6 changes: 3 additions & 3 deletions ydb_sqlalchemy/sqlalchemy/dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

class Upsert(sa.sql.Insert):
__visit_name__ = "upsert"
_propagate_attrs = {"compile_state_plugin": "yql"}
stringify_dialect = "yql"
_propagate_attrs = {"compile_state_plugin": "ydb"}
stringify_dialect = "ydb"
inherit_cache = False


@sa.sql.base.CompileState.plugin_for("yql", "upsert")
@sa.sql.base.CompileState.plugin_for("ydb", "upsert")
class UpsertDMLState(sa.sql.dml.InsertDMLState):
pass
4 changes: 2 additions & 2 deletions ydb_sqlalchemy/sqlalchemy/test_sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sqlalchemy as sa

from . import YqlDialect, types
from . import YDBDialect, types


def test_casts():
dialect = YqlDialect()
dialect = YDBDialect()
expr = sa.literal_column("1/2")

res_exprs = [
Expand Down

0 comments on commit 0ddabfe

Please sign in to comment.