Mads
Mads
TTCTheo's Typesafe Cult
Created by Mads on 3/29/2024 in #questions
Prisma w/pgvector
For anyone who is (probably) going to have the same problem as me, this is how I handle it:
getEmbeddings: protectedProcedure.query(async ({ ctx }) => {
const embeddings = await ctx.prisma.$queryRawUnsafe(
`SELECT embedding::text FROM "User" where id = ${ctx.session.user.id}`
);
return embeddings;
}),
getEmbeddings: protectedProcedure.query(async ({ ctx }) => {
const embeddings = await ctx.prisma.$queryRawUnsafe(
`SELECT embedding::text FROM "User" where id = ${ctx.session.user.id}`
);
return embeddings;
}),
6 replies
TTCTheo's Typesafe Cult
Created by Mads on 3/29/2024 in #questions
Prisma w/pgvector
I ended up using queryRaw and casting the response as text, so sort of a hack so I really hope Prisma starts to support a better way to handle unsupported types.
6 replies
TTCTheo's Typesafe Cult
Created by Mads on 3/29/2024 in #questions
Prisma w/pgvector
user router:
...other routers
deleteUser: protectedProcedure.mutation(async ({ ctx }) => {
await ctx.prisma.image.deleteMany({
where: { userId: ctx.session.user.id },
});
const deletedUser = await ctx.prisma.user.delete({
where: { id: ctx.session.user.id },
});
return deletedUser;
}),

getEmbeddings: protectedProcedure.query(async ({ ctx }) => {
await ctx.prisma.user <-- No getUserEmbedding?
}),
...other routers
deleteUser: protectedProcedure.mutation(async ({ ctx }) => {
await ctx.prisma.image.deleteMany({
where: { userId: ctx.session.user.id },
});
const deletedUser = await ctx.prisma.user.delete({
where: { id: ctx.session.user.id },
});
return deletedUser;
}),

getEmbeddings: protectedProcedure.query(async ({ ctx }) => {
await ctx.prisma.user <-- No getUserEmbedding?
}),
6 replies
TTCTheo's Typesafe Cult
Created by Mads on 3/29/2024 in #questions
Prisma w/pgvector
import { PrismaClient, Prisma } from "@prisma/client";
import { env } from "~/env.mjs";

const prismaClientSingleton = () => {
return new PrismaClient();
};

type Embedding = number[];

declare global {
var prisma: undefined | ReturnType<typeof prismaClientSingleton>;
}

export const prisma = globalThis.prisma ?? prismaClientSingleton();

const getUserEmbedding = async (userId: number): Promise<Embedding> => {
const embedding: Embedding = await prisma.$queryRaw`
SELECT embedding
FROM "User"
WHERE id = ${userId}
`;
return embedding;
};

prisma.$extends({
model: {
user: {
async getEmbedding(userId: number) {
return getUserEmbedding(userId);
},
},
},
});
if (process.env.NODE_ENV !== "production") globalThis.prisma = prisma;

export default prisma;
import { PrismaClient, Prisma } from "@prisma/client";
import { env } from "~/env.mjs";

const prismaClientSingleton = () => {
return new PrismaClient();
};

type Embedding = number[];

declare global {
var prisma: undefined | ReturnType<typeof prismaClientSingleton>;
}

export const prisma = globalThis.prisma ?? prismaClientSingleton();

const getUserEmbedding = async (userId: number): Promise<Embedding> => {
const embedding: Embedding = await prisma.$queryRaw`
SELECT embedding
FROM "User"
WHERE id = ${userId}
`;
return embedding;
};

prisma.$extends({
model: {
user: {
async getEmbedding(userId: number) {
return getUserEmbedding(userId);
},
},
},
});
if (process.env.NODE_ENV !== "production") globalThis.prisma = prisma;

export default prisma;
6 replies
TTCTheo's Typesafe Cult
Created by Mads on 3/29/2024 in #questions
Prisma w/pgvector
prisma.schema
6 replies
TTCTheo's Typesafe Cult
Created by Mads on 7/15/2023 in #questions
Add rest of User prisma table types and data to nextauth session in auth.ts
Thank you very much @nexxel I actually found out I did it correctly, or everything works at least, so I will just go ahead and mark my own code as the solution.
7 replies
TTCTheo's Typesafe Cult
Created by Mads on 4/7/2023 in #questions
Modify user model in Prisma on signup
Thanks for input man🙌🏻
3 replies
TTCTheo's Typesafe Cult
Created by Mads on 4/5/2023 in #questions
What is the convention for customizing sign-in pages in NextAuth
Thanks mate:)
12 replies
TTCTheo's Typesafe Cult
Created by Mads on 4/5/2023 in #questions
What is the convention for customizing sign-in pages in NextAuth
As I can see you didn't do that:)
12 replies
TTCTheo's Typesafe Cult
Created by Mads on 4/5/2023 in #questions
What is the convention for customizing sign-in pages in NextAuth
But I think the problem was in me defining it in the api folder instead of in the pages folder
12 replies
TTCTheo's Typesafe Cult
Created by Mads on 4/5/2023 in #questions
What is the convention for customizing sign-in pages in NextAuth
I had originally followed the documentation - but has some problems with the rendering of the signin page even though it is defined in pages
12 replies
TTCTheo's Typesafe Cult
Created by Mads on 4/5/2023 in #questions
What is the convention for customizing sign-in pages in NextAuth
Ahh thank you so much for your answer Ygor, I will try it out again 😄
12 replies
TTCTheo's Typesafe Cult
Created by Mads on 4/6/2023 in #questions
tRPC router refreshes and gives 429 HTTP error
Actually It might have something to do with the OpenAI api endpoint
5 replies
TTCTheo's Typesafe Cult
Created by Mads on 4/5/2023 in #questions
How to create new tRPC api route calling external api
Thanks for the input, unfortunately this did not work as much as I'd like it to 😦 Seems like the request get's called a multitude of times after calling the api
6 replies
TTCTheo's Typesafe Cult
Created by Mads on 4/5/2023 in #questions
How to create new tRPC api route calling external api
Was my question okay formulated? Or should I try again:)?
6 replies