Metadata-Version: 2.1
Name: fastsql
Version: 1.0.1
Summary: A bit of extra usability for sqlalchemy v2.
Home-page: https://github.com/fastai/fastsql
Author: Jeremy Howard
Author-email: info@fast.ai
License: Apache Software License 2.0
Keywords: nbdev jupyter notebook python sqlalchemy sql orm
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: Apache Software License
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastcore
Requires-Dist: sqlalchemy >=2
Provides-Extra: dev

# fastsql


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

A bit of extra usability for sqlalchemy v2.

## Install

    pip install fastsql

## Example

This little library provides a single function,
[`conn_db`](https://fastai.github.io/fastsql/core.html#conn_db), which
returns an extended sqlalchemy `MetaData` object which you can use for
accessing your database with full dynamic autocomplete support in
Jupyter and IPython. So it’s particularly useful for interactive
development.

We demonstrate it here using the ‘chinook’ sample database.

``` python
from fastsql import conn_db
from fastcore.utils import *
```

``` python
url = 'https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite'
path = Path('chinook.sqlite')
if not path.exists(): urlsave(url, path)
```

``` python
connstr = f"sqlite:///{path}"
db = conn_db(connstr)
```

``` python
' '.join(db.tables)
```

    'Album Artist Customer Employee Genre Invoice InvoiceLine Track MediaType Playlist PlaylistTrack'

``` python
a = db.Album
```

``` python
list(a.c)
```

    [Column('AlbumId', INTEGER(), table=<Album>, primary_key=True, nullable=False),
     Column('Title', NVARCHAR(length=160), table=<Album>, nullable=False),
     Column('ArtistId', INTEGER(), ForeignKey('Artist.ArtistId'), table=<Album>, nullable=False)]

Rows are returned as named tuples.

``` python
rs = db.sql('select AlbumId,Title from Album')
rs[0]
```

    Row(AlbumId=1, Title='For Those About To Rock We Salute You')

``` python
a.get(a.c.Title.startswith('F'), limit=5)
```

    [Row(AlbumId=1, Title='For Those About To Rock We Salute You', ArtistId=1),
     Row(AlbumId=7, Title='Facelift', ArtistId=5),
     Row(AlbumId=60, Title='Fireball', ArtistId=58),
     Row(AlbumId=88, Title='Faceless', ArtistId=87),
     Row(AlbumId=99, Title='Fear Of The Dark', ArtistId=90)]

``` python
db.close()
```
