Created
May 29, 2018 20:33
-
-
Save ivanleoncz/bc124fa046df26da6e82121c0d06d9e6 to your computer and use it in GitHub Desktop.
Demonstrating SQLite3 query with data returned as JSON Array.
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
""" Demonstrating SQLite3 query with data returned as JSON Array. """ | |
from json import dumps | |
__author__ = "@ivanleoncz" | |
import sqlite3 | |
def data_as_json(): | |
db = sqlite3.connect("app_db.sqlite3") | |
cursor = db.cursor() | |
query = """ SELECT * FROM Users """ | |
cursor.execute(query) | |
data = [ row for row in cursor.fetchall() ] | |
db.commit() | |
return dumps(data, indent=4) | |
print(data_as_json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment