{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import sqlite3\n",
"import pandas as pd\n",
"from pyprojroot import here"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Connect to SQLite database\n",
"db_path = here('data/Chinook.db')\n",
"conn = sqlite3.connect(db_path)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" name | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Album | \n",
"
\n",
" \n",
" | 1 | \n",
" Artist | \n",
"
\n",
" \n",
" | 2 | \n",
" Customer | \n",
"
\n",
" \n",
" | 3 | \n",
" Employee | \n",
"
\n",
" \n",
" | 4 | \n",
" Genre | \n",
"
\n",
" \n",
" | 5 | \n",
" Invoice | \n",
"
\n",
" \n",
" | 6 | \n",
" InvoiceLine | \n",
"
\n",
" \n",
" | 7 | \n",
" MediaType | \n",
"
\n",
" \n",
" | 8 | \n",
" Playlist | \n",
"
\n",
" \n",
" | 9 | \n",
" PlaylistTrack | \n",
"
\n",
" \n",
" | 10 | \n",
" Track | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" name\n",
"0 Album\n",
"1 Artist\n",
"2 Customer\n",
"3 Employee\n",
"4 Genre\n",
"5 Invoice\n",
"6 InvoiceLine\n",
"7 MediaType\n",
"8 Playlist\n",
"9 PlaylistTrack\n",
"10 Track"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Get list of all tables\n",
"query = \"SELECT name FROM sqlite_master WHERE type='table';\"\n",
"tables = pd.read_sql(query, conn)\n",
"tables"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Title | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" Jagged Little Pill | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Title\n",
"0 Jagged Little Pill"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"query = \"\"\"SELECT Album.Title\n",
"FROM Album\n",
"JOIN Artist ON Album.ArtistId = Artist.ArtistId\n",
"WHERE Artist.Name = 'Alanis Morissette';\"\"\"\n",
"tables = pd.read_sql(query, conn)\n",
"tables"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "rag-sqlagent",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}