K
Kyselylukas.slezevicius

How to add table/column comments when creating tables?

Hey, we're approaching close to 100 tables in our project. New people will be joining our founding team and we thought documenting the tables using the Postgres table/column commenting feature would make it easier to understand the DB schema. After searching the docs, discord, and google, I couldn't find any info on how to do this in Kysely. Should we resort to raw SQL? Thanks!
Solution:
Hey 👋 Kysely supports column comments in introspectors. This should allow external codegen tools (e.g. kysely-codegen) to generate types with jsdocs. Builders don't have built-in support for adding comments on tables or columns. You can use modifyEnd where possible to add comments with sql template tag....
Solution
Igal
Igal•36d ago
Hey 👋 Kysely supports column comments in introspectors. This should allow external codegen tools (e.g. kysely-codegen) to generate types with jsdocs. Builders don't have built-in support for adding comments on tables or columns. You can use modifyEnd where possible to add comments with sql template tag.
import { sql } from 'kysely'

await db.schema
.createTable('awesome_stuff')
.addColumn('price', 'double precision', (col) =>
col.notNull().modifyEnd(sql`comment ${sql.lit('Price in USD')}`),
)
.modifyEnd(sql`comment ${sql.lit('This table is awesome!')}`)
.execute()
import { sql } from 'kysely'

await db.schema
.createTable('awesome_stuff')
.addColumn('price', 'double precision', (col) =>
col.notNull().modifyEnd(sql`comment ${sql.lit('Price in USD')}`),
)
.modifyEnd(sql`comment ${sql.lit('This table is awesome!')}`)
.execute()
lukas.slezevicius
lukas.slezevicius•36d ago
Thank you!!
Igal
Igal•36d ago
We might have missed a few spots with modifyEnd , so if you see any that miss it, let us know.
Want results from more Discord servers?
Add your server
More Posts
Need help improving a custom helperMy dopamine with Kysely is quite high right now, so I am experimenting all sorts of things to createjsonArrayFrom with `as` not being typedI have the following query ```ts await db .selectFrom('user') .selectAll() .select((eb) How to use multiple schema definitions ( e.g. <catalog>.<schema>.<table> )Hey guys, I'm currently working on a new version for our graphql wrapper. Currently we're using kneUsing raw SQL with `or` whereI have been using the raw SQL template tag to work with certain JSON columns and wanted to add a `orCustom 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.can kysely be extended with custom types within the databasehi. i would like to extend my database with custom types (a date type for sqlite) so that it is easinewbie need help with json_build_objectHi! Just starting with kysely and encountered problem I cant solve. I want to build raw query with kSolved: Exporting query builder classesI saw this PR https://github.com/kysely-org/kysely/pull/763 where you guys have decided not to exporbuilding kysely makes the package size very largehi. i'd be more than happy to figure this out because i like kysely a lot more than drizzle. the thiKysely setup in monolith APIHello, we have a basic http server with a basic router and a PostgreSQL database. We're wondering whIs it possible to get the total count while fetching rows in a single query?I have a query which looks like this: ```typescript const { items, count } = await db .selectFrom(Separating results of join into objects of each typeHey guys, I'm curious if anyone knows a way to unmerge the results of a join into objects of both ty