Skip to content

Commit ce16a96

Browse files
author
Your Name
committed
fix:__table_args__ missing
1 parent e3b27e5 commit ce16a96

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

build.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
python3 -m grpc_tools.protoc --proto_path=. --proto_path=./ --python_out=./ --pyi_out=./ --grpc_python_out=./ ./protobuf_pydantic_gen/*.proto
1+
python3 -m grpc_tools.protoc --proto_path=. --proto_path=./ --python_out=./ --pyi_out=./ --grpc_python_out=./ ./protobuf_pydantic_gen/*.proto
2+
3+
protoc --plugin=protoc-gen-custom=pydantic_protobuf_gen/main.py --custom_out=./models -I ./protos protos/example.proto protos/options.proto

models/example_model.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from pydantic import BaseModel, ConfigDict, Field as _Field
2222

23-
from sqlmodel import Column, Enum, Field, Integer, JSON, SQLModel
23+
from sqlmodel import Column, Enum, Field, Integer, JSON, PrimaryKeyConstraint, SQLModel, UniqueConstraint
2424

2525
from typing import Any, Dict, List, Optional, Type
2626

@@ -49,7 +49,10 @@ def from_protobuf(cls: Type[PydanticModel], src: _message.Message) -> PydanticMo
4949
class Example(SQLModel, table=True):
5050
model_config = ConfigDict(protected_namespaces=())
5151
__tablename__ = "users"
52-
52+
__table_args__ = (
53+
UniqueConstraint(
54+
"name", "age", name='uni_name_age'), PrimaryKeyConstraint(
55+
"name", name='index_name'),)
5356
name: Optional[str] = Field(
5457
description="Name of the example",
5558
default="John Doe",

protobuf_pydantic_gen/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ def generate_code(request: plugin_pb2.CodeGeneratorRequest,
426426
message_ext = message.options.Extensions[pydantic_pb2.database]
427427
# ext = MessageToDict(message_ext)
428428

429-
table_args = get_table_args(ext, sqlmodel_imports)
429+
table_args = get_table_args(msg_ext, sqlmodel_imports)
430+
# logging.info(f"table args is {table_args}")
430431
sqlmodel_imports_str = ", ".join(set(sqlmodel_imports))
431432
sqlmodel_imports_str = f"from sqlmodel import {sqlmodel_imports_str}" if sqlmodel_imports_str else ""
432433
imports.add(sqlmodel_imports_str)

0 commit comments

Comments
 (0)