simonw / sqlite-utils

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

Idea: insert-files mechanism for adding extra columns with fixed values #140

Open simonw opened 4 years ago

simonw commented 4 years ago

Say for example you want to populate a file_type column with the value gif. That could work like this:

sqlite-utils insert-files gifs.db images *.gif \
    -c path -c md5 -c last_modified:mtime \
    -c file_type:text:gif --pk=path

So a column defined as a text column with a value that follows a second colon.

simonw commented 2 years ago

Alternative idea for specifying types: accept a Python expression, then use Python type literal syntax. For example:

sqlite-utils insert-files gifs.db images *.gif \
    -c path -c md5 -c last_modified:mtime \
    -a file_type '"gif"'

Where -a indicates an additional column.