Add jq::expr argument support Add initial jq::expr argument support. This is still sort of experimental, so may break later if I find a better way to handle this sort of thing. For now, this provides a convenient way to chain results together so that if one query produces a value the next query needs, that can be used. The man page has been updated accordingly for this.
Relicense under Apache 2.0 license For future use, relicense under the Apache 2.0 license.
Additional refactoring for use in chisel Some additional refactoring to make it easier to use vdb in chisel (working name, anyway). No significant changes at the moment, but moving some marshaling code into vdb so it can be used with config files more reliably.
Move drivers to top-level package Move the drivers to the top-level package so they can be reused.
Add sqlite3 DBs, vim files to gitignore Bump gitignore with some more files.
Add sqlite driver Add a basic `sqlite` driver. Doesn't do anything particularly unique, but does require cgo. Won't be included if built without cgo, of course.
Update to use Go 1.17, go:build constraints Update to use go:build constraints and Go 1.17.
Move database value handling to vdb package Move the database value handling / query code to the vdb packge so it can be reused elsewhere. There aren't any significant logical changes to the code except that PrintArray is moved out of the QueryOptions struct. Some refactoring has been done to make JSON parsing more likely. This is mainly from findings in sqlite testing and for columns that are explicitly named `foo_json` and such. It's still imperfect, but should be a little better about it, especially if the type coming back from the database is a string (which was previously ignored as a candidate).
Fix argument notation in multi-args example Add missing `::` to argument in multi-args example. Probably went missing with a replace-all a while back.
Fix typos, grammar in man page, README Fix a handful of typos in the man page, and a few spots of odd grammar in both the man page and README.
Filter query string through cli.FromFile Fix query strings not being read-able from files / standard input. This was a side effect of moving most of the argument parsing for queries around to handle argument types and arrays. In the process, query strings stopped being read from files. This fixes that by filtering query strings through cli.FromFile before any other parameters are read (to keep somewhat-consistent order on reads from stdin, mainly). Fixes tools#1.
Replace README.adoc with README.md and sql.1.scd Split the README and man page into separate documents. This is mostly so I can have a README on Sourcehut, since Asciidoc is unsupported for rendering (understandably, given how hard it can be to work with). This also changes the manpage rendering to scdoc, since it has lower overhead to installation, which should make it easier to build the project's man pages with.
Add README.adoc, makefile to generate manpage Add a README.adoc file that can be used to generate the sql(1) man page. This is pretty rudimentary right now, so it's not perfect and will need touching up over time. Still, it's better than nothing and covers some topics that weren't captured in the usage text.
Add `pg` alias for longer `postgres` scheme Add a `pg` alias for the longer `postgres` scheme. This is just to reduce typing for folks and has no special meaning.
Add basic config file support Add basic config file support by allowing users to load arguments for flags (if not already provided on the CLI) from INI files. This searches for INI files in a few places: 1. If -f, --config is passed, then the only config file loaded is the one named on the command line. This flag can be passed multiple times, with the first config file getting precedence. 2. Search for a .sqlrc file in the current directory and any directory above it. This hops up directories lexically (i.e., by calling filepath.Dir repeatedly), so it ends when it hits a root-level path. Each config file is loaded in the order it's found, excluding the paths from steps 3 and 4, which will always be loaded last. 3. It will then check for `$XDG_CONFIG_HOME/sql/sqlrc` and load that, if present. 4. Finally, it will check for $HOME/.sqlrc. This is always loaded last. To allow setting the DSN by default, there's a special `sql.dsn` key that can be set and used if the user passes `-` as the DSN. For example: $ cat ~/.sqlrc [sql] dsn = mysql://foo@bar:baz/db compact = true $ sql - 'select 1 as foo' {"foo":1} Single-character flags are rejected when loading a config file, as well as any flag that was passed on the command-line. Because config file loading happens after CLI parsing, it is also not possible to refer to another config file from within a config file.
Add cli.Forward to account for flag visiting Add a cli.Forward function to pass any value from one flag to another in a FlagSet. This is to ensure that if a short flag is passed, it invokes a long flag and causes both to be counted as "visited". This doesn't work in reverse, so you can't rely on short flags as being an authority on whether a flag was visited. This is part of a change to support configuration and default value loading from config files.
Add support for arrays via sqlx.In Add support for arrays on the command line and expansion in query strings via sqlx.In. This is roughly a two-parter: 1. On the CLI, when parsing arguments, treat anything between `-{` and `}-` as an array of arguments, to be expanded in any query string using `?`-s as its placeholder. The use of `?`-s is a limitation of sqlx.In. I may later replace this by stealing SQL parsers from Vitess and CockroachDB for different SQL dialects (writing my own would be interesting but isn't really needed right now). 2. When executing queries, transform the query string with sqlx.In, using the argument set given so that any `?` matching an array is expanded to one or more `?`-s. This depends on sqlx.Rebind as well to convert the parameter bindings to an acceptable format for the database in use. There are a handful of ways to express types for parameters as well, now, by prefixing any argument with `TYPE::`. This takes precedence before `@file`, so `int::@id` will expand to the content of the file `id` and be parsed as an int. There are probably still some bugs and behavioral oddities to be worked out with this, but it's primarily useful for cases like fields::'1 2 3' and so on, which expand to arrays as well (in case you have a file full of IDs where `-{ 1 2 3 ... }-` doesn't make sense to use).
Fix TryJSON defaulting to true This should be defaulting to false.
Add GPL-3.0-or-later license The project was missing a license, so make it available under the GPL3 since it's a good fit for tools.
Clean-up some of the CLI parsing and add more options This refactors sql to allow running one query multiple times with different sets of arguments. This can be useful if you're piping a query in and want to run it with a variety of inputs. The argument sets are separated by ',,' by default, but this can be overridden with --arg-sep. Option changes: * Add -d, --arg-sep to allow passing multiple argument sets for each query. This required a bit of refactoring to support, so arguments for queries are now stored a little differently to accomodate this. * The semantics of -J, --no-json are a little different now. Because -j, --json is not the default, the assumption is that if a column is already JSON, it should be parsed as such, and otherwise it should be viewed as similar to its source bytes as possible. If --no-json is set, JSON columns will no longer be parsed as JSON and will instead be treated as their source strings / bytes. * Add -x, --transaction to run all queries inside of a transaction. * Add -i, --isolation-level to set the isolation level of the transaction started via --transaction. Whether a particular level works is up to the database driver. * -t, --time-format now accepts 'float' as a synonym for 'unixf' and 'fs', and 'fsec'. * -t, --time-format now accept arbitrary time formats, following Go's layouts. To pass your own layout, the format string must begin with either '+' or 'format:'. * -h, --help now prints a slightly friendlier usage text. These changes are a little old and just haven't been committed or pushed, so bear with me on the brevity of this message. The program's still more or less a hack, so it's probably fine.