Skip to content

Commit 0d7364a

Browse files
committed
Quick Save
1 parent a2bbe4b commit 0d7364a

File tree

133 files changed

+218
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+218
-123
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ test: $(PACKAGE)
7676
# cd timefmt && go test
7777
cd codemeta && go test
7878

79+
man: $(MAN_PAGES)
80+
7981
$(MAN_PAGES): .FORCE
8082
mkdir -p man/man1
8183
pandoc $@.md --from markdown --to man -s >man/man1/$@
8284

83-
man: $(MAN_PAGES)
84-
8585
website: .FORCE
8686
cd how-to && make -f website.mak
8787
make -f website.mak
@@ -107,7 +107,7 @@ clean:
107107
#@if [ -d man ]; then rm -fR man; fi
108108

109109
# NOTE: macOS causes problems if you copy a binary versus move it.
110-
install: build
110+
install: build man
111111
@echo "Installing programs in $(PREFIX)/bin"
112112
@for FNAME in $(PROGRAMS); do if [ -f ./bin/$$FNAME ]; then mv -v ./bin/$$FNAME $(PREFIX)/bin/$$FNAME; fi; done
113113
@echo ""

about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
<section>
2727
<h1 id="about-this-software">About this software</h1>
28-
<h2 id="datatools-1.2.6">datatools 1.2.6</h2>
28+
<h2 id="datatools-1.2.8">datatools 1.2.8</h2>
2929
<h3 id="authors">Authors</h3>
3030
<ul>
3131
<li>R. S. Doiel</li>

about.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ authors:
1111
orcid: "https://orcid.org/0000-0003-0900-6903"
1212

1313
repository-code: "https://github.com/caltechlibrary/datatools"
14-
version: 1.2.7
14+
version: 1.2.8
1515
license-url: "https://data.caltech.edu/license"
1616
keywords: [ "csv", "excel", "sql", "json", "yaml", "xlsx", "golang", "bash" ]
1717

@@ -20,7 +20,7 @@ keywords: [ "csv", "excel", "sql", "json", "yaml", "xlsx", "golang", "bash" ]
2020
About this software
2121
===================
2222

23-
## datatools 1.2.7
23+
## datatools 1.2.8
2424

2525
### Authors
2626

