Created
April 20, 2017 10:26
-
-
Save chaoflow/3a6dc9d42a90c38870b8d4033b58a4d1 to your computer and use it in GitHub Desktop.
sqlite WITHOUT ROWID with (flask-)sqlalchemy
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 flask_sqlalchemy | |
from sqlalchemy import schema | |
from sqlalchemy.ext.compiler import compiles | |
db = flask_sqlalchemy.SQLAlchemy() | |
class Tag(db.Model): | |
__table_args__ = {'info': {'without_rowid': True}} | |
text = db.Column(db.String, primary_key=True) | |
@compiles(schema.CreateTable) | |
def compile(element, compiler, **kw): | |
text = compiler.visit_create_table(element, **kw) | |
if element.element.info.get('without_rowid'): | |
text = text.rstrip() + ' WITHOUT ROWID\n\n' | |
return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wonderful. Thank you @chaoflow !