{ "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
name
0Album
1Artist
2Customer
3Employee
4Genre
5Invoice
6InvoiceLine
7MediaType
8Playlist
9PlaylistTrack
10Track
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Title
0Jagged Little Pill
\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 }