Access column type in custom plugin
Hey!
We would like to access the column type in one of my custom Kysely plugins.
The AST does not seem to know the column type in the
transformQuery
method.
Is there a way to access the column types within our plugin?
Our ultimate goal would be to convert ISO8601 strings into JavaScript Date
s. The used dialect (kysely-data-api
) is not doing that out-of-the-box. It seems a common way to do this would be to use a regex for an ISO8601 compatible string, but as this would not consider the timestamp
column type, we may transform strings that should rather not be transformed.
Any ideas would be appreciated 🙏
Thank you!Solution:Jump to solution
That info is not available. The only way to get it is to query the db and Kysely never runs queries you don't explicitly execute.
4 Replies
Solution
That info is not available. The only way to get it is to query the db and Kysely never runs queries you don't explicitly execute.
I don't think that's true, because there is the
DatabaseIntrospector
: https://kysely-org.github.io/kysely/interfaces/DatabaseIntrospector.htmlDatabaseIntrospector | kysely
Documentation for kysely
well it is true. the introspector's code never runs as part of, e.g. a select query, so that info is not available in the query's results or syntax tree.
even if it did run, let's say, on kysely initialization, that'd only cover the tables, no computed values and no raw sql.
your best bet is to use something like date-fns'
parseJson
in a custom pluginYep. I'm relatively sure what gets executed and what doesn't.. There's an introspection module, but it's not used automatically. You can call it and build a plugin using it, but making it work in all cases is hard.