drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.61k stars 649 forks source link

[BUG]: Drizzle Studio doesn't save strings in JSON fields #3586

Open helloryuko opened 1 day ago

helloryuko commented 1 day ago

Report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.3

What version of drizzle-kit are you using?

0.28.1

Other packages

No response

Describe the Bug

What is the undesired behavior?

Drizzle Studio row editor doesn't let using strings (a valid JSON object!) in a JSON column. Video demonstration: https://youtu.be/XeFh62uAOag

What are the steps to reproduce it?

  1. Create a jsonb column in schema
  2. Push the schema
  3. Run Drizzle Studio
  4. Try to enter a string instead of an object (e.g. "foo", not {"foo": "bar"})

    What is the desired result?

    Same as I expect from INSERT INTO items (id, name) VALUES ('test', '"a json stringy!!"'); - creating a row with JSON column name containing a string.

    What database engine are you using?

    Postgres with pg driver.

Schema

import { boolean, jsonb, pgTable, varchar } from "drizzle-orm/pg-core";

type Translatable = {
    ua: string | null;
    ru: string | null;
    en: string | null;
} | string;

const translatable = () => jsonb().$type<Translatable>();

export const items = pgTable("items", {
    id: varchar({ length: 128 }).primaryKey(),

    name: translatable(),
    description: translatable(),

    sellable: boolean().default(true),
});