add dialect to compilation of sqlalchemy clauses

This commit is contained in:
collerek
2020-08-09 06:24:22 +02:00
parent 8f179f763f
commit 39e44b1985
4 changed files with 7 additions and 1 deletions

View File

@ -3,6 +3,7 @@ from orm.fields import Integer, BigInteger, Boolean, Time, Text, String, JSON, D
from orm.models import Model
from orm.exceptions import ModelDefinitionError, MultipleMatches, NoMatch, ModelNotSet
__version__ = "0.0.1"
__all__ = [
"Integer",
"BigInteger",

View File

@ -5,6 +5,7 @@ import uuid
from typing import Any, List, Type, TYPE_CHECKING, Optional, TypeVar, Tuple
from typing import Set, Dict
import databases
import pydantic
import sqlalchemy
from pydantic import BaseModel, BaseConfig, create_model
@ -107,6 +108,9 @@ class Model(list, metaclass=ModelMetaclass):
__fields__: Dict[str, pydantic.fields.ModelField]
__pydantic_model__: Type[BaseModel]
__pkname__: str
__tablename__: str
__metadata__: sqlalchemy.MetaData
__database__: databases.Database
_orm_relationship_manager: RelationshipManager
objects = qry.QuerySet()

View File

@ -262,7 +262,8 @@ class QuerySet:
clause = getattr(column, op_attr)(value)
clause.modifiers['escape'] = '\\' if has_escaped_character else None
clause_text = str(clause.compile(compile_kwargs={"literal_binds": True}))
clause_text = str(clause.compile(dialect=self.model_cls.__database__._backend._dialect,
compile_kwargs={"literal_binds": True}))
alias = f'{table_prefix}_' if table_prefix else ''
aliased_name = f'{alias}{table.name}.{column.name}'
clause_text = clause_text.replace(f'{table.name}.{column.name}', aliased_name)