Simulate enums with SQLite `CHECK()`
I'm a heavy enum user in Postgres. Using SQLite now, wondering if anyone has come up with something clever to narrow a TEXT value to some values, perhaps based on
CHECK()
constraints, which kind of give you what ENUM does.Migrating from Prisma gradually
We're in the middle of migrating away from Prisma to Drizzle which we just found out that Drizzle has its own naming convention for
FOREIGN KEY CONSTRAINT
.
To avoid surprises for this migration, we'd like to keep Prisma constraint names, I looked into the reference()
type definitions, it seems that we don't have a way to customise the FOREIGN KEY CONSTRAINT
name, is that correct?
At the same time, the current generated constraint name is longer than Postgres's allowed length. How can we workaround this?...select with limit of 1
Is there a cleaner way of selecting only one item with proper type safety than this?
...
const user: User | undefined = (await db.select().from(users).where(eq(users.id, userId)).limit(1))[0];
const user: User | undefined = (await db.select().from(users).where(eq(users.id, userId)).limit(1))[0];
Option filter parameters
Hi! Love using drizzle so far! Had a quick question (not a bug):
```
const res = await ctx.database
.select()...
How to delete with cascade?
I'm using postgres with the following schema (reduced to the important parts):
```
export const worlds = pgTable('worlds', {
id: uuid('id').defaultRandom().primaryKey()...
PSQL SQL query does not work
Unable to achieve it with Drizzle helpers - I had to write my query in plain SQL.
I'm trying to build a query that looks like this;
```...
drop tables
Is there a way to do a migration to drop tables? Other ORMs like Sequelize and Prisma have a concept of up & down migrations, but Drizzle doesn't. Is there a Drizzle way to do a "down" migration?
db.query error with relation
I have created a schema.ts, with two tables, with a one-to-one relationship. I have also create the "relation".
In my index file, I get an error with the following code
```...
How to transform to camelCase with json_agg()?
As topic. I can't find any example on how to go about this. The closest I can find is https://orm.drizzle.team/docs/sql#sqlmapwith, but this feels counter-productive as we will have to do it every time we need it. Is there a better way?
Count in relational queries
How do I count in relational queries? For example if i'm querying db.query.posts.findMany() and want to include an extra field that counts the number of likes (diff table), how can I achieve that? Couldn't make it work with the "extras" and trying to make a sql
count()
there.
Thanks in advance...Create a type of VARCHAR[]
I want to create a type for my column of
VARCHAR[]
but when I used Drizzle-Kit to generate it, I got the drizzle-kit
that generated "varchar[]"
type instead of VARCHAR[]
Here's how I defined the column;
anonymousIds: varchar("anonymous_ids").array()
It represents an array of ids....Select with relation
Is there a way to get relations when using
db.select().from(table)
I can't get the db.query.table.findMany
to work, so if someone could help me get that setup that would be fine too`where` inside relational queries `with` does not work
Hi there! I'm new to drizzle and tried out the relational queries.
I want to do a nested
where
rule inside a with
relation. But doing it is giving me type errors (Object literal may only specify known properties, and where does not exist in type
) and it's just ignored by the orm.
Maybe someone knows what I am doing wrong and why I don't get the option to do a where
. Thanks in advance!...Issue with 'insert on conflict do update where'
I am using
db.insert(lastHeaterMetricsTable)
.values(heaterEntityWithMaxTime)
.onConflictDoUpdate({
target: lastHeaterMetricsTable.deviceId,...

Duplicate relations when using `with`
I'm running into a problem where some duplicate values are being returned through a relation with
with
.
Basically, I'm getting
```...Using BIN_TO_UUID / UUID_TO_BIN
I’m trying to understand the best way to use
BIN_TO_UUID
and UUID_TO_BIN
(MySQL).
The below is working fine...
```typescript...drizzle-kit drop config file does not exist
I have a
/foo/drizzle.config.ts
file as suggested in the docs (https://orm.drizzle.team/kit-docs/conf).
When I run drizzle-kit drop
it fails because it can't locate the config file:
```...Related object is not typed correctly
I have the following schema
```
export const menus = pgTable('menus', {
id: uuid('id').primaryKey(),
name: varchar('name', { length: 256 }).notNull(),...