walterwanderley / sqlc-grpc

Create a gRPC server from code generated by sqlc
MIT License
127 stars 13 forks source link

Is there a way to change the proto file or make additions without them being overwritten? #10

Closed JamesArthurHolland closed 8 months ago

JamesArthurHolland commented 8 months ago

I have the following schema:

--pricing_schema.sql

CREATE TABLE pricing_schema (
    id UUID PRIMARY KEY,
    name varchar(255) NOT NULL,
    organization_id UUID NOT NULL,
    created_at timestamp NOT NULL DEFAULT current_timestamp,
    updated_at timestamp NOT NULL DEFAULT current_timestamp
);

CREATE TABLE price_category (
    id UUID PRIMARY KEY,
    name varchar(255) NOT NULL,
    pricing_schema_id UUID NOT NULL,
    created_at timestamp NOT NULL DEFAULT current_timestamp,
    updated_at timestamp NOT NULL DEFAULT current_timestamp
);

CREATE TABLE price (
    id UUID PRIMARY KEY,
    name varchar(255) NOT NULL,
    description varchar(255) NOT NULL,
    price_category_id UUID NOT NULL,
    price_in_smallest_donimation int NOT NULL,
    created_at timestamp NOT NULL DEFAULT current_timestamp,
    updated_at timestamp NOT NULL DEFAULT current_timestamp
);

I want to be able to use transactions to save a full pricing schema at once, including the nested parts.

schema -> category1 ----> item1 -> category2 ----> item1 ----> item2

I have the individual methods / queries for saving, but how do I create the addition to the proto file / grpc schema without having to write a sql query for the insert?

walterwanderley commented 8 months ago

At this moment it's impossible. Just proto comments and options aren't overwrited. I'll try to implement this feature on the next release.

JamesArthurHolland commented 8 months ago

Do you have an idea of how this would be implemented?

I have some spare time right now, I could potentially contribute a PR if you could discuss implementation details?

walterwanderley commented 8 months ago

Do you have an idea of how this would be implemented?

I have some spare time right now, I could potentially contribute a PR if you could discuss implementation details?

Try the new version v0.19.3.

Add new rpc and messages to the proto file and execute go generate

JamesArthurHolland commented 8 months ago

The proto file still gets overwritten each time go generate runs

$ sqlc-grpc -v
v0.19.3
walterwanderley commented 8 months ago

Could you provide an example of a modified proto file?

JamesArthurHolland commented 8 months ago

I can't seem to replicate the error in a fresh repo. It works fine when I've initialised using v0.19.3, but in my project that was created with the old version it doesn't behave correctly.

Tried:

go clean -modcache
rm go.mod && rm go.sum
go generate

Still nothing.

Tried removing all the buf.*.yaml and associated lock files, nothing.

Tried running the command from terminal, in case it was some weird goland caching issue, nada.