tursodatabase / turso-cli

Command line interface to Turso.
https://turso.tech
MIT License
199 stars 33 forks source link

Turso databases GUI uses literal sql string for defaults instead of output #700

Open jschuur opened 8 months ago

jschuur commented 8 months ago

Looks like your Drizzle Studio version has problems executing default SQL when adding rows. Not sure where else to file this :)

Using Drizzle, I have a schema that looks (in part) like this:

export const locations = sqliteTable('locations', {
  id: integer('id').primaryKey(),
  name: text('name').notNull(),
  createdAt: integer('created_at', { mode: 'timestamp' })
    .default(sql`(cast (unixepoch() as int))`)
    .notNull(),
  updatedAt: integer('updated_at', { mode: 'timestamp' })
    .default(sql`(cast (unixepoch() as int))`)
    .notNull(),
});

This creates the following migration:

CREATE TABLE `locations` (
    `id` integer PRIMARY KEY NOT NULL,
    `name` text NOT NULL,
    `created_at` integer DEFAULT (cast (unixepoch() as int)) NOT NULL,
    `updated_at` integer DEFAULT (cast (unixepoch() as int)) NOT NULL
);

Now if i visit https://turso.tech/app/databases and add a new record and leave the date fields blank, this creates an entry that lists (cast (unixepoch() as int)) and not an epoch timestamp as expected:

CleanShot 2023-10-23 at 15 53 28@2x

Likewise, in the turso db shell I get similar:

→  select id, name, created_at, updated_at from locations where id = 1;
ID     NAME       CREATED AT                      UPDATED AT
1      London     (cast (unixepoch() as int))     (cast (unixepoch() as int))

The default works fine if I run a SQL command in the shell though:

→  insert into locations (name, slug, metrics) values ('Beijing', 'beijing', '["temp"]');
→  select id, name, created_at, updated_at from locations where name='Beijing';;
ID     NAME        CREATED AT     UPDATED AT
4      Beijing     1698047909     1698047909
haaawk commented 8 months ago

Thank you for reparting @jschuur. @gris Could you have a look at this please?

lbenevenuto commented 8 months ago

With this config it seams to work createdAt: integer('created_at', { mode: 'timestamp_ms' }).default(sql(unixepoch())), updatedAt: integer('updated_at', { mode: 'timestamp_ms' }).default(sql(unixepoch())),

The issue is on Studio visualization image

mrheio commented 2 months ago

I'm also getting unixepoch() as value in the database column. Any update on this matter?