drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: SQLITE - Introspect `BOOLEAN` as `integer("...", { mode : "boolean" })`

Open
#2,539 2 comments 1 reaction 0 assignees View on GitHub
db/sqlite drizzle/kit enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

We are trying to use Drizzle with SQLite. The drizzle schema is not the source of truth, so we are trying to introspect the DB and make minor tweaks if needed.

I noticed that `BOOLEAN` is introspected as `numeric()` by Drizzle. In SQLite, `BOOLEAN` is just syntactic sugar, but could that be used to infer `number("column", { mode: "boolean" })` instead of `numeric("column")`. I believe numeric is actually the correct thing to convert to, according to Column Affinity though.

> SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true).
SQLite recognizes the keywords "TRUE" and "FALSE", as of version 3.23.0 (2018-04-02) but those keywords are really just alternative spellings for the integer literals 1 and 0 respectively.

https://www.sqlite.org/datatype3.html#boolean_datatype

```sql
active BOOLEAN NOT NULL

# Results in
active: numeric("active").notNull(),
```

After a quick play with Prisma, I noticed that they are introspecting `BOOLEAN` as a Prisma `Boolean`. Making it a lot easier to work with in your app logic. The issue with numeric is, anything is accepted.

Contributor guide

Open the contributing guide

Research direction

No files, tests, or entry points are named. Start by locating SQLite introspection and compare how a BOOLEAN column is currently mapped to numeric("column"); done means the generated schema uses the requested boolean mode while preserving the column's constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite, typescript
Domain
databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.