1

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?enter image description here

Pramod
  • 21
  • 6

2 Answers2

1

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

for PowerShell use docker run --rm -v ${PWD}:/src -w /src kjconroy/sqlc generate

Jaxoo Jack
  • 50
  • 3