Orcioly Andrade Alves
03/10/2022, 12:39 PMJulien Demarque
03/10/2022, 3:12 PMprisma.authors.findMany({
where: {
books: {
id: {
IN: [1,2,3]
}
}
}
})
This would filter the authors, but what i want is to get all the authors, but filter their book selection. How would I do that?Anthony Roux
03/10/2022, 4:35 PMShiva Kar
03/10/2022, 5:35 PMShiva Kar
03/10/2022, 5:43 PMShiva Kar
03/10/2022, 5:44 PMNathaniel Babalola
03/10/2022, 7:53 PMMacRae Linton
03/10/2022, 10:27 PMJuan Carlos Blanco Delgado
03/10/2022, 11:43 PMWilliam GM
03/11/2022, 2:06 AMtstzrange
type?SKhan
03/11/2022, 6:44 AMmodel User {
id String @id @default(cuid())
team Team[]
...
}
model Team {
id String @id @default(cuid())
member User[]
...
}
QUESTION: Is this logic good or would it better to have two fields (member1 & member2) within the Team
table, which would reference User
?
2 -
The above logic is incorporated within Prisma. How do I query Team
to get User
. I get stuck because there are no foreign keys within Team referencing User.id, nor is there another table connecting Team -> User.
(correction:) - There is a table _TeamToUser
which only has 2 fields (A, B).
(correction:) - Got this working with the following query.
select * from "Team" inner join "_TeamToUser" on "Team".id = "_TeamToUser"."A" inner join "User" on "_TeamToUser"."B" = "User".id;
Would love feedback to 1st question.Elliot Pitts
03/11/2022, 8:45 AMMichael Roberts
03/11/2022, 12:12 PMMichael Roberts
03/11/2022, 12:13 PMMichael Azogu
03/11/2022, 12:52 PMDamien Duhamel
03/11/2022, 3:43 PMP1001 Can't reach database server at xxxx:xxx
So the Prisma client seems to lose the connection with the Postgresql DB obviously ...
It’s not linked to the server load or too many connections because I have the same issue in staging environment (low trafic)
It’s happening on two different services: a NodeJS API and a web worker
Everything looks fine on Postgresql DB side and I have another very similar service connected to the same Postgresql DB but with Sequelize as ORM and no issue in this service
Do you have any idea, what should I look for in order to fix it ?Mischa
03/11/2022, 4:08 PMreaddirSync
?Paulo Menezes
03/11/2022, 8:41 PMconst customers = await prisma.customer.findMany({
where: {
birthday: {
equals: 'YYYY-03-11',
},
},
});
Demian N
03/11/2022, 9:45 PMWilliam GM
03/12/2022, 6:05 AMexecuteRaw
, whenever I try to execute this code snippet I get the following error db error: ERROR: invalid input syntax for type timestamp with time zone: "$1"
const { from, to } = createAppointmentDto;
await prisma.$executeRaw`insert into public."Appointment" ("date", "patientId", "itemId") values ('[${from}, ${to})', ${id}, ${itemId});`;
The weird part is that if I hardcode the dates directly as strings, IT WORKS!
await prisma.$executeRaw`insert into public."Appointment" ("date", "patientId", "itemId") values ('[2010-01-01 14:45, 2010-01-01 15:45)', ${id}, ${itemId});`;
Surely I'm missing something but don't know what it is.
Thoughts?user
03/12/2022, 9:00 AMOctal pixel
03/12/2022, 8:26 PMJakub Figlak
03/13/2022, 12:26 PMmodel TeamAffiliation {
id String @id @default(cuid())
startDate DateTime
endDate DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relation fields
player Player @relation(fields: [playerId], references: [id])
playerId String
team Team @relation(fields: [teamId], references: [id])
teamId String
}
This table's responsibility is to keep the information to which team has the player been assigned within a certain time period (between startDate
and endDate
). I also have a NOTES table, its simplified model looks like this:
model Note {
id String @id @default(cuid())
docNumber Int @default(autoincrement())
description String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relation fields
player Player? @relation(fields: [playerId], references: [id])
playerId String?
}
And here comes my question. On a note itself (when I'm for example fetching a list of notes) I need information to which team has the player been assigned when the note was created (it'd be perfect if I could filter notes by this piece of data). How would you approach this kind of problem? The simplest way would be just to create a field like playerCurrentTeam
on a note and save it when a note is created. But it seems like a workaround, is there a better solution?aj
03/13/2022, 3:00 PMwork
record which has link to order
, user
and location
. Schema is as follows:
model User {
id String @id @default(cuid())
email String? @unique
orders Order[]
}
model Order {
id String @id @default(cuid())
orderNumber Int
user User @relation(fields: [userId], references: [id])
userId String
origin Location @relation("OrderOrigin", fields: [orderOriginId], references: [id])
orderOriginId String
destination Location? @relation("OrderDestination", fields: [orderDestinationId], references: [id])
orderDestinationId String?
work Work? @relation("OrderWork")
includeLocations Location[] @relation("OrderIncludeLocations")
excludeLocations Location[] @relation("OrderExcludeLocations")
}
model Work {
id String @id @default(cuid())
origin Location @relation("WorkOrigin", fields: [workOriginId], references: [id])
destination Location @relation("WorkDestination", fields: [workDestinationId], references: [id])
stops Location[] @relation("WorkStops")
originLocationId String
destinationLocationId String
workOriginId String
workDestinationId String
workStopsId String?
order Order @relation("OrderWork", fields: [orderId], references: [id])
orderId String @unique
status WorkStatus @default(value: BOOKED)
}
model Location {
id String @id @default(cuid())
address String
city String
state String
locationCode String?
workStops Work[] @relation("WorkStops")
workOrigin Work[] @relation("WorkOrigin")
workDestination Work[] @relation("WorkDestination")
orderOrigin Order[] @relation("OrderOrigin")
orderDestination Order[] @relation("OrderDestination")
orderIncludeLocations Order[] @relation("OrderIncludeLocations")
orderExcludeLocations Order[] @relation("OrderExcludeLocations")
}
Now when work
is created order
status becomes BOOKED
. I can’t figure out how to upsert locations.
let work = await prisma.work.create({
data: {
destination: {
connectOrCreate: {
where: {
// address: data.work.destination.Address,
// city: data.work.destination.City,
state: data.work.destination.State,
},
create: {
address: data.work.destination.Address,
city: data.work.destination.City,
state: data.work.destination.State,
},
},
},
origin: {
connectOrCreate: {
where: {
// address: data.work.origin.Address,
// city: data.work.origin.City,
state: data.work.origin.State
},
create: {
address: data.work.origin.Address,
city: data.work.origin.City,
state: data.work.origin.State
},
},
},
// stops: data.work.stops.map(stop => {
// return {
// connectOrCreate: {
// address: stop.Address,
// city: stop.City,
// state: stop.State,
// },
stopsCount: 0,
workOriginId: data.work.workOriginId,
originLocationId: data.work.originLocationId,
workDestinationId: data.work.workDestinationId,
destinationLocationId: data.work.destinationLocationId,
workStopsId:"1234",
status: data.work.status,
orderId: orderId,
}
Isaac McFadyen
03/13/2022, 8:24 PMesbuild
or similar when used with Cloudflare Workers (otherwise it gives a "not allowed in browser" error). What's the blocker on removing this bundle requirement?Matias Filliez
03/14/2022, 4:13 AMDev__
03/14/2022, 10:20 AMSimon
03/14/2022, 4:51 PMNicholas Chiang
03/14/2022, 5:55 PMselect
links.*,
clusters.id as cluster_id,
clusters.name as cluster_name,
clusters.slug as cluster_slug,
sum(tweets.insider_score) as insider_score,
sum(tweets.attention_score) as attention_score,
json_agg(tweets.*) as tweets
from links
inner join (
select distinct on (urls.link_id, tweets.author_id, tweets.cluster_id)
urls.link_id as link_id,
tweets.*
from urls
inner join (
select
tweets.*,
scores.cluster_id as cluster_id,
scores.insider_score as insider_score,
scores.attention_score as attention_score,
to_json(influencers.*) as author,
to_json(scores.*) as score
from tweets
inner join influencers on influencers.id = tweets.author_id
inner join scores on scores.influencer_id = influencers.id
${filter === 'hide_retweets' ? `where not exists (select 1 from refs where refs.referencer_tweet_id = tweets.id and refs.type = 'retweeted')` : ''}
) as tweets on tweets.id = urls.tweet_id
) as tweets on tweets.link_id = links.id
inner join clusters on clusters.id = tweets.cluster_id
where clusters.slug = '${params.cluster}' and expanded_url !~ '^https?:\\/\\/twitter\\.com'
group by links.id, clusters.id
order by ${sort === 'tweets_count' ? 'count(tweets)' : sort} desc
limit 20;
Nicholas Chiang
03/14/2022, 5:57 PMconst links = await db.links.findMany({
select: { // There's no way to `_sum` the nested fields from `scores`.
urls: {
select: {
tweets: { // There's no way to have a nested `groupBy` here.
select: {
influencers: {
select: {
scores: {
where: {
cluster_id: params.cluster,
},
},
},
},
},
},
},
},
},
});