Copium Dealer
07/06/2021, 2:55 PMconst results = await prisma.token.findMany({
select: {
id: true,
name: true,
symbol: true,
telegram: true,
_count: { select: { votes: true } },
},
orderBy: { votes: { count: "desc" } },
});
However I would like this to be a range query, so I can select tokens in descending order where the date on votes are less than 24 hours ago
If possible, I would also like to select the count of these votes too (but total count is fine if that's not possible).Dominic Hadfield
07/06/2021, 3:11 PMconst results = await prisma.token.findMany({
select: {
id: true,
name: true,
symbol: true,
telegram: true,
_count: { select: { votes: true } },
},
orderBy: { votes: { count: 'desc' } },
where: {
votes: {
some: {
createdAt: {
gt: '24 hours ago' // send actual date object,
},
},
},
},
})Dominic Hadfield
07/06/2021, 3:11 PMCopium Dealer
07/06/2021, 3:40 PMDominic Hadfield
07/06/2021, 3:46 PMDominic Hadfield
07/06/2021, 3:47 PMCopium Dealer
07/06/2021, 3:50 PMDominic Hadfield
07/06/2021, 3:50 PMDominic Hadfield
07/06/2021, 3:52 PMCopium Dealer
07/06/2021, 3:53 PM// This is your Prisma schema file,
// learn more about it in the docs: <https://pris.ly/d/prisma-schema>
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["selectRelationCount", "orderByRelation"]
}
model Token {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
launchDate DateTime
name String
symbol String
address String
chain String
description String
website String
telegram String
twitter String?
discord String?
approved Boolean @default(false)
listed Boolean @default(false)
voteCount Int @default(0)
votesToday Int @default(0)
votes Vote[]
sponsoredListings SponsoredListing[]
}
model SponsoredListing {
id Int @id @default(autoincrement())
token Token @relation(fields: [tokenId], references: [id])
tokenId Int
campaignStart DateTime
campaignEnd DateTime
}
model Vote {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id])
userId Int
token Token @relation(fields: [tokenId], references: [id])
tokenId Int
}
model Account {
id Int @default(autoincrement()) @id
compoundId String @unique @map(name: "compound_id")
userId Int @map(name: "user_id")
providerType String @map(name: "provider_type")
providerId String @map(name: "provider_id")
providerAccountId String @map(name: "provider_account_id")
refreshToken String? @map(name: "refresh_token")
accessToken String? @map(name: "access_token")
accessTokenExpires DateTime? @map(name: "access_token_expires")
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @map(name: "updated_at")
@@index([providerAccountId], name: "providerAccountId")
@@index([providerId], name: "providerId")
@@index([userId], name: "userId")
@@map(name: "accounts")
}
model Session {
id Int @default(autoincrement()) @id
userId Int @map(name: "user_id")
expires DateTime
sessionToken String @unique @map(name: "session_token")
accessToken String @unique @map(name: "access_token")
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @map(name: "updated_at")
@@map(name: "sessions")
}
model User {
id Int @default(autoincrement()) @id
name String?
email String? @unique
emailVerified DateTime? @map(name: "email_verified")
image String?
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @map(name: "updated_at")
votes Vote[]
@@map(name: "users")
}
model VerificationRequest {
id Int @default(autoincrement()) @id
identifier String
token String @unique
expires DateTime
createdAt DateTime @default(now()) @map(name: "created_at")
updatedAt DateTime @default(now()) @map(name: "updated_at")
@@map(name: "verification_requests")
}Copium Dealer
07/06/2021, 3:54 PMCopium Dealer
07/06/2021, 4:27 PMDominic Hadfield
07/06/2021, 4:49 PMDominic Hadfield
07/06/2021, 4:49 PMDominic Hadfield
07/06/2021, 4:49 PMDominic Hadfield
07/06/2021, 4:50 PMCopium Dealer
07/06/2021, 8:59 PMCopium Dealer
07/07/2021, 2:05 PM