Created
January 21, 2020 11:37
-
-
Save AndreiPashkin/9b497233e2a7668d0da67dc74d169812 to your computer and use it in GitHub Desktop.
Compiled statement example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlalchemy as sa | |
from sqlalchemy import create_engine | |
from sqlalchemy.ext.declarative import declarative_base | |
Base = declarative_base() | |
class User(Base): | |
__tablename__ = 'users' | |
id = sa.Column(sa.Integer, primary_key=True) | |
name = sa.Column(sa.String) | |
fullname = sa.Column(sa.String) | |
nickname = sa.Column(sa.String) | |
def __repr__(self): | |
return "<User(name='%s', fullname='%s', nickname='%s')>" % ( | |
self.name, self.fullname, self.nickname | |
) | |
engine = create_engine('sqlite:///:memory:', echo=True) | |
Base.metadata.create_all(engine) | |
statement = sa.select([User.__table__]).where(User.__table__.c.id == sa.bindparam('id')) | |
compiled_statement = statement.compile(dialect=sa.dialects.sqlite.dialect()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment