Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chaoflow
Created April 20, 2017 10:26
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaoflow/3a6dc9d42a90c38870b8d4033b58a4d1 to your computer and use it in GitHub Desktop.
Save chaoflow/3a6dc9d42a90c38870b8d4033b58a4d1 to your computer and use it in GitHub Desktop.
sqlite WITHOUT ROWID with (flask-)sqlalchemy
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
@makmanalp
Copy link

Wonderful. Thank you @chaoflow !

@mitchins
Copy link

Did the trick, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment