-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
Support type overrides in config #60
Comments
A related thought on this - do we want to get involved in actually parsing values? Currently we are just relying on mapped types being assignable from whatever the database driver provides. In the case of pg this is mostly strings by default. If we want to support composite types it seems like we will need parsing, we might also want to parse things like dates, intervals, and uuids. How best to handle this? We can generate (or import) parsers/serialisers and use them to wrap We could then describe types by a pair of functions. At this point we may want to extend my type ParseableType<T> = {
to: AST<T => string>;
from: AST<string => T>
}
export Type<T> = NamedType | ImportedType | AliasedType | EnumType | ParseableType<T>; |
Hm, well the generic types I used above imply we would have the target type available at generation type which we presumably would not if it is custom or if it depends on the SQL, but vaguely like that. |
I think adding parsers is a step in the right direction. I like the idea of wrapping const queryConfig = {
text: 'SELECT * from some_table ...',
values: ...,
types: {
getTypeParser: () => val => val,
},
}
client.query(queryConfig); I am not sure I understand why a generic param is needed in type ParseableType = {
parserCode: string;
serializerCode: string;
typeDefCode: string;
} We still have full control over which types we emit for query result and params. Wdyt? |
Hi @adelsz , I’ve also looked into the implementation of this feature, but I found some obstacles in the way: Parsing & different Postgres clientsIf we want to override Diverting from pg’s type parser/ serializerRight now if users are actually using it with a different client than @pgtyped/types package
I think it's nice to use this as an opt-in feature first, in order not to break any user setup with different Postgres clients. Overriding typesI also propose using cosmicconfig and cosmiconfig-typescript-loader for config files in the You can let know what you think, and I can give it a shot at an implementation |
Basic type overrides have now been added. Imported type overrides are in the work as part of #480 |
Allow override of type mapping form config by adding
types
section that takes a map of postgres type names toType
:This would support the currently supported
AliasedType
,ImportedType
, andEnumType
definitions and apply them as overrides into theTypeMapping
passed toTypeAllocator
Some issues:
srcDir
in config and convert them to relative imports in code. There are probably some corner cases to consider when emitting generated code outside of the source tree (is that even allowed?)The text was updated successfully, but these errors were encountered: