Raphael Etim
09/30/2022, 7:42 AMgt/gte
and lt/lte
. For example.
let result = await prisma.post.findMany({
where: {
updatedAt: {
gte: '2020-03-19T00:00:00+00:00',
lte: '2020-03-19T23:59:59+00:00'
}
}
})
darksider
09/30/2022, 8:22 AMJoey
09/30/2022, 2:19 PMorganizationId String?
field and a required name String
field.
Is there any way to enforce that two teams in the same organization don’t have the same name, BUT also allow many Teams with the same name if they’re not affiliated with an organization (organizationId = null)?
So my goal would be :
name: “joe”, orgId: null + name:“joe”, orgId:null === OK
name: ’joe”, orgId: 1 + name:“joe”, orgId:2 === OK
name: ’joe”, orgId: 1 + name:“joe”, orgId:1 === err: DUPLICATE
I usually do @@unique([name, organizationId])
, but i think this would cause the first example to fail when it shouldnt, bc both are null, but i want to allow that.Jose Donato
09/30/2022, 3:24 PMdoddy nicolas
09/30/2022, 3:45 PMAnthony
09/30/2022, 6:07 PMpg
(postgres) library to query with SQLs. We still want to reuse the connections created by pg
, without setting up new connections by Primsa client. I’m wondering if this is possible and if it’s so, how can we do that?Boo
09/30/2022, 11:18 PMNOT/not/notIn
filter queries does not work on optional fields?ven v
10/01/2022, 12:47 AMexport const getUser = (id) => {
return prisma.User.findUnique({
where: { authId: id },
});
};
Ridhwaan Shakeel
10/01/2022, 4:08 AMGrégory D'Angelo
10/01/2022, 8:14 AMinclude
or select
?
I'm asking that because I'm wrapping my Prisma functions inside service functions for a Node.js project. Those functions accept include
or select
as arguments and I'd like to keep type-safety, but I'm not sure if it is actually possible or the best way to do it.
Any advice or suggestions from what you've seen?
Here's an example:
export interface FindQuizzesByStatusInput {
status: Status;
take: number;
after?: string | null;
include?: { [key: string]: any }; // not great for type-safety!!!
}
export const findQuizzesByStatus = async (
input: FindQuizzesByStatusInput
): Promise<Quiz[]> => {
// ...
}
Thanks!Slackbot
10/01/2022, 10:52 AMdoddy nicolas
10/01/2022, 10:54 AMdoddy nicolas
10/01/2022, 10:56 AMdoddy nicolas
10/01/2022, 11:52 AMprisma.ts
declare global {
var prisma: PrismaClient; // This must be a `var` and not a `let / const`
}
import { PrismaClient } from '@prisma/client'
let prisma: PrismaClient;
if(process.env.NODE_ENV === 'production'){
prisma = new PrismaClient();
}
else{
if(!global.prisma){
global.prisma = new PrismaClient();
}
prisma = global.prisma
}
export default prisma;
graphl.ts
import { createServer , createPubSub } from '@graphql-yoga/node'
import { User } from '@prisma/client'
import type { NextApiRequest, NextApiResponse } from 'next'
import prisma from '../../lib/prisma'
const schema = {schema: {
typeDefs: /* GraphQL */ `
type User {
lname: String
fname: String
}
type Mutation{
addUser(lname: String, fname: String): User!
}
`,
resolvers: {
Mutation: {
addUser: async(parent: any,_: any) => {
return await prisma.user.create(
data:{
lname:"coucou",
fname:"salut"
}
)}
},
}
}
i just want to add a new user in graphql with prisma but the resolver don't work <https://github.com/doddynicolas/try-prisma.git>
doddy nicolas
10/01/2022, 11:56 AMKenny Tran
10/01/2022, 1:24 PMmodel Sale {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
date String
time String
revenue Int
amount Int
invoice String
}
After I fetch using prisma.sale.findMany({})
I want to calculate the commission against some percentage and add an addition commission field. How would I add the type of the additional field to the client so that I can consume it there?
Would it be possible to do something like -
type Sale = Prisma.SaleGetPayload<{
include: {
commission: float
}
}>
The reason why the commission field isn't in the sales model in the first place is because the commission percentage is not persistant and might change depending on other factors. So it needs to be calculated before it gets passed further. I hope that makes sense.
Any help is appreciatedN
10/01/2022, 2:13 PMmodel User {
id Int @id @default(autoincrement())
profile Profile?
}
model Profile {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int @unique // relation scalar field (used in the `@relation` attribute above)
}
N
10/01/2022, 2:41 PMSJ
10/02/2022, 12:45 AMPrismaClient
support programmatically accessing its generated SQL query e.g. as a string
, without executing it?
a sort of dry run, for debugging, strong emphasis on not actually executing the query and on 'piping' the query into a standard javascript variable
example pseudocode:
const sqlThatWouldHaveBeenExecuted: string = stringifyQueryAndDontExecute(await prisma.user.create({
data: {
name: 'Alice',
email: '<mailto:alice@prisma.io|alice@prisma.io>',
},
}))
I doubt this is possible atm with Prisma judging from a cursory glance, but if so, it would be quite a pleasant surprise for a database playgroundJyn
10/02/2022, 5:03 AMmodel Stage {
id String @id @default(cuid())
code String @unique
createdAt DateTime? @default(now())
rewards Reward[]
}
type Reward {
item_code String
count Int
}
I want to make my schema like this, but an error appears:
Error validating: Composite types are not supported on Postgres.
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
I don’t wanna make Reward
as a table(model in schema), since it is very small pieces. What i tried instead is
1. Make It Together
model Stage {
id String @id @default(cuid())
code String @unique
createdAt DateTime? @default(now())
reward_item_codes String[]
reward_item_counts Int[]
}
Probleme: i need to always check the lengths of those are equal.
2. Use Json
model Stage {
id String @id @default(cuid())
code String @unique
createdAt DateTime? @default(now())
rewards Json
}
probleme: Unhappy that i need to make json converter at each server&front.
What do you bros usually solve these kinda mundane problem in Prisma?
Appreciate your ideas,David Hancu
10/02/2022, 8:08 AMpg_trgm
) ready for the next release of Prisma Util and I was wondering what you think about this configuration example. Should I change anything or keep it like this?
ftsIndexes: {
"base.prisma:Post": {
type: "GIN",
indexes: [{ language: "english", field: "title", weight: "A"}]
}
}
Kenny Tran
10/02/2022, 10:12 AMonDelete: Cascade
however when I perform a delete operation it only deletes the relation. Here's my models -
model Sale {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
index Int @unique @default(autoincrement())
rank Rank @default(ROOKIE)
services ServicesOnSales[]
}
model Service {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
provision String
sales ServicesOnSales[]
}
model ServicesOnSales {
saleId Int
serviceId Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
subscription String
sale Sale @relation(fields: [saleId], references: [index], onDelete: Cascade)
service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
@@id([saleId, serviceId])
}
enum Rank {
ROOKIE
MASTER
VETERAN
}
The query below only deletes the sale and the relation but the service is not getting removed
await prisma.sale.delete({
where: {
id
}
})
David Hancu
10/02/2022, 12:16 PMDavid Hancu
10/02/2022, 12:16 PMМовсар Халахоев
10/02/2022, 2:36 PMSahas Saurav
10/02/2022, 3:27 PMSahas Saurav
10/02/2022, 3:30 PMGeneric type 'UserDelegate<GlobalRejectSettings>' requires 1 type argument(s).
David Hancu
10/02/2022, 8:34 PMRidhwaan Shakeel
10/02/2022, 9:38 PMBigInt.prototype.toJSON = () => {
return this.toString();
};
I used the above function to fix the prisma error:
message: "const result = await prisma.product.findMany(Inconsistent column data. Conversion failed: Value does not fit in an INT column, try migrating the 'revenue' column type to BIGINT"
However, now when I query prisma and display the response it doesnt show the numerical value
[
{
"id": 1,
"revenue": "[object Object]",
...
}
...
]
How do you further resolve it?
thanksMarrtin Rylander
10/03/2022, 8:18 AM