cmd/sql2csv/sql2csv.go

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ dsn_url
4242
: (string) A data source name in URL form where the "protocol" element
4343
identifies the database resource being accessed (e.g. "sqlite://",
4444
"mysql://", "postgres://"). A data source name are rescribed
45-
at <https://github.com/golang/go/wiki/SQLInterface>.
45+
at <https://go.dev/wiki/SQLInterface>. For the specificly supported
46+
datatabase connection strings see
47+
<https://pkg.go.dev/github.com/glebarez/go-sqlite>,
48+
<https://pkg.go.dev/github.com/go-sql-driver/mysql#readme-dsn-data-source-name>
49+
and <https://pkg.go.dev/github.com/lib/pq>
50+
4651
4752
header_row
4853
: (boolean) if true print a header row in the output, false for no
@@ -112,20 +117,36 @@ configuration file
112117
: Force the line ending per row to carage return and
113118
line feed if true, false use line feed
114119
115-
# EXAMPLE
120+
-sql FILENAME
121+
: Read sql statement from a file instead of the command line.
122+
123+
# EXAMPLES
116124
117125
Using the "dbcfg.json" configuration file, display ten rows
118126
from table "mytable" in database indicated in "dbcfg.json".
119127
128+
~~~sql
120129
{app_name} dbcfg.json 'SELECT * FROM mytable LIMIT 10'
130+
~~~
121131
122132
The CSV output is written standard out and can be redirected into
123133
a file if desired.
124134
135+
~~~shell
125136
{app_name} dbcfg.json 'SELECT * FROM mytable LIMIT 10' \
126137
>ten-rows.csv
138+
~~~
139+
140+
Read SQL from a file and connect to Postgres without SSL you
141+
can pass the `+"`"+`-sql`+"`"+` and `+"`"+`-dsn`+"`"+` options.
142+
143+
~~~shell
144+
{app_name} \
145+
-dsn "postgres://${USER}@/${DB_NAME}?sslmode=disable" \
146+
-sql query.sql \
147+
>my_data.csv
148+
~~~
127149
128-
{app_name} {version}
129150
`
130151
)
131152

@@ -148,6 +169,7 @@ func main() {
148169
writeHeaderRow, useCRLF := sqlCfg.WriteHeaderRow, sqlCfg.UseCRLF
149170
dsn, delimiter := "", ""
150171
fName, stmt := "", ""
172+
sqlFName := ""
151173

152174
// Handle options
153175
flag.BoolVar(&showHelp, "help", showHelp, "display help")
@@ -157,6 +179,7 @@ func main() {
157179
flag.BoolVar(&useCRLF, "use-crlf", useCRLF, "delimited rows with a carriage return and line feed")
158180
flag.StringVar(&dsn, "dsn", dsn, "connect using the data source name provided in URL form")
159181
flag.StringVar(&delimiter, "delimiter", "", "set the delimiter, defaults to comma")
182+
flag.StringVar(&sqlFName, "sql", "", "read the SQL statement from a file, '-' will cause a read from standard input")
160183
flag.Parse()
161184
args := flag.Args()
162185

@@ -184,8 +207,20 @@ func main() {
184207
case 2:
185208
fName, stmt = args[0], args[1]
186209
default:
187-
fmt.Fprintf(eout, "missing configuration and SQL query statement")
188-
os.Exit(1)
210+
if sqlFName == "" {
211+
fmt.Fprintf(eout, "missing configuration and SQL query statement")
212+
os.Exit(1)
213+
}
214+
}
215+
216+
// Read SQL from file if specified.
217+
if sqlFName != "" {
218+
src, err := os.ReadFile(sqlFName)
219+
if err != nil {
220+
fmt.Fprintf(eout, "%s\n", err)
221+
os.Exit(1)
222+
}
223+
stmt = fmt.Sprintf("%s", src)
189224
}
190225

191226
// Load configuration if provided

codemeta.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
"codeRepository": "https://github.com/caltechlibrary/datatools",
66
"dateCreated": "2017-02-06",
77
"dateRelease": "2023-10-02",
8-
"dateModified": "2024-02-26",
8+
"dateModified": "2024-02-27",
99
"downloadUrl": "https://github.com/caltechlibrary/datatools/releases/",
1010
"issueTracker": "https://github.com/caltechlibrary/datatools/issues",
1111
"name": "datatools",
12-
"version": "1.2.7",
12+
"version": "1.2.8",
1313
"description": "A set of command line tools for working with CSV, Excel Workbooks, JSON and structured text documents.",
14+
"releaseNotes": "Maintenance, added -sql to sql2csv cli.",
1415
"applicationCategory": "computer programming",
1516
"developmentStatus": "active",
1617
"funder": {

codemeta2cff.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%codemeta2cff(1) user manual | version 1.2.7 ede8965
1+
%codemeta2cff(1) user manual | version 1.2.7 a2bbe4b
22
% R. S. Doiel
33
% 2024-02-27
44

csv2json.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%csv2json(1) user manual | version 1.2.7 ede8965
1+
%csv2json(1) user manual | version 1.2.7 a2bbe4b
22
% R. S. Doiel
33
% 2024-02-27
44

csv2mdtable.1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ <h1 id="examples">EXAMPLES</h1>
7979
<pre><code> cat data1.csv | csv2mdtable &gt; data1.md</code></pre>
8080
<p>Convert data1.csv to data1.md using options.</p>
8181
<pre><code> csv2mdtable -i data1.csv -o data1.md</code></pre>
82-
<p>csv2mdtable 1.2.6</p>
82+
<p>csv2mdtable 1.2.7</p>
8383
</section>
8484

8585
<footer>

csv2mdtable.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%csv2mdtable(1) user manual | version 1.2.7 ede8965
1+
%csv2mdtable(1) user manual | version 1.2.7 a2bbe4b
22
% R. S. Doiel
33
% 2024-02-27
44

csv2tab.1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ <h1 id="examples">EXAMPLES</h1>
5656
<p>This would yield</p>
5757
<pre><code> name email age
5858
Doe, Jane [email protected] 42</code></pre>
59-
<p>csv2tab 1.2.6</p>
59+
<p>csv2tab 1.2.7</p>
6060
</section>
6161

6262
<footer>

0 commit comments

Comments
 (0)