英文:
the PostgreSQL engine does not support Windows
问题
我尝试使用sqlc包生成golang代码,但它显示“PostgreSQL引擎不支持Windows”。我尝试为插入操作生成代码,使用的是postgresql alpine docker镜像。
我的sql.yaml文件如下:
version: "1"
packages:
- name: "db"
path: "./db/sqlc"
queries: "./db/query/"
schema: "./db/migration/"
engine: "postgresql"
emit_json_tags: true
emit_prepared_queries: false
emit_interface: false
emit_exact_table_names: false
account.sql文件内容如下:
-- name CreateAccount: one
INSERT INTO accounts (
owner,
balance,
currency
) VALUES(
$1,$2,$3
) RETURNING *;
我的schema包含以下内容:
CREATE TABLE "accounts" (
"id" bigserial PRIMARY KEY,
"owner" varchar NOT NULL,
"balance" bigint NOT NULL,
"currency" varchar NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE "entries" (
"id" bigserial PRIMARY KEY,
"account_id" bigint NOT NULL,
"amount" bigint NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE "transfers" (
"id" bigserial PRIMARY KEY,
"from_account_id" bigint NOT NULL,
"to_account_id" bigint NOT NULL,
"amount" bigint NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now())
);
ALTER TABLE "entries" ADD FOREIGN KEY ("account_id") REFERENCES "accounts" ("id");
ALTER TABLE "transfers" ADD FOREIGN KEY ("from_account_id") REFERENCES "accounts" ("id");
ALTER TABLE "transfers" ADD FOREIGN KEY ("to_account_id") REFERENCES "accounts" ("id");
CREATE INDEX ON "accounts" ("owner");
你缺少了什么?
英文:
I try to generate golang code using sqlc package but it say "the PostgreSQL engine does not support Windows"
I tried to generate code for insert operation in postgresql for which I used postgresql alpine docker image.
my sql.yaml file is
version: "1"
packages:
- name: "db"
path: "./db/sqlc"
queries: "./db/query/"
schema: "./db/migration/"
engine: "postgresql"
emit_json_tags: true
emit_prepared_queries: false
emit_interface: false
emit_exact_table_names: false
account.sql
-- name CreateAccount: one
INSERT INTO accounts (
owner,
balance,
currency
) VALUES(
$1,$2,$3
) RETURNING *;
and my scema contain
CREATE TABLE "accounts" (
"id" bigserial PRIMARY KEY,
"owner" varchar NOT NULL,
"balance" bigint NOT NULL,
"currency" varchar NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE "entries" (
"id" bigserial PRIMARY KEY,
"account_id" bigint NOT NULL,
"amount" bigint NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now())
);
CREATE TABLE "transfers" (
"id" bigserial PRIMARY KEY,
"from_account_id" bigint NOT NULL,
"to_account_id" bigint NOT NULL,
"amount" bigint NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now())
);
ALTER TABLE "entries" ADD FOREIGN KEY ("account_id") REFERENCES "accounts" ("id");
ALTER TABLE "transfers" ADD FOREIGN KEY ("from_account_id") REFERENCES "accounts" ("id");
ALTER TABLE "transfers" ADD FOREIGN KEY ("to_account_id") REFERENCES "accounts" ("id");
CREATE INDEX ON "accounts" ("owner");
答案1
得分: 1
关于#282,sqlc不支持Windows上的PostgreSQL。但是你可以使用docker生成文件,如sqlc的安装指南中所提到的。(链接)
> docker run --rm -v $(shell pwd):/src -w /src kjconroy/sqlc generate
英文:
Regarding #282 sqlc doesn't support PostgreSQL for windows. But you can generate files using docker, as mentioned in the installation guide of sqlc.(link)
> docker run --rm -v $(shell pwd):/src -w /src kjconroy/sqlc generate
答案2
得分: -2
对于PowerShell,请使用以下命令进行翻译:docker run --rm -v ${PWD}:/src -w /src kjconroy/sqlc generate
英文:
for PowerShell use docker run --rm -v ${PWD}:/src -w /src kjconroy/sqlc generate
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论