ydb-platform / ydb-sqlalchemy

YQL Dialect for SQLAlchemy
Apache License 2.0
18 stars 5 forks source link

update query is failing #31

Closed kabulov closed 4 months ago

kabulov commented 4 months ago

cannot update table:

from sqlalchemy import create_engine, Column, Boolean, Integer
from sqlalchemy.dialects import registry
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import sessionmaker

registry.register("yql.ydb", "ydb_sqlalchemy.sqlalchemy", "YqlDialect")
registry.register("ydb", "ydb_sqlalchemy.sqlalchemy", "YqlDialect")
registry.register("yql", "ydb_sqlalchemy.sqlalchemy", "YqlDialect")

engine = create_engine("yql+ydb://localhost:2136/local")
Base = declarative_base()
Session = sessionmaker(bind=engine)
session = Session()

class Table(Base):
    __tablename__ = "dir/table"
    pk = Column(Integer, primary_key=True)
    col = Column(Boolean)

Base.metadata.create_all(engine)

session.add(Table(pk=1, col=False))
session.commit()

row = session.query(Table).first()
row.col = True
session.commit()

fails with following message:

sqlalchemy.exc.DataError: (ydb_sqlalchemy.dbapi.errors.DataError) position { row: 1 column: 57 } message: "Unknown name: $dir" end_position { row: 1 column: 57 } severity: 1 (server_code: 400080)
[SQL: UPDATE `dir/table` SET col=%(col)s WHERE `dir/table`.col = %(dir/table_col)s]
[parameters: {'col': True, 'dir/table_col': False}]
(Background on this error at: https://sqlalche.me/e/20/9h9h)
rekby commented 4 months ago

sqlalchemy ORM has not supported yet https://github.com/ydb-platform/ydb-sqlalchemy/issues/33

kabulov commented 3 months ago

fixed in https://github.com/ydb-platform/ydb-sqlalchemy/pull/41