You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATETYPEpublic.state AS ENUM (
'CREATED',
'RUNNING'
);
CREATETABLEpublic.member (
id uuid DEFAULT public.uuid_generate_v4() NOT NULL,
states public.state[] DEFAULT ARRAY['CREATED'::public.state] NOT NULL
);
Queries:
-- name: GetMember :oneSELECT*FROM member WHERE id = $1;
GET_MEMBER="""-- name: get_member \\:oneSELECT id, states FROM member WHERE id = :p1"""classQuerier:
def__init__(self, conn: sqlalchemy.engine.Connection):
self._conn=conndefget_member(self, *, member_id: uuid.UUID) ->Optional[models.Member]:
row=self._conn.execute(sqlalchemy.text(GET_MEMBER), {"p1": member_id}).first()
ifrowisNone:
returnNonereturnmodels.Member(
id=row[0],
states=row[1],
)
Issue
When using the get_member() method, the states property doesn't have the expected type.
It should be a List[State] but the type is a string of the following format: {CREATED,RUNNING}.
member=queries.get_member(some_uuid)
# the following line is not expected.type(member.states) # <class 'str'>
Workaround
Our current workaround is to manually parse the string but this would be better handled by SQLAlchemy / SQLC.
Context
Given the following SQL schema
Queries:
sqlc-gen-python
generates the following model:And the following query:
Issue
When using the
get_member()
method, thestates
property doesn't have the expected type.It should be a
List[State]
but the type is astring
of the following format:{CREATED,RUNNING}
.Workaround
Our current workaround is to manually parse the string but this would be better handled by SQLAlchemy / SQLC.
It seems that SQLAlchemy supports array types when using the ORM interface:
https://docs.sqlalchemy.org/en/20/dialects/postgresql.html#sqlalchemy.dialects.postgresql.ARRAY
But I'm not sure how to use this with the
execute
method.For reference, the
List
type is generated by sqlc-gen-python:sqlc-gen-python/internal/gen.go
Lines 35 to 50 in 8b3fe83
The text was updated successfully, but these errors were encountered: