I'm trying to use Golang to call transport data from a Victorian data organisation and store it in a database.
I'm using SQLC to try and generate the SQL code to query the database and store the data that is incoming. SQLC is here https://docs.sqlc.dev/en/stable/tutorials/getting-started.html .
The SQL code looks like this
-- name: trafficData :one
INSERT INTO trafficData (
href,id,
name,length,
min_number_of_lanes,minimum_tt,
is_freeway,direction,
origin,destination,organization,latest_stats
) VALUES (
$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12
)
RETURNING *;
When using SQLC generate I am receiving an error like this,
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0xd21f28]
goroutine 1 [running]:
github.com/kyleconroy/sqlc/internal/compiler.resolveCatalogRefs(0xc00027f260, 0xc00061bf78, 0x1, 0x1, 0xc0000f6900, 0xc, 0xc, 0xc000aab140, 0x0, 0xc000890d30, ...)
/root/parts/sqlc/build/internal/compiler/resolve.go:301 +0x16c8
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQuery(0xc0003d6800, 0x1270cc0, 0xc000885720, 0xc0009a2240, 0x216, 0x0, 0x0, 0x0, 0xc00099e6f0)
/root/parts/sqlc/build/internal/compiler/parse.go:90 +0x565
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQueries(0xc0003d6800, 0x2000000, 0xc00027f260, 0xc0004ace10, 0x1)
/root/parts/sqlc/build/internal/compiler/compile.go:109 +0x599
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
/root/parts/sqlc/build/internal/compiler/engine.go:49
github.com/kyleconroy/sqlc/internal/cmd.parse(0xc0000f3600, 0xc0004aec14, 0x2, 0xc000042244, 0x36, 0xc0004aec60, 0xa, 0xc0004ace10, 0x1, 0x1, ...)
/root/parts/sqlc/build/internal/cmd/generate.go:223 +0x145
github.com/kyleconroy/sqlc/internal/cmd.Generate(0x1b30500, 0xc000042244, 0x36, 0x0, 0x0, 0x1275280, 0xc000010020, 0x0, 0x1024d37, 0x32)
/root/parts/sqlc/build/internal/cmd/generate.go:167 +0xce9
github.com/kyleconroy/sqlc/internal/cmd.glob..func3(0x1b30540, 0x207fc80, 0x0, 0x0)
/root/parts/sqlc/build/internal/cmd/cmd.go:120 +0x17d
github.com/spf13/cobra.(*Command).execute(0x1b30540, 0x207fc80, 0x0, 0x0, 0x1b30540, 0x207fc80)
/root/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:856 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000ccf00, 0xc0000f3f10, 0x1, 0x1)
/root/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:960 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
/root/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:897
github.com/kyleconroy/sqlc/internal/cmd.Do(0xc00003c050, 0x1, 0x1, 0x1275240, 0xc000010010, 0x1275280, 0xc000010018, 0x1275280, 0xc000010020, 0xc00004a238)
/root/parts/sqlc/build/internal/cmd/cmd.go:34 +0x317
main.main()
/root/parts/sqlc/build/cmd/sqlc/main.go:10 +0xb5
The database schema looks like this currently,
CREATE TABLE "trafficData" (
"index" SERIAL PRIMARY KEY,
"href" VARCHAR,
"id" int,
"name" VARCHAR,
"length" int,
"min_number_of_lanes" int8,
"minimum_tt" int,
"is_freeway" bool,
"direction" VARCHAR(3),
"origin" json,
"destination" json,
"organization" json,
"latest_stats" json
);
And the API i'm using is here,
https://data-exchange.vicroads.vic.gov.au/docs/services/bluetooth-links/operations/get-bluetooth-links/console
Now - Assumedly something is wrong with the SQL I am entering - but I'm not sure exactly what. I am polling this api above and want to add in all extra data as it comes in. Maybe SQLC is overkill - I just want to be able to store this data simply and would love some help in approaching that.
Thanks!