Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/src/gen/plugin/codegen_pb.ts linguist-generated=true
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ out.js: src/app.ts $(wildcard src/drivers/*.ts) src/gen/plugin/codegen_pb.ts nod
npx esbuild --bundle src/app.ts --tree-shaking=true --format=esm --target=es2020 --outfile=out.js

src/gen/plugin/codegen_pb.ts: buf.gen.yaml
buf generate --template buf.gen.yaml buf.build/sqlc/sqlc --path plugin/
npx @bufbuild/buf generate --template buf.gen.yaml buf.build/sqlc/sqlc --path plugin/

node_modules: package.json package-lock.json
npm install
Expand Down
2 changes: 1 addition & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: v1
plugins:
- plugin: buf.build/bufbuild/es:v1.4.2
- plugin: buf.build/bufbuild/es:v2.11.0
opt: target=ts
out: src/gen
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@bufbuild/protobuf": "^1.4.2",
"@bufbuild/protobuf": "^2.11.0",
"javy": "^0.1.2",
"pg": "^8.11.3"
}
Expand Down
13 changes: 8 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ import {
factory,
} from "typescript";

import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
import {
GenerateRequest,
GenerateRequestSchema,
GenerateResponse,
GenerateResponseSchema,
Parameter,
Column,
File,
FileSchema,
Query,
} from "./gen/plugin/codegen_pb";

Expand Down Expand Up @@ -200,7 +204,7 @@ ${query.text}`
}
if (nodes) {
files.push(
new File({
create(FileSchema, {
name: `${filename.replace(".", "_")}.ts`,
contents: new TextEncoder().encode(printNode(nodes)),
})
Expand All @@ -209,15 +213,15 @@ ${query.text}`
}
}

return new GenerateResponse({
return create(GenerateResponseSchema, {
files: files,
});
}

// Read input from stdin
function readInput(): GenerateRequest {
const buffer = readFileSync(STDIO.Stdin);
return GenerateRequest.fromBinary(buffer);
return fromBinary(GenerateRequestSchema, buffer);
}

function queryDecl(name: string, sql: string) {
Expand Down Expand Up @@ -299,7 +303,6 @@ function printNode(nodes: Node[]): string {

// Write output to stdout
function writeOutput(output: GenerateResponse) {
const encodedOutput = output.toBinary();
const buffer = new Uint8Array(encodedOutput);
const buffer = toBinary(GenerateResponseSchema, output);
writeFileSync(STDIO.Stdout, buffer);
}
Loading