-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sqlite dict cursors #588
Comments
Sounds like a good idea. Do you want to update the docs and send me a pull request? |
soulseekah
added a commit
to soulseekah/flask
that referenced
this issue
Nov 5, 2012
As pointed out in issue pallets#588 sqlite3.Row should be used instead of using casting to dict(). Also altered the "Easy Querying" Patterns example to include the more correct way to return rows as dicts. Did not touch Tutorial examples ("Views"), as these are not up to date with the current Flaskr code, and the "Show Entries" section points out the "Easy Querying" section on how to convert to a dict().
kennethreitz
pushed a commit
that referenced
this issue
Jan 25, 2013
Use sqlite3.Row factory in Flaskr (#588)
Fixed with #625 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
There are whole sections based on assumption that sqlite has no built-in DictCursor behavior
http://flask.pocoo.org/docs/tutorial/views/#tutorial-views
http://flask.pocoo.org/docs/patterns/sqlite3/#easy-querying
Besides verbosity, by wrapping result in dict() we block transparent data passing to INSERT which waits for "tupled" format
Here is solution:
db = sqlite3.connect(app.config['DATABASE_NAME'])
db.row_factory = sqlite3.Row # trick!
While "print cur.fetchall()" still looks like tuples are here... don't worry, it supports key access:
for item in cur.fetchall():
print item['title'] # works!
So you can easily remove those custom wrappers which i saw copied here and there...
The text was updated successfully, but these errors were encountered: