3 ms·
A few years back I toyed with the idea of building something like this. It was a dark time that I was stuck using a database besides Postgres. If you want to r
by koolba 10y ago
A few years back I toyed with the idea of building something like this. It was a dark time that I was stuck using a database besides Postgres.
If you want to really make this usable here's what you need to add:
- usql -f foo.sql
- Allow @path/to/file.sql and @@path/to/relative/file.sql references
- Common syntax for referencing env variables in SQL (each DB's utilities have slightly different syntaxes so have to pick one)
- External transaction demarcation to ensure a set of commands get executed together (ex: psql --single-transaction)
- Some autocompletion (if you plan on this being used for interactive use)
- kenshaw 10y agoAuto-completion will come in time. I don't know if I would allow "relative" pathing via @@, I'm not sure why you wouldn't just use general paths. As for the other options, such as -f, etc., yes those will be put in place. I am hoping to make this a 100% drop in replacement for psql, so whatever psql supports on the command line, as well as the various backslash commands (ie, \f) will be added.
- koolba 10y agoRelative paths are a must. I don't think I ever use non-relative paths. Say you have a folder structure like this: sql/ tables/ foo.sql bar.sql main.sql And the contents of main.sql are something like this: @@tables/foo.sql @@tables/foo.sql Then you can run main.sql via: usql -f sql/main.sql If script file resolution is not relative pathed to the parent, it gets very fragile as you must invoke the parent from a specific location, or, you have to hard code full pathes in your scripts (arguably even uglier).
- kenshaw 10y agoThis is a feature in psql? I must admit if it is, I'm not familiar with it.
- koolba 10y agoYes psql supports it. The syntax is "\i path/to/file.sql" or "\ir relative/path/to/file.sql". The latter is resolved relative to the parent script. Makes nesting scripts possible without losing your sanity.
- kenshaw 10y agoYes, if it's in psql, I'll get it into usql in the near future. (for certain large values of near).
- ComodoHacker 10y agoThis feature is actually borrowed from Oracle's SQLPlus.