simonw / sqlite-utils

Python CLI utility and library for manipulating SQLite databases
https://sqlite-utils.datasette.io
Apache License 2.0
1.68k stars 112 forks source link

Utilities for building lookup tables #44

Closed simonw closed 5 years ago

simonw commented 5 years ago

While building https://github.com/dogsheep/healthkit-to-sqlite I found a need for a neat mechanism for easily building lookup tables - tables where each unique value in a column is replaced by a foreign key to a separate table.

csvs-to-sqlite currently creates those with its "extract" mechanism - but that's written as custom code against Pandas. I'd like to eventually replace Pandas with sqlite-utils there.

See also #42

simonw commented 5 years ago

id = table.lookup({"name":"Cleo"})

simonw commented 5 years ago

I considered keyword arguments for this, but I am going with a dictionary instead - for two reasons: