failed psql because i forgot the sort. RIP.

master
bel 2022-10-20 08:53:08 -06:00
parent b5273549e0
commit 2321c171c2
4 changed files with 38 additions and 6 deletions

View File

@ -15,14 +15,18 @@ func main() {
q := flag.String("q", "show tables", "query to execute")
flag.Parse()
query := strings.Trim(strings.TrimSpace(*q), ";")
if len(query) == 0 {
panic("refusing empty query")
}
query += ";"
log.Printf("%s", query)
db, err := sql.Open("sqlite3", *dbpath)
if err != nil {
panic(err)
}
query := strings.Trim(strings.TrimSpace(*q), ";") + ";"
log.Printf("%s", query)
if strings.HasPrefix(strings.ToUpper(strings.TrimSpace(query)), "SELECT") {
rows, err := db.Query(query)
if err != nil {

BIN
amex-2022-10-20/3_/db.db Normal file

Binary file not shown.

View File

@ -1,3 +0,0 @@
module 3_
go 1.18

31
amex-2022-10-20/3_/mvp.sh Normal file
View File

@ -0,0 +1,31 @@
#! /bin/bash
main() {
set -e
set -o pipefail
local bin=../0_setup/0_setup
local cmds=(
'DROP TABLE IF EXISTS events'
'
CREATE TABLE events (
sensor_id integer not null,
event_type integer not null
);
'
'INSERT INTO events VALUES (2, 2)'
'INSERT INTO events VALUES (2, 4)'
'INSERT INTO events VALUES (2, 2)'
'INSERT INTO events VALUES (3, 2)'
'INSERT INTO events VALUES (2, 3)'
"$@"
)
for cmd in "${cmds[@]}"; do
echo =================
$bin -q "$cmd"
echo
done
}
main "$@"