{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# fastlite\n", "\n", "> A bit of extra usability for sqlite\n", "\n", "- image: \"images/diagram.png\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`fastlite` provides some little quality-of-life improvements for interactive use of the wonderful [sqlite-utils](https://sqlite-utils.datasette.io/) library. It's likely to be particularly of interest to folks using Jupyter." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Install" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```\n", "pip install fastlite\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "from nbdev.showdoc import show_doc" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from fastlite import *\n", "from fastcore.utils import *\n", "from fastcore.net import urlsave" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We demonstrate `fastlite`'s features here using the 'chinook' sample database." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "Path('chinook.sqlite').unlink(missing_ok=True)\n", "Path('chinook.sqlite-shm').unlink(missing_ok=True)\n", "Path('chinook.sqlite-wal').unlink(missing_ok=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = 'https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite'\n", "path = Path('chinook.sqlite')\n", "if not path.exists(): urlsave(url, path)\n", "\n", "db = database(\"chinook.sqlite\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Databases have a `t` property that lists all tables:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Album, Artist, Customer, Employee, Genre, Invoice, InvoiceLine, MediaType, Playlist, PlaylistTrack, Track" ] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dt = db.t\n", "dt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can use this to grab a single table...:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "