-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make CompositeType Status public #100
Conversation
The Status for other (all?) data types is public. Keeping status private makes it difficult to create a CompositeType with an initial value. The work around is to call Set() and create an []interface{} of the fields.
The private status field is intentional. I suppose this could be revisited, but its interface is not really conducive to direct use. How does a public status field change things? All the other fields are still private. |
The main reason I ask is because creating and initializing a nested composite type is pretty tedious. The use-case is to encode query parameters. Right now, the only way to create an initialized composite type is by calling The alternative is to initialize a composite type with ValueTranscoders that are already As an example, see https://github.com/jschaf/pggen/tree/main/example/complex_params. In order to initialize composite types for query parameters I ended up doing is creating 3 functions. See
I think the basic problem is that it's very difficult to compose composite and array types and build them up programmatically. |
Sorry, its been a while since I initially wrote the composite type support and the project where I was using it ended going a different direction so my memory might be a bit fuzzy. But I do remember for sure that CompositeType was not designed to be used directly as a value container. I might be wrong on the reason, but I think it was mostly just that it is just too awkward to use directly. I think even with this change it would be rather tedious. I took a look at the code you linked to but I still don't quite understand. Are you creating a FWIW, when I was using it I would create Go structs that represented by composite types and use utilities like I'm not totally against making Maybe Take a look at https://github.com/jackc/pgtype/tree/master/pgxtype if you haven't already. It has a bunch of utilities for inspecting the database and registering types that may be useful. Maybe there needs to be a new type in pgtype that is designed for containing values instead of just (ab)using one designed only for type registration. Perhaps the code generator should use the lower level |
Not quite. I'm creating a CompositeType for each composite type either used in query params or as an output column.
Yea, I think that's probably the right way forward. |
The Status for other (all?) data types is public. Keeping status private makes
it difficult to create a CompositeType with an initial value. The work around
is to call Set() and create an []interface{} of the fields.