isitayush
isitayush
Explore posts from servers
DTDrizzle Team
Created by isitayush on 12/5/2023 in #help
search on all `with` and `columns` fields via text (sqlite)
Hi! I'm using better-sqlite3 as the driver. I have a bunch of fields selected via columns & with (nested fields) & an offset based pagination. I'm using the querybuilder (.query). How would I go about performing a full text search on the selected columns as well as the selected nested columns? Say,
const { offset, query, limit} = input;
const result = ctx.db.query.myModel.findMany({
limit: limit ?? 10,
offset: offset ?? 0,
with: ...,
columns: ...
});
const nextOffset: number = result.length + (offset ?? 0);
return {
data: result,
nextOffset: nextOffset
};
const { offset, query, limit} = input;
const result = ctx.db.query.myModel.findMany({
limit: limit ?? 10,
offset: offset ?? 0,
with: ...,
columns: ...
});
const nextOffset: number = result.length + (offset ?? 0);
return {
data: result,
nextOffset: nextOffset
};
I'm including towards using where: or(x, or(y, or())) but i'm not sure that's correct (& would work for slected nested relations). Let me know!!
14 replies
DTDrizzle Team
Created by isitayush on 9/23/2023 in #help
accessing related foreign tables via sql operator
No description
1 replies
DTDrizzle Team
Created by isitayush on 5/14/2023 in #help
I think I don't really understand migrations local sqlite.
It's a local sqlite db (DB_URL=file:dev.db) in a nextjs & trpc setup. I'm trying drizzle for the first time & I did follow the steps mentioned https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/sqlite-core/README.md#-quick-start. I ran npx drizzle-kit generate:sqlite & it succesfully generated a migration. Good Job Drizzle! The problem is how do I push these migrations to my dev.db file? Do I need to push them manually? Am I missing something? I was planning to later use Turso & switch to it but even in the case of turso, I think I would have to manually write each migration in the db shell. Drizzle Kit does not have a push command for sqlite. I'm using drizzle-kit: v0.17.6 drizzle-orm: v0.25.4. Any help is appreciated as I'm tired reading docs & searching for similar issues here.
13 replies
TtRPC
Created by isitayush on 2/17/2023 in #❓-help
typesafe permissions
Hi, So I wanted to infer all the procedures from my router recursively & assign a permission (string[]) to each one them. I wrote the following,
type GetProceduresRecusivelyAndAssignPermissions<T extends AnyRouter> = {
[K in keyof T]: T[K] extends AnyProcedure
? { permissions: string[] }
: T[K] extends AnyRouter
? GetProceduresRecusivelyAndAssignPermissions<T[K]>
: never;
};

const permissions: GetProceduresRecusivelyAndAssignPermissions<
typeof appRouter
> = {
example: { getData: { permissions: ["canGetData"] } },
};
type GetProceduresRecusivelyAndAssignPermissions<T extends AnyRouter> = {
[K in keyof T]: T[K] extends AnyProcedure
? { permissions: string[] }
: T[K] extends AnyRouter
? GetProceduresRecusivelyAndAssignPermissions<T[K]>
: never;
};

const permissions: GetProceduresRecusivelyAndAssignPermissions<
typeof appRouter
> = {
example: { getData: { permissions: ["canGetData"] } },
};
It works however, I get a red squiggly (error) under the example in my permissions object with the following error message.
Type '{ getData: { permissions: string[]; }; }' is missing the following properties from type 'GetProceduresRecusivelyAndAssignPermissions<CreateRouterInner<RootConfig<{ ctx: ....
Type '{ getData: { permissions: string[]; }; }' is missing the following properties from type 'GetProceduresRecusivelyAndAssignPermissions<CreateRouterInner<RootConfig<{ ctx: ....
In my above type, I am trying to check if the key is a procedure, then simply returning the permissions. Otherwise checking if the key is a router then repeating it recursively. I'm unable to figure out what I'm doing wrong. Can someone help fix this. : )
28 replies
TtRPC
Created by isitayush on 2/14/2023 in #❓-help
awaiting for procedure & logging the response.
Hi, I was wondering if there is a way to handle the return object via the post-middleware's? I know we could do something like,
const logMiddleware = t.middleware(async ({ ctx, next }) => {
const res = await next();
// insert logging here
return res;
);
const logMiddleware = t.middleware(async ({ ctx, next }) => {
const res = await next();
// insert logging here
return res;
);
However, I want to access the returned result with an event name & log it. This event name could be returned by the procedure itself as one of the key's of res. The problem is I can't access the res object as it's of type MiddlewareResult & is the whole request itself that is returned from a procedure's query/mutation. How should I go about solving this? Is there a way I could destruct the data returned from next() and wrap it in a defined type say something similar to,
type Response = {
event: "requested_data"; // res.response.type
request: { ip: res.req.headers.forwarded, ua: ...},
time: 18214931949,
data: { type: "query/mutation", path: "procedure path", ctx: res.ctx, input: res.input, response: res.response.message
},
}
type Response = {
event: "requested_data"; // res.response.type
request: { ip: res.req.headers.forwarded, ua: ...},
time: 18214931949,
data: { type: "query/mutation", path: "procedure path", ctx: res.ctx, input: res.input, response: res.response.message
},
}
& fill in the fields with my res object. log the response to my db & return res.reponse to my client.
3 replies