storj/satellite/satellitedb/dbx/gen.sh
JT Olio 8e242cd012 dbutil: statically require all databases accesses to use contexts
this will allow for some nice runtime analysis down the road.
also, this allows for wrapping database handles in a way that
can interact with these contexts

requires https://review.dev.storj.io/c/storj/dbx/+/514

Change-Id: Ib087b7cd73296dd2c1e0331314da34d861f61d2b
2020-01-14 18:20:47 -05:00

16 lines
700 B
Bash

#!/bin/bash
dbx schema -d postgres -d cockroach satellitedb.dbx .
dbx golang -d postgres -d cockroach -t templates satellitedb.dbx .
( echo '//lint:file-ignore * generated file'; cat satellitedb.dbx.go ) > satellitedb.dbx.go.tmp && mv satellitedb.dbx.go{.tmp,}
gofmt -r "*sql.Tx -> dbwrap.Tx" -w satellitedb.dbx.go
perl -0777 -pi \
-e 's,\t"github.com/lib/pq"\n\),\t"github.com/lib/pq"\n\n\t"storj.io/storj/private/dbutil/dbwrap"\n\),' \
satellitedb.dbx.go
perl -0777 -pi \
-e 's/type DB struct \{\n\t\*sql\.DB/type DB struct \{\n\tdbwrap.DB/' \
satellitedb.dbx.go
perl -0777 -pi \
-e 's/\tdb = &DB\{\n\t\tDB: sql_db,/\tdb = &DB\{\n\t\tDB: dbwrap.SQLDB\(sql_db\),/' \
satellitedb.dbx.go