Skip to content

Instantly share code, notes, and snippets.

@marttp
Created June 19, 2025 23:03
Show Gist options
  • Save marttp/93e1039f0cddc8471df344e81ac43454 to your computer and use it in GitHub Desktop.
Save marttp/93e1039f0cddc8471df344e81ac43454 to your computer and use it in GitHub Desktop.
import sqlite3
db_file = "sample.db"
db_conn = sqlite3.connect(db_file)
def list_tables() -> list[str]:
"""Retrieve the names of all tables in the database."""
# Include print logging statements so you can see when functions are being called.
print(" - DB CALL: list_tables()")
cursor = db_conn.cursor()
# Fetch the table names.
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
return [t[0] for t in tables]
print(list_tables())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment