【问题标题】:the PostgreSQL engine does not support WindowsPostgreSQL 引擎不支持 Windows
【发布时间】:2022-11-23 18:45:50
【问题描述】:

我尝试使用 sqlc 包生成 golang 代码,但它说“PostgreSQL 引擎不支持 Windows” 我试图在我使用 postgresql alpine docker 镜像的 postgresql 中生成用于插入操作的代码。

我的 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

帐户.sql

-- name CreateAccount: one
INSERT INTO accounts (
    owner,
    balance,
    currency
) VALUES(
    $1,$2,$3
) RETURNING *;

我的架构包含

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

我错过了什么?

【问题讨论】:

标签: postgresql go sqlc


【解决方案1】:

关于#282 sqlc 不支持 PostgreSQL for windows。但是你可以使用docker生成文件,如sqlc的安装指南中所述。(link

docker run --rm -v $(shell pwd):/src -w /src kjconroy/sqlc 生成

【讨论】:

    猜你喜欢
    • 2022-07-28
    • 2020-09-07
    • 2011-12-23
    • 2021-05-11
    • 2011-12-26
    • 2016-01-11
    • 2019-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多