drizzle-orm: [BUG]: Column name not being returned as snake_case
What version of drizzle-orm are you using?
0.34.1
What version of drizzle-kit are you using?
0.25.0
Describe the Bug
When using casing: 'snake_case' in the config and defining a column like so firstName: t.text().notNull()
And then when accessing the column name via users.firstName.name we get firstName instead of first_name
Same happens if we get the columns via getTableConfig(users).columns and getTableColumns(users)
Expected behavior
No response
Environment & setup
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 31
- Comments: 17
You need to pass
casingtodrizzle()too, not only in the drizzle-kit config.This is my current workaround. I’ve committed to snake_case for the project so not a huge deal, but would be nice to inherit casing from the config.
I can confirm
getTableColumns(table)with the snake_casing settings turned on returns the columns incorrectly as camelCase.Table was defined like
shortId: varchar({ length: 21 })It should be
I guess it’s to be expected, but this doesn’t affect the column name mappings for tables outside the context of a query. I’ve written a convenience method for
onConflictDoUpdateand I’m still getting the camelCase column name:The missing part for me was the opposite. I included
casing: 'snake_case'parameter in drizzle() but not in drizzle-kit config. I was following this guide, but configuring drizzle-kit is not mentioned there. Shall we mention drizzle-kit there?I’m seeing the same issue (using Vercel Postgres)
Adding
casing: 'snake_case'to both drizzle client and drizzle config does fix creating tables in snake case but it doesn’t return it in snake case when used with utils (e.g. getTableColumns) and with views which may lead drizzle studio to breakI was able to get my snake_case in the db right by specifying the casing in both
drizzle.config.tsand/src/db/index.ts, I believe this should be specified in the docs as I have spent hours making this workI have recently set up a fresh Supabase database (PostgreSQL)
my current setup is as follow
my
drizzle.config.tsmy
/src/db/index.tsmy
/src/db/schema.tsexecuting
npx drizzle-kit generateresulted in this migration fileI’m guessing this is also related here.
When running
drizzle-kit exportthe table names are also camelCased instead of snake_cased.drizzle-kit pushworks correctly.Same issue as @kaelruland - getting camelCase when snake_case is needed for excluded. As a workaround, I added the snake_case column name to the column definition.
getTableColumns()returns columns in camelCase instead of snake_case in migrations