PostgreSQL引擎不支持Windows操作系统。

huangapple go评论84阅读模式
英文:

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");

What I am missing?PostgreSQL引擎不支持Windows操作系统。

答案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

huangapple
  • 本文由 发表于 2022年7月31日 01:05:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/73177601.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定