dandadan
dandadan
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
async function findMany<
TSchema extends Record<string, unknown>,
DB extends PostgresJsDatabase<TSchema>,
TableName extends keyof NonNullable<DB["_"]["schema"]>,
>(db: DB, table: TableName) {
return await db.query[table].findMany();
}
findMany(db, "users");
async function findMany<
TSchema extends Record<string, unknown>,
DB extends PostgresJsDatabase<TSchema>,
TableName extends keyof NonNullable<DB["_"]["schema"]>,
>(db: DB, table: TableName) {
return await db.query[table].findMany();
}
findMany(db, "users");
this was probably my best attempt, unfortunately findMany errors with This expression is not callable
15 replies
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
i guess whats left is to figure out if the previous desired behavior is at least achievable using the query api
15 replies
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
this basically means you can pass whatever you want to it as long as its an actual table, it doesnt restrict possible tables based on the schema
15 replies
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
No description
15 replies
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
unfortunately, what _.schema has is not the same thing as the actual schema youre supposed to use inside .from()
15 replies
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
or, an even simpler example, achieving something like this
let tb = db._.schema?.users
if (tb) {
db.select().from(tb);
}
let tb = db._.schema?.users
if (tb) {
db.select().from(tb);
}
15 replies
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
unfortunately i havent been able to write an interface for that function that actually types out correctly
15 replies
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
ive messed around with many things, such as
async function testing<
TSchema extends Record<string, unknown>,
DB extends PostgresJsDatabase<TSchema>,
>(x: DB, table: keyof DB["_"]["schema"]) {
let schema = x._.schema;
if (schema === undefined) {
throw new Error("Schema is undefined");
}
return await x.select().from(schema[table]).limit(1);
}
async function testing<
TSchema extends Record<string, unknown>,
DB extends PostgresJsDatabase<TSchema>,
>(x: DB, table: keyof DB["_"]["schema"]) {
let schema = x._.schema;
if (schema === undefined) {
throw new Error("Schema is undefined");
}
return await x.select().from(schema[table]).limit(1);
}
15 replies
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
i think the goal is to achieve something like this
15 replies
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
async function findMany<DB extends PostgresJsDatabase, TableName>(db: DB, table: TableName) {
let schema = null; // get schema from db instance
return await db.select().from(schema).limit(1);
}

findMany(db, "users");
async function findMany<DB extends PostgresJsDatabase, TableName>(db: DB, table: TableName) {
let schema = null; // get schema from db instance
return await db.select().from(schema).limit(1);
}

findMany(db, "users");
15 replies
DTDrizzle Team
Created by giovannibenussi on 1/15/2024 in #help
Get Schema From db instance
following this
15 replies
DTDrizzle Team
Created by Md Jahidul Islam milon on 7/6/2023 in #help
union or union all in drizzle orm?
2 replies
DTDrizzle Team
Created by francis on 9/13/2023 in #help
How to include array literals in raw sql?
ive got it working with the following
const sanitizeArray = (arr: string[]) => {
const sanitizedArray: SQL<unknown>[] = [sql`[`];
const rawArray: SQL<unknown>[] = [];

for (const element of arr) {
rawArray.push(sql`${element}`);
}
sanitizedArray.push(sql.join(rawArray, sql`, `));
sanitizedArray.push(sql`]`);

const sanitizedQuery = sql.join(sanitizedArray);
return sanitizedQuery;
};

const tokens = ["a", "b"];
const sanitizedTokens = sanitizeArray(tokens);
const x = sql`SELECT unnest(ARRAY${sanitizedTokens}) AS word`;
const sanitizeArray = (arr: string[]) => {
const sanitizedArray: SQL<unknown>[] = [sql`[`];
const rawArray: SQL<unknown>[] = [];

for (const element of arr) {
rawArray.push(sql`${element}`);
}
sanitizedArray.push(sql.join(rawArray, sql`, `));
sanitizedArray.push(sql`]`);

const sanitizedQuery = sql.join(sanitizedArray);
return sanitizedQuery;
};

const tokens = ["a", "b"];
const sanitizedTokens = sanitizeArray(tokens);
const x = sql`SELECT unnest(ARRAY${sanitizedTokens}) AS word`;
im not even sure where i picked up the snippet of code from im leaving this here in case someone has a better solution
3 replies
DTDrizzle Team
Created by Md Jahidul Islam milon on 7/9/2023 in #help
how to use insert with select in drizzle?
nvm, you cant you should either use sql with the embedded column names, or a transaction
13 replies
DTDrizzle Team
Created by Md Jahidul Islam milon on 7/9/2023 in #help
how to use insert with select in drizzle?
although in your case you could probably just use db.insert() since the query is straight forward (unless the query you provided is just an example and in reality yours is much more complex)
13 replies
DTDrizzle Team
Created by Md Jahidul Islam milon on 7/9/2023 in #help
how to use insert with select in drizzle?
you can just write the names of the columns directly, i havent found another way
13 replies
DTDrizzle Team
Created by Md Jahidul Islam milon on 7/9/2023 in #help
how to use insert with select in drizzle?
any updates on this by any chance? was in need of something similar and was wondering if it has been implemented in the meanwhile, sql builder should work fine though
13 replies
TtRPC
Created by sumatoken on 9/14/2023 in #❓-help
tRPC Express server with Next.js
this might be inaccurate but maybe it can help I also have a few apps using an express + nextjs setup, but I am not using the Next adapter for trpc. Instead I use the base react adapter. Here's an example, although its from an expo project. But the client setup is exactly the same across all of my projects: https://github.com/Pridestalkerr/expo-chat-t3e-turbo/blob/main/apps/mobile/src/utils/trpc.tsx Now, the big issue with this is that I haven't been able to get it to work inside server components, so if you're working with the app router it might not be what you're looking for. I am currently trying to get another express/nextjs project to work. I'll make sure to get back to you in case I am successful. Best of luck!
6 replies
DTDrizzle Team
Created by Guilherme Rosado on 8/28/2023 in #help
Bug on custom type inference? Maybe I'm doing something wrong.
const schema = createSelectSchema(table);
type x = z.infer<typeof schema>;
const schema = createSelectSchema(table);
type x = z.infer<typeof schema>;
this doesnt though
14 replies
DTDrizzle Team
Created by Guilherme Rosado on 8/28/2023 in #help
Bug on custom type inference? Maybe I'm doing something wrong.
type x = table.$inferSelect like this
14 replies