icarus
icarus
DTDrizzle Team
Created by icarus on 10/31/2024 in #help
A way to make a custom type generatedAlwaysAsIdentity
but thank you for the attempt anyway
16 replies
DTDrizzle Team
Created by icarus on 10/31/2024 in #help
A way to make a custom type generatedAlwaysAsIdentity
yeah I wish there was a simple .transform function available on all types similar to zod's
16 replies
DTDrizzle Team
Created by icarus on 10/31/2024 in #help
A way to make a custom type generatedAlwaysAsIdentity
16 replies
DTDrizzle Team
Created by icarus on 10/31/2024 in #help
A way to make a custom type generatedAlwaysAsIdentity
think something like the following, for the sake of simplicity
export const customId = customType<{
data: string;
driverData: number;
notNull: true;
default: true;
}>({
dataType() {
return "INTEGER GENERATED ALWAYS AS IDENTITY";
},
fromDriver(value: number) {
return value.toString();
},
toDriver(value: string) {
return Number(value);
},
});
export const customId = customType<{
data: string;
driverData: number;
notNull: true;
default: true;
}>({
dataType() {
return "INTEGER GENERATED ALWAYS AS IDENTITY";
},
fromDriver(value: number) {
return value.toString();
},
toDriver(value: string) {
return Number(value);
},
});
16 replies
DTDrizzle Team
Created by icarus on 10/31/2024 in #help
A way to make a custom type generatedAlwaysAsIdentity
i do need to use a custom type. to do some custom encoding/decoding to the integer coming from/going to the database
16 replies
DTDrizzle Team
Created by icarus on 10/31/2024 in #help
A way to make a custom type generatedAlwaysAsIdentity
all issues related to this on github were closed with the release of generatedAlwaysAs and generatedAlwaysAsIdentity, but none of those two actually fix this issue as you can't do something like:
id: customId("id").primaryKey().generatedAlwaysAsIdentity()
id: customId("id").primaryKey().generatedAlwaysAsIdentity()
16 replies
DTDrizzle Team
Created by LeFuncq on 11/22/2023 in #help
Create unique slugs with $defaultFn
you're welcome :)
7 replies
DTDrizzle Team
Created by LeFuncq on 11/22/2023 in #help
Create unique slugs with $defaultFn
i've also been looking into doing something like that recently, i think the best approach that'd work for you with how drizzle is currently is to create a trigger in the database layer, and have it fill your generated column on every insert
7 replies
DTDrizzle Team
Created by NotLuksus on 4/4/2023 in #help
"Extend" tables by other tables
yea the table builders just take regular js objects for columns, so u can simply do something like this:
const commonColumns = {
id: serial("id").primaryKey(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow().onUpdateNow(),
};

export const users = mysqlTable("users", {
...commonColumns,
username: varchar("username", { length: 128 }).notNull(),
bio: varchar("bio", { length: 255 }),
});

export const cars = mysqlTable("cars", {
...commonColumns,
name: varchar("name", { length: 128 }),
});
const commonColumns = {
id: serial("id").primaryKey(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow().onUpdateNow(),
};

export const users = mysqlTable("users", {
...commonColumns,
username: varchar("username", { length: 128 }).notNull(),
bio: varchar("bio", { length: 255 }),
});

export const cars = mysqlTable("cars", {
...commonColumns,
name: varchar("name", { length: 128 }),
});
2 replies
DTDrizzle Team
Created by icarus on 3/30/2023 in #help
drizzle-orm/mysql-core has no InferModel or MySqlRawQueryResult exports
Oh that makes sense, thanks for the clarification :)
27 replies
DTDrizzle Team
Created by icarus on 3/30/2023 in #help
drizzle-orm/mysql-core has no InferModel or MySqlRawQueryResult exports
Yes I just figured that part out, importing InferModel from drizzle-orm works, but MySqlRawQueryResult seems to be missing still.
27 replies