K
Kysely•8mo ago
mike

Custom Plugin to transform Alias.* to "Alias.Column1", "Alias.Column2", etc.

Hi everyone, in the previous question, I asked how to transform the following syntax into a new one. I was adviced to create my own plugin serializer (example: https://github.com/subframe7536/kysely-sqlite-tools/tree/master/packages/plugin-serialize). However, I still struggle with how to do it. Can anybody please give me a hint? I'll do it later by myself but need a guide how to start. Thank you very much! input syntax:
.SelectFrom('Table as Alias')
.SelectAll('Alias')
.SelectFrom('Table as Alias')
.SelectAll('Alias')
required result:
.SelectFrom('Table as Alias')
.Select('Alias.Column1 as "Alias.Column1"')
.Select('Alias.Column2 as "Alias.Column2"')
... all the rest columns in 'Alias' ...
.SelectFrom('Table as Alias')
.Select('Alias.Column1 as "Alias.Column1"')
.Select('Alias.Column2 as "Alias.Column2"')
... all the rest columns in 'Alias' ...
7 Replies
Unknown User
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
mike
mikeOP•8mo ago
you mean debug and checkout inside the plugin, right?
koskimas
koskimas•8mo ago
Kysely doesn't have the data required to convert selectAll('Alias') into select(['Alias.Column1', 'Alias.Column2']). Kysely only knows about Column1, Column2 etc. in the type level. You need to provide that information yourself somehow. You can't create a plugin that'd also make the types aware of the new Alias.Column1 and Alias.Column2 column names TLDR; It's impossible to create this plugin.
mike
mikeOP•8mo ago
😢 I've created class called KyselyBroker which consumes compiled-query and do some dynamic post-processing based on additional parameters and options so the result is easier to use in other db frameworks or ORMs. It's not fancy but it works. This one is however more complex - it's not just replace this with that. I'll think about it. The whole think is we have a huge implementation of sequelize already and we combine it (not replace) with Kysely. We use Kysely where Sequelize struggles.
Igal
Igal•8mo ago
Hey 👋 Have you tried https://github.com/kysely-org/kysely-sequelize by any chance?
GitHub
GitHub - kysely-org/kysely-sequelize: A toolkit (dialect, type tran...
A toolkit (dialect, type translators, etc.) that allows using your existing Sequelize instance with Kysely. - kysely-org/kysely-sequelize
mike
mikeOP•8mo ago
wow, I definitely haven't. I'll take a look for sure. Thank you
Igal
Igal•8mo ago
Getting some feedback would be great!
Want results from more Discord servers?
Add your server