drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Add text(..., { mode: "timestamp" }) support to SQLite

Open
#3,154 5 comments 33 reactions 0 assignees View on GitHub
db/sqlite enhancement
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.