Created
September 14, 2016 14:40
-
-
Save squeaky-pl/097b8ecdd82c6b3ebce198fdfde88ec6 to your computer and use it in GitHub Desktop.
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
In [1]: from sqlalchemy.ext.declarative import declarative_base | |
In [2]: Base = declarative_base() | |
In [3]: from sqlalchemy import Column, Integer, String | |
In [4]: class User(Base): | |
...: __tablename__ = 'users' | |
...: id = Column(Integer, primary_key=True) | |
...: name = Column(String) | |
...: | |
In [6]: from sqlalchemy.orm import Query | |
In [7]: q = Query([User.id, User.name]).filter(User.name.startswith('Ramón')) | |
In [14]: from sqlalchemy.dialects import mysql | |
In [16]: compiled = q.statement.compile(dialect=mysql.dialect()) | |
In [18]: str(compiled) | |
Out[18]: "SELECT users.id, users.name \nFROM users \nWHERE (users.name LIKE concat(%s, '%%'))" | |
In [19]: compiled.params | |
Out[19]: {'name_1': 'Ramón'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment