drizzle-team / drizzle-team/drizzle-orm
[BUG]:pgTable column renders as undefined in sql
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [x] I have verified that the bug I'm about to report hasn't been filed before.
### What version of `drizzle-orm` are you using?
0.39.1
### What version of `drizzle-kit` are you using?
N?A
### Other packages
_No response_
### Describe the Bug
```ts
import {drizzle} from 'drizzle-orm/postgres-js'
const db = drizzle('postgres://...', {logger: true})
const t1 = pgTable('table', (t) => ({
id: t.text().primaryKey(),
}))
console.log(
t1.id.name,
db.insert(t1).values({id: '1'}).toSQL(),
)
// id { sql: 'insert into "table" ("id") values ($1)', params: [ '1' ] }
const t2 = pgTable('table', (t) => ({
id: t.text().primaryKey(),
name: t.text(),
}))
const query = db.insert(t2).values({id: '1', name: 'test'}).toSQL()
console.log(t2.name.name, query)
// {
// sql: 'insert into "table" ("id", "undefined") values ($1, $2)',
// params: [ '1', 'test' ]
// }
```
See the repro step above. It appears that drizzle is unexpectedly caching columns based on table names, and that breaks when you construct tables dynamically
Upon some digging, I believe this is due to the unfortunate `CasingCache`
Contributor guide
Assessment
This issue has not been assessed yet.