TJ
TJ
Explore posts from servers
PPrisma
Created by TJ on 11/5/2024 in #help-and-questions
How to derive a type from types generated by Prisma?
Hi, The following TypeScript code snippet is working where I'm able to derive a type X from the query result from Prisma.
const rows = await prisma.role_users.findMany({
select: {
users: {
select: {
id: true,
email: true,
},
},
roles: {
select: {
members: {
select: {
groups: {
select: {
id: true,
name: true,
},
},
},
},
},
},
},
});

type X = (typeof rows)[number]["users"] & {
roles: (typeof rows)[number]["roles"]["members"][number]["groups"][];
};
const rows = await prisma.role_users.findMany({
select: {
users: {
select: {
id: true,
email: true,
},
},
roles: {
select: {
members: {
select: {
groups: {
select: {
id: true,
name: true,
},
},
},
},
},
},
},
});

type X = (typeof rows)[number]["users"] & {
roles: (typeof rows)[number]["roles"]["members"][number]["groups"][];
};
May I know how to create the type outside of the function instead of defining the type X on runtime in the function? Something like deriving the type from the database table types generated by Prisma and etc?
2 replies
PPrisma
Created by TJ on 11/1/2024 in #help-and-questions
Does Prisma support MariaDB 10.6
https://www.prisma.io/docs/orm/reference/supported-databases mentioned MariaDB 10.0+ Does the + means 10.0.x or the versions from 10.0 (including 10.6)?
7 replies