Skip to content

Commit

Permalink
Merge pull request #3 from easeq/fix-large-proto-msg
Browse files Browse the repository at this point in the history
fix: read gen request message till the end (fill_buf() has a default …
  • Loading branch information
easeq authored Oct 17, 2024
2 parents 7b9eacb + 7dfa954 commit feda98b
Show file tree
Hide file tree
Showing 14 changed files with 330 additions and 183 deletions.
4 changes: 3 additions & 1 deletion sqlc-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ lto = true
sqlparser = { version = "0.9.0", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
prost = "0.9.0"
prost = "0.13"
bytes = "1.1.0"
syn = "2.0.77"
quote = "1.0.37"
Expand All @@ -23,6 +23,8 @@ strum_macros = "0.26.4"
itertools = "0.13.0"
pluralizer = "0.4.0"
check_keyword = "0.3.1"
base64 = "0.22.1"
sqlc_sqlc_community_neoeinstein-prost = { version = "0.4.0-20231002190240-3f2d312ab6fd.1", registry = "buf" }

[build-dependencies]
prost-build = "0.9.0"
2 changes: 1 addition & 1 deletion sqlc-gen/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ get-outer-examples:
echo $(EXAMPLES_OUTER) | make -s prepare-list

generate-for-example:
@echo "generating for $$example" && \
@echo "generating for $$example_dir" && \
cd $$example_dir && \
file_with_ext=$$(ls sqlc.*) && \
file_ext=$${file_with_ext##*.} && \
Expand Down
6 changes: 6 additions & 0 deletions sqlc-gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ sql:
lang: en-us
```
### Setup
- Go to [https://buf.build/sqlc/sqlc/sdks/v1.22.0](https://buf.build/sqlc/sqlc/sdks/v1.22.0)
- Follow the instructions for Rust - community/neoeinstein-prost
### Run
The following command generates rust code for all examples
Expand Down
7 changes: 7 additions & 0 deletions sqlc-gen/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# buf.gen.yaml
version: v2
managed:
enabled: false
plugins:
- remote: buf.build/community/neoeinstein-prost:v0.4.0
out: src/codegen
13 changes: 11 additions & 2 deletions sqlc-gen/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
extern crate prost_build;
// extern crate prost_build;

fn main() {
prost_build::compile_protos(&["src/codegen.proto"], &["src/"]).unwrap();
// // prost_build::compile_protos(&["src/codegen.proto"], &["src/"]).unwrap();
// let status = std::process::Command::new("buf")
// .arg("generate")
// .current_dir(env!("CARGO_MANIFEST_DIR"))
// .status()
// .unwrap();
//
// if !status.success() {
// std::process::exit(status.code().unwrap_or(-1))
// }
}
2 changes: 1 addition & 1 deletion sqlc-gen/examples/authors/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins:
- RUST_LOG
wasm:
url: file://./../../../target/wasm32-wasip1/release/sqlc-gen.wasm
sha256: 8920bd7d234e7705f537979be05780fd08a8285fbae26afec268caad3d064867
sha256: d5c79985e5590cd3f29b0236203e9a054744d4edbbdfef2b91dc418dce8c0066
#
# - name: js
# process:
Expand Down
2 changes: 1 addition & 1 deletion sqlc-gen/examples/batch/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"wasm": {
"url": "file://./../../../target/wasm32-wasip1/release/sqlc-gen.wasm",
"sha256": "8920bd7d234e7705f537979be05780fd08a8285fbae26afec268caad3d064867"
"sha256": "d5c79985e5590cd3f29b0236203e9a054744d4edbbdfef2b91dc418dce8c0066"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion sqlc-gen/examples/booktest/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins:
- RUST_LOG
wasm:
url: file://./../../../target/wasm32-wasip1/release/sqlc-gen.wasm
sha256: 8920bd7d234e7705f537979be05780fd08a8285fbae26afec268caad3d064867
sha256: d5c79985e5590cd3f29b0236203e9a054744d4edbbdfef2b91dc418dce8c0066
#
# - name: js
# process:
Expand Down
2 changes: 1 addition & 1 deletion sqlc-gen/examples/jets/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"wasm": {
"url": "file://./../../../target/wasm32-wasip1/release/sqlc-gen.wasm",
"sha256": "8920bd7d234e7705f537979be05780fd08a8285fbae26afec268caad3d064867"
"sha256": "d5c79985e5590cd3f29b0236203e9a054744d4edbbdfef2b91dc418dce8c0066"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion sqlc-gen/examples/ondeck/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"wasm": {
"url": "file://./../../../target/wasm32-wasip1/release/sqlc-gen.wasm",
"sha256": "8920bd7d234e7705f537979be05780fd08a8285fbae26afec268caad3d064867"
"sha256": "d5c79985e5590cd3f29b0236203e9a054744d4edbbdfef2b91dc418dce8c0066"
}
}
],
Expand Down
213 changes: 66 additions & 147 deletions sqlc-gen/src/codegen.proto
Original file line number Diff line number Diff line change
@@ -1,171 +1,87 @@
// https://github.com/kyleconroy/sqlc/blob/main/protos/plugin/codegen.proto
syntax = "proto3";

package plugin;

option go_package = "github.com/kyleconroy/sqlc/internal/plugin";

message File
{
string name = 1 [json_name="name"];
bytes contents = 2 [json_name="contents"];
service CodegenService {
rpc Generate (GenerateRequest) returns (GenerateResponse);
}

message Override {
// name of the type to use, e.g. `github.com/segmentio/ksuid.KSUID` or `mymodule.Type`
string code_type = 1 [json_name="code_type"];

// name of the type to use, e.g. `text`
string db_type = 3 [json_name="db_type"];

// True if the override should apply to a nullable database type
bool nullable = 5 [json_name="nullable"];

// fully qualified name of the column, e.g. `accounts.id`
string column = 6 [json_name="column"];

Identifier table = 7 [json_name="table"];

string column_name = 8 [json_name="column_name"];

PythonType python_type = 9;

ParsedGoType go_type = 10;
message File {
string name = 1 [json_name = "name"];
bytes contents = 2 [json_name = "contents"];
}

message PythonType
{
string module = 1;
string name = 2;
}
message Settings {
// Rename message was field 5
// Overides message was field 6
// PythonCode message was field 8
// KotlinCode message was field 9
// GoCode message was field 10;
// JSONCode message was field 11;
reserved 5, 8, 9, 10, 11;

message ParsedGoType
{
string import_path = 1;
string package = 2;
string type_name = 3;
bool basic_type = 4;
map<string, string> struct_tags = 5;
string version = 1 [json_name = "version"];
string engine = 2 [json_name = "engine"];
repeated string schema = 3 [json_name = "schema"];
repeated string queries = 4 [json_name = "queries"];
Codegen codegen = 12 [json_name = "codegen"];
}

message Settings
{
string version = 1 [json_name="version"];
string engine = 2 [json_name="engine"];
repeated string schema = 3 [json_name="schema"];
repeated string queries = 4 [json_name="queries"];
map<string, string> rename = 5 [json_name="rename"];
repeated Override overrides = 6 [json_name="overrides"];
Codegen codegen = 12 [json_name="codegen"];

// TODO: Refactor codegen settings
PythonCode python = 8;
KotlinCode kotlin = 9;
GoCode go = 10;
JSONCode json = 11;
message Codegen {
message Process {
string cmd = 1;
}
message WASM {
string url = 1;
string sha256 = 2;
}
string out = 1 [json_name = "out"];
string plugin = 2 [json_name = "plugin"];
bytes options = 3 [json_name = "options"];
repeated string env = 4 [json_name = "env"];
Process process = 5 [json_name = "process"];
WASM wasm = 6 [json_name = "wasm"];
}

message Codegen
{
string out = 1 [json_name="out"];
string plugin = 2 [json_name="plugin"];
bytes options = 3 [json_name="options"];
}

message PythonCode
{
bool emit_exact_table_names = 1;
bool emit_sync_querier = 2;
bool emit_async_querier = 3;
string package = 4;
string out = 5;
bool emit_pydantic_models = 6;
}

message KotlinCode
{
bool emit_exact_table_names = 1;
string package = 2;
string out = 3;
}

message GoCode
{
bool emit_interface = 1;
bool emit_json_tags = 2;
bool emit_db_tags = 3;
bool emit_prepared_queries = 4;
bool emit_exact_table_names = 5;
bool emit_empty_slices = 6;
bool emit_exported_queries = 7;
bool emit_result_struct_pointers = 8;
bool emit_params_struct_pointers = 9;
bool emit_methods_with_db_argument = 10;
string json_tags_case_style = 11;
string package = 12;
string out = 13;
string sql_package = 14;
string output_db_file_name = 15;
string output_models_file_name = 16;
string output_querier_file_name = 17;
string output_files_suffix = 18;
bool emit_enum_valid_method = 19;
bool emit_all_enum_values = 20;
}

message JSONCode
{
string out = 1;
string indent = 2;
string filename = 3;
}

message Catalog
{
message Catalog {
string comment = 1;
string default_schema = 2;
string name = 3;
repeated Schema schemas = 4;
}

message Schema
{
message Schema {
string comment = 1;
string name = 2;
repeated Table tables = 3;
repeated Enum enums = 4;
repeated CompositeType composite_types = 5;
}

message CompositeType
{
message CompositeType {
string name = 1;
string comment = 2;
}

message Enum
{
message Enum {
string name = 1;
repeated string vals = 2;
string comment = 3;
}

message Table
{
message Table {
Identifier rel = 1;
repeated Column columns = 2;
string comment = 3;
string comment = 3;
}

message Identifier
{
message Identifier {
string catalog = 1;
string schema = 2;
string name = 3;
}

message Column
{
message Column {
string name = 1;
bool not_null = 3;
bool is_array = 4;
Expand All @@ -179,35 +95,38 @@ message Column
Identifier table = 10;
string table_alias = 11;
Identifier type = 12;
bool is_sqlc_slice = 13;
Identifier embed_table = 14;
string original_name = 15;
bool unsigned = 16;
int32 array_dims = 17;
}

message Query
{
string text = 1 [json_name="text"];
string name = 2 [json_name="name"];
string cmd = 3 [json_name="cmd"];
repeated Column columns = 4 [json_name="columns"];
repeated Parameter params = 5 [json_name="parameters"];
repeated string comments = 6 [json_name="comments"];
string filename = 7 [json_name="filename"];
Identifier insert_into_table = 8 [json_name="insert_into_table"];
message Query {
string text = 1 [json_name = "text"];
string name = 2 [json_name = "name"];
string cmd = 3 [json_name = "cmd"];
repeated Column columns = 4 [json_name = "columns"];
repeated Parameter params = 5 [json_name = "parameters"];
repeated string comments = 6 [json_name = "comments"];
string filename = 7 [json_name = "filename"];
Identifier insert_into_table = 8 [json_name = "insert_into_table"];
}

message Parameter
{
int32 number = 1 [json_name="number"];
Column column = 2 [json_name="column"];
message Parameter {
int32 number = 1 [json_name = "number"];
Column column = 2 [json_name = "column"];
}

message CodeGenRequest
{
Settings settings = 1 [json_name="settings"];
Catalog catalog = 2 [json_name="catalog"];
repeated Query queries = 3 [json_name="queries"];
string sqlc_version = 4 [json_name="sqlc_version"];
message GenerateRequest {
Settings settings = 1 [json_name = "settings"];
Catalog catalog = 2 [json_name = "catalog"];
repeated Query queries = 3 [json_name = "queries"];
string sqlc_version = 4 [json_name = "sqlc_version"];
bytes plugin_options = 5 [json_name = "plugin_options"];
bytes global_options = 6 [json_name = "global_options"];
}

message CodeGenResponse
{
repeated File files = 1 [json_name="files"];
message GenerateResponse {
repeated File files = 1 [json_name = "files"];
}
Loading

0 comments on commit feda98b

Please sign in to comment.