Created
June 19, 2025 23:03
-
-
Save marttp/93e1039f0cddc8471df344e81ac43454 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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