ak4zh
ak4zh
DTDrizzle Team
Created by ak4zh on 11/17/2024 in #help
libsql not generating migration for generatedAlwaysAs
No migration were detected by the drizle when I changed from this
buildDate: integer("created", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
buildYear: integer(),
buildDate: integer("created", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
buildYear: integer(),
to this
buildDate: integer("created", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
buildYear: integer().generatedAlwaysAs(
(): SQL => sql`CAST(strftime('%Y', ${vehicles.buildDate}, 'unixepoch') AS INTEGER)`,
{ mode: "stored" }
),
buildDate: integer("created", { mode: "timestamp" })
.notNull()
.default(sql`(unixepoch())`),
buildYear: integer().generatedAlwaysAs(
(): SQL => sql`CAST(strftime('%Y', ${vehicles.buildDate}, 'unixepoch') AS INTEGER)`,
{ mode: "stored" }
),
1 replies
DTDrizzle Team
Created by ak4zh on 7/15/2024 in #help
Column name different in drizzle magic sql vs drizzle-orm
I use camelCase column names for the ORM and snake_case for the databse columns. Queries run through ORM returns camelCase columns but if I use drizzle.execute(sql``) it results in snake_case columns any workaround ?
4 replies
DTDrizzle Team
Created by ak4zh on 7/13/2024 in #help
Infer date values in jsonb column as Date object
I used $types<>() to provide the type for my jsonb column but the returned value is date string not a js Date object.
type InvoiceSchema = {
invoiceNumber: string;
invoiceDate: Date;
items: {
name: string;
}[];
value?: number;
}
export const myTable = pgTable('my_table', {
invoices: jsonb("invoices").$type<InvoiceSchema[]>(),
})
type InvoiceSchema = {
invoiceNumber: string;
invoiceDate: Date;
items: {
name: string;
}[];
value?: number;
}
export const myTable = pgTable('my_table', {
invoices: jsonb("invoices").$type<InvoiceSchema[]>(),
})
Output Data
{
invoices : [
{
invoiceNumber: '3432423',
invoiceDate: '2024-07-13T00:00:00.000Z',
value: null,
items: [ [Object] ]
}
]
}
{
invoices : [
{
invoiceNumber: '3432423',
invoiceDate: '2024-07-13T00:00:00.000Z',
value: null,
items: [ [Object] ]
}
]
}
25 replies
DTDrizzle Team
Created by ak4zh on 8/24/2023 in #help
adding default to array of text creates invalid migrations
values: text('values').array().notNull().default(['a', 'b']) generates: ALTER TABLE "test" ALTER COLUMN "values" SET DEFAULT a,b; Should be: ALTER TABLE "test" ALTER COLUMN "values" SET DEFAULT ARRAY['a', 'b'];
"drizzle-orm": "^0.28.3",
"drizzle-kit": "^0.19.13",
"pg": "^8.11.3"
"drizzle-orm": "^0.28.3",
"drizzle-kit": "^0.19.13",
"pg": "^8.11.3"
6 replies