harelba / q

q - Run SQL directly on delimited files and multi-file sqlite databases
http://harelba.github.io/q/
GNU General Public License v3.0
10.15k stars 419 forks source link

Add option -x to preload an SQLite extension #265

Closed rolandwalker closed 2 years ago

rolandwalker commented 3 years ago

I was confused by the various exit codes, and picked one that was unused.

Example using https://github.com/nalgeon/sqlean/blob/main/docs/stats.md :

du -sk * | q -t -x /full/path/to/sqlite3-stats 'select mode(c1) from -'

Example using https://github.com/nalgeon/sqlean/blob/main/docs/re.md :

du -sk * | q -t -x /full/path/to/sqlite3-re 'select regexp_replace(c2,"^.*\.", "") as filetype, sum(c1) from - where c2 like "%.%" group by filetype'
harelba commented 2 years ago

support for adding extensions is a great idea, especially now that q 3.1.0 will allow direct querying sqlite database file as well.

However, solving this would require a more generic mechanism that will support multiple extensions. I've opened a new PR (#282) for adding new user functions. I'll consider adding external extension support to it.

InCogNiTo124 commented 2 years ago

I would suggest using the action='append' of the OptionParser. In that way the user can do something along these lines (implying avg() is defined in one of the extensions

cat file.txt | q -x /path/to/extension1 -x /path/to/extension2 "select avg(column) from -"