drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: Add text(..., { mode: "timestamp" }) support to SQLite
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Describe what you want
Currently, SQLite allows default values for a `text` column to be set as `CURRENT_TIMESTAMP`. Drizzle however only automatically casts `integer(..., { mode: 'timestamp' }` (and `_ms`) to `Date` objects, making those two features incompatible.
We should allow `text` to also be a `timestamp` so it can be used in conjunction with the default value:
```js
export const log = sqliteTable("log", {
id: integer("id").primaryKey(),
// ...
created:
text("created", { mode: "timestamp" })
.default(sql`(CURRENT_TIMESTAMP)`),
});
```
Expecting `created` to be of type `Date` when selecting.
### Why?
Currently it isn't possible to achieve the "default to current timestamp" when columns are of type integer, only text.
Contributor guide
Research direction
Start at the SQLite text(...) and integer(..., { mode: "timestamp" }) column implementations, then locate their existing type or mapping tests. Trace how the mode affects selected values and the default sql`(CURRENT_TIMESTAMP)` expression. Done means text("created", { mode: "timestamp" }) accepts the configuration and selecting the column returns a Date, with coverage for the example case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- sqlite, typescript
- Domain
- database
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100