Skip to content
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 Postgres generated column #26

Closed
AzSiAz opened this issue Dec 3, 2021 · 6 comments
Closed

Support Postgres generated column #26

AzSiAz opened this issue Dec 3, 2021 · 6 comments
Labels
api Related to library's API enhancement New feature or request

Comments

@AzSiAz
Copy link

AzSiAz commented Dec 3, 2021

I didn't found a way to use Postgres generated column or to alter a table to add a generated column (no view/materialized view either)

My use case is storing a tsvector representation of another column to allow faster searching with a gin index

Link to the doc just in case

@koskimas
Copy link
Member

koskimas commented Dec 3, 2021

You can always run raw queries in migrations using db.raw. Views could be one of the next things to add. I've never used generated columns or heard anyone using them. But I'll see if it's easy to add support for those too.

@AzSiAz
Copy link
Author

AzSiAz commented Dec 3, 2021

True, I could always create the table and add a manual alter table after 🤔

Generated column are quite new (PG 12) and to be honest the only time I saw them used is here

@koskimas
Copy link
Member

koskimas commented Dec 4, 2021

0.9.9 version now has createView and dropView methods in the schema module.

@koskimas
Copy link
Member

koskimas commented Dec 5, 2021

0.10.0 also supports materialized views. There's a couple of breaking changes in 0.10.0 https://github.com/koskimas/kysely/releases

@koskimas
Copy link
Member

koskimas commented Dec 5, 2021

Generated columns are now also supported in master. Not released yet. You can use it like this:

db.schema
  .createTable('person')
  .addColumn('full_name', 'varchar(255)',
    (col) => col.generatedAlwaysAs("concat(first_name, ' ', last_name)").stored()
  )
  .execute()

@AzSiAz
Copy link
Author

AzSiAz commented Dec 5, 2021

Thanks for those 3 extremely quick update, I will try to test these new migration as soon as I can

To be honest I had to replace some prisma query for more optimized query and working with Kysely as been fantastic so far, so thank you ☺️

@igalklebanov igalklebanov added enhancement New feature or request api Related to library's API labels Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to library's API enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants