febreeze
11/23/2021, 9:07 PMn
11/23/2021, 11:26 PMwhere: {
applicationId: application.id,
status: Status.REQUIRED || Status.PENDING,
},
n
11/23/2021, 11:27 PMPhilipp Minder
11/23/2021, 11:32 PMFROM node:latest
# Create app directory
WORKDIR /usr/src/app
COPY _package.json_
./
COPY _pnpm-lock.yaml_
./
RUN _npm_
install
-g
pnpm
RUN _pnpm_
install
RUN _pnpm_
install
-g
prisma
COPY _._
.
EXPOSE 8000
RUN _pnpx_
prisma
generate
CMD _[_ "npm"_,_ "run"_,_ "start:prod" _]_
Britt Danzer
11/24/2021, 7:13 AMconst data = await prisma.customer.groupBy({
by: ['dueDate'],
where: {
status: {
in: 'PAID',
},
merchantId: 1
},
_sum: {
balancePaid: true
},
orderBy: {
dueDate: 'asc'
}
})
And this is a sample of the return:
[
{
"dueDate": "2021-11-01T06:30:26.387Z",
"_sum": {
"balancePaid": 27337.94
}
},
{
"dueDate": "2021-11-01T09:26:17.966Z",
"_sum": {
"balancePaid": 4320.82
}
},
{
"dueDate": "2021-11-01T09:43:23.207Z",
"_sum": {
"balancePaid": 50684.73
}
},
{
"dueDate": "2021-11-01T10:10:48.072Z",
"_sum": {
"balancePaid": 65238.76
}
},
Is there a way to trunc the dates prisma without having to do a raw query? Or is that not possible? I would like to be able to group by date without a specific time getting in the way.Devi Prasad
11/24/2021, 8:16 AM`SELECT COUNT(g.id) AS 'total_used', s.`product_name`, s.`current_period_start` AS 'current_period_start', s.`current_period_end` AS 'current_period_end'
FROM `subscription` s
JOIN `user` u ON s.`customer_id` = u.`customer_id`
LEFT JOIN `goat` g ON g.`user_id` = u.`id` AND
g.`date_created` BETWEEN s.`current_period_start` AND s.`current_period_end`
WHERE u.`id` = "00000-00000" AND s.`status` = 'ACTIVE'
user
11/24/2021, 9:41 AMNathaniel Babalola
11/24/2021, 1:48 PMSimoh 2k
11/24/2021, 3:10 PMmodel User {
id String @id @default(uuid())
username String
roleId String?
role Role? @relation(fields: [roleId], references: [id])
contact Contact?
acceptCGU Boolean @default(false)
opinons Opinion[]
}
model Role {
id String @id @default(uuid())
name String
description String
rolePermissions RolePermission[]
users User[]
}
model Opinion {
id String @id @default(uuid())
opinionCount Int?
descriptionOpinion String?
user User @relation(fields: [authorId], references: [id])
authorId String
createdAt DateTime @default(now())
}
Irakli Safareli
11/24/2021, 4:17 PMRequest#1 prisma query ...
Request#2 prisma query ...
Request#1 prisma query ...
Request#2 prisma query ...
...
Is there something that one can do to active this?
of course naive approach would be to create multiple prisma clients per request. but if you have 100 requsts and each client creates multiple db connection it’s not good.
basically some “soft clone” like function is needed on prisma client
const softClone = (c: PrismaClient, context: unknown): PrismaClient
and then in when listening to events on prisma:
prisma.$on("query", (e) => {
console.log(e.context, "query", e.query);
});
and this softClone should not result in new connections (should use previous prisma client.
Any suggestions? is there issue for it?
(I’ve created an issue here: https://github.com/prisma/prisma/issues/10425)Dennis Yurkevich
11/24/2021, 4:38 PMprisma.schema
- how would one pull those in as deps to other modules, so as not to keep defining the same types on a bunch of interfaces.Taras Protchenko
11/24/2021, 8:10 PMRykuno
11/24/2021, 8:42 PMRykuno
11/24/2021, 8:43 PMTomer Aberbach
11/25/2021, 2:12 AMexport async function getUser(
request: Request,
{ include }: { include?: Prisma.UserInclude } = {},
) {
const session = await getUserSession(request)
const userId = session.get(`userId`)
if (!userId || typeof userId !== `string`) {
return null
}
return db.user.findUnique({ where: { id: userId }, include })
}
Now, no matter what I do, calling getUser(request, { include: { classes: true } })
does not get typed as Promise<(User & { classes: Class[] }) | null>
. It gets typed as Promise<(User & {}) | null>
. I can't figure out how to make it infer the return type properly based on the given include
. Any help would be greatly appreciated!Akshay Kadam (A2K)
11/25/2021, 9:58 AMProperty 'settings' is missing in type '{ id: string; name: string; username: string; }' but required in type 'UserCreateInput'.ts(2322)
but I have set the default values in settings
but it is not optional.
How do I fix it?
My schema:
model User {
id String @id @default(cuid())
username String @unique
name String?
email String? @unique
image String?
// relations
settings Settings @relation(fields: [settingsId], references: [id], onDelete: Cascade)
teams Team[]
settingsId String
}
model Settings {
id String @id @default(cuid())
timezone String @default("UTC")
// relations
user User[]
}
Akshay Kadam (A2K)
11/25/2021, 10:01 AMSettings
?Akshay Kadam (A2K)
11/25/2021, 10:31 AMprisma
or is there a way to call mutation directly? I am doing Oauth so I get the data on the backend only.
If I do send it back to client using res.send
& then do mutation createUser
, then its 2 steps.
If I don't send it to client but do it on the backend, then I don't use the mutation createUser
but directly do it so its 1 step.
What is your recommended approach?user
11/25/2021, 11:12 AMMuhammed Kaplan
11/25/2021, 12:51 PMAkshay Kadam (A2K)
11/25/2021, 1:07 PMError:
Invalid `prisma.user.create()` invocation:
The table `public.Settings` does not exist in the current database.
My code is simply:
await prisma.user.create({
data: {
id,
username,
name,
settings: {
connect: {
id,
},
},
},
})
I don't think I need to manually create any tables but it does throw an error when the table does not exist. I'm using docker with postgres so not sure if i can create a table in there. how do i solve this?user
11/25/2021, 1:17 PMBamada
11/25/2021, 2:08 PMSELECT * FROM employees WHERE timesheeting=1 AND year(termination_date)=2021 AND MONTH(termination_date)=10;
ThksNathaniel Babalola
11/25/2021, 2:37 PMDateTime
?
If it can't , can I use String
instead and will ordering (asc or desc) work for year stored as String
. ?henry
11/26/2021, 9:01 AMhenry
11/26/2021, 10:11 AMuser
11/26/2021, 10:19 AMJorge Whitte
11/26/2021, 1:36 PMmodel User{
name String
settings: UserSettings
}
submodel UserSettings {
smsNotifications Status
emailNotifications Status
... etc
}
enum Status{
ON
OFF
}
maybe not the best example, but I think it show the idea, something like this would be like nested type enforcement in models, that doesn't translate into a DB entityOctavio Augusto Barbosa
11/26/2021, 3:26 PMasync listAccounts(user: Clients): Promise<AccountResponse[]> {
const accounts = await this.prismaService.accounts.findMany({
where: {
company: {
id: user.company.id,
deletedAt: null
}
}
})
return plainToClass(AccountResponse, accounts)
}
if i try a console.log( user ) i receive all data of clients and company