我正在尝试使用 Golang 从维多利亚时代的数据组织中调用传输数据并将其存储在数据库中。
我正在使用 SQLC 尝试生成 SQL 代码来查询数据库并存储传入的数据。SQLC 在这里https://docs.sqlc.dev/en/stable/tutorials/getting-started.html。
SQL 代码如下所示
-- 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 *;
使用 SQLC 生成时,我收到这样的错误,
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
数据库模式目前看起来像这样,
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
);
我正在使用的 API 在这里,
https://data-exchange.vicroads.vic.gov.au/docs/services/bluetooth-links/operations/get-bluetooth-links/console
现在 - 假设我输入的 SQL 有问题 - 但我不确定到底是什么。我在上面轮询这个 api,并想在它进来时添加所有额外的数据。也许 SQLC 有点矫枉过正——我只是希望能够简单地存储这些数据,并希望在处理这些数据时得到一些帮助。
谢谢!