add mapping for text search types
abenhamdine opened this issue · 4 comments
A powerfull feature in postgres is the full text search, which can be perfectly used as a replacement of nosql similar features (elastic search, etc).
For this, postgres provides several types :
- tsquery
- tsvector
- tsrange
see https://www.postgresql.org/docs/current/static/datatype-textsearch.html
The udt names are the sames as the postgres type names :
SELECT column_name, udt_name
FROM information_schema.columns
WHERE table_name = 'test' and table_schema = 'public'
gives
I don't know exactly which typescript type to map to these types, as usually theses types are manipulated with built-in functions/casts, like ::tsvector
or to_tsvector
and can not be inserted like simple strings.
Perhaps the any
type is the most appropriate for this ?
I'm not really sure how to deal with this. If pg does not provide a typecast for it, then it's safe to give it an any
type.
All things considered, wouldn't it be better to map any
for any unknown type ? Because it's likely that we miss some valid types in the mapping (this time it's tsvector, next time it will be veryRarePgTypeButValidOne, etc...).
What you think about returning any
for any unrecognized type in the mapping, and print a warning in the console (eg : Warning : type foo is unknown and will be mapped with any
type) ?
Yup let's do that.
Yes, it is much better for an unknown type to generate type any
, and show a warning, rather than just throw an error and stop.