Skip to content

Instantly share code, notes, and snippets.

@ivanleoncz
Created May 29, 2018 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanleoncz/bc124fa046df26da6e82121c0d06d9e6 to your computer and use it in GitHub Desktop.
Save ivanleoncz/bc124fa046df26da6e82121c0d06d9e6 to your computer and use it in GitHub Desktop.
Demonstrating SQLite3 query with data returned as JSON Array.
""" 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