nico
nico
Explore posts from servers
DTDrizzle Team
Created by nico on 11/9/2024 in #help
SQLite insert schema does not include nullable columns?
Hi, I am just tring out Drizzle with SQLite, but am running into some weird problem. I created a table like this
export const products = sqliteTable(
"products_table",
{
id: int().primaryKey(),
name: text().notNull(),
type: text(),
sku: text(),
externalId: text("external_id").notNull().unique(),
price: text(),
regularPrice: text("regular_price"),
salePrice: text("sale_price"),
manageStock: int("manage_stock", { mode: "boolean" }),
stockQuantity: int("stock_quantity"),
},
(table) => {
return {
nameIdx: index("sku_idx").on(table.sku),
};
}
);
export const products = sqliteTable(
"products_table",
{
id: int().primaryKey(),
name: text().notNull(),
type: text(),
sku: text(),
externalId: text("external_id").notNull().unique(),
price: text(),
regularPrice: text("regular_price"),
salePrice: text("sale_price"),
manageStock: int("manage_stock", { mode: "boolean" }),
stockQuantity: int("stock_quantity"),
},
(table) => {
return {
nameIdx: index("sku_idx").on(table.sku),
};
}
);
Now when I infer the insert schema, or just try to insert data, typescript allways throws an error as it expects this schema:
{
name: string;
sku: string;
price: string;
regularPrice: string;
}
{
name: string;
sku: string;
price: string;
regularPrice: string;
}
It seems like to only includes columns that are not optional (and indexed clumns). This is preventing me from buildung my application as typescript allways throws when I try to insert data into the db. Does someone know why this happens and how to prevent it?
2 replies
TTCTheo's Typesafe Cult
Created by nico on 2/1/2024 in #questions
How would you go about layered authentication?
I have an upcomming project where it might be useful to have layered authentication. As an example: If you login to my app, you would do so using a magic link. This is enough to use the app and so on. But if you want to access your invoices or other financial data, you would need to authenticate using your secound factor (for example sms otc). How would you go about something like this? Is there an authentication solution provider who supports use cases like this? Thanks a lot! Nico
3 replies
TTCTheo's Typesafe Cult
Created by nico on 2/1/2024 in #questions
Integrating Clerk: How to supply req to createTRPCContext on server-side?
Hi! I am currently trying to integrate Clerk into an T3 Setup with tRPC, App Router and Drizzle. Everything goes relatively smooth. Clerk needs the NextRequest object tho, so I updated the createTRPCContext to reflect that:
export const createTRPCContext = async (opts: { req: NextRequest }) => {
return {
db,
auth: getAuth(opts.req),
headers: opts.req.headers,
...opts,
};
};
export const createTRPCContext = async (opts: { req: NextRequest }) => {
return {
db,
auth: getAuth(opts.req),
headers: opts.req.headers,
...opts,
};
};
The problem is on the Server-Side. In server.ts (src/trpc/server.ts) the createTRPCProxyClient creates a trpcLink that uses the following code:
const createContext = cache(() => {
const heads = new Headers(headers());

heads.set("x-trpc-source", "rsc");

return createTRPCContext({
headers: heads,
});
});
const createContext = cache(() => {
const heads = new Headers(headers());

heads.set("x-trpc-source", "rsc");

return createTRPCContext({
headers: heads,
});
});
` I would need to update this, so it supplies the request to createTRPCContext. Does anyone know how to do this? Thanks a lot! Nico
6 replies