Chris D.
09/24/2021, 7:43 AMJosef Henryson
09/24/2021, 7:46 AMVladi Stevanovic
NikolaBjelo
09/24/2021, 1:28 PMnode_modules/.prisma/client
and node_modules/@prisma/client
? (didn't know about node_modules/.prisma until vscode autoimported from there today for the first time)Chip Clark
09/24/2021, 2:59 PM$queryRaw
is a tag function, please use it like the following:
breaking with Prisma 3.1.1 - was working with prisma 2.x
public RelatedClient = 'SELECT client.RelatedClientNumber [RelatedClientNumber], client.RelatedClientName [RelatedClientName], ' +
'splitbill.TimekeeperNumber [TimekeeperNumber], person.LastName [SplitBill_LastName], ' +
'person.FirstName [SplitBill_FirstName] ';
public RelatedClientJoin = 'FROM ERP_ODS_Test.dbo.Client AS client ' +
'INNER JOIN ERP_ODS_Test.dbo.SplitBillingAttorney AS splitbill ' +
'ON client.ClientNumber = splitbill.ClientNumber ' +
'INNER JOIN dbo.Person AS person ' +
'ON splitbill.TimekeeperNumber = person.TimekeeperNumber ';
public activeClient = "WHERE client.ClientActive = 1 AND splitbill.EmployeeActive = 1 ";
public Count = 'SELECT COUNT(*) ';
accessPrismaRaw(raw1: TemplateStringsArray, rawCount: TemplateStringsArray) {
let Memory = [];
const data = Promise.all([
this.prisma.$queryRaw(raw1),
this.prisma.$queryRaw(rawCount),
Memory = this.appService.getMemory()
]).then(([records, total]) => {
return {
records,
metadata: {
count: total,
memory: Memory
},
};
});
return data;
}
async relatedclients(params: { searchString?: string; } = {}) {
const { searchString } = params;
let viewString = this.RelatedClient + this.RelatedClientJoin;
let rawView;
let rawCount;
let searchFilter = this.activeClient + " AND client.RelatedClientName LIKE '%" + searchString + "%'";
if (searchString) {
rawView = this.RelatedClient + this.RelatedClientJoin + searchFilter;
rawCount = this.Count + this.RelatedClientJoin + searchFilter;
} else {
rawView = this.RelatedClient + this.RelatedClientJoin + this.activeClient;
rawCount = this.Count + this.RelatedClientJoin + this.activeClient;
}
return this.accessPrismaRaw(rawView, rawCount);
}
The final script (rawView) =
SELECT client.RelatedClientNumber [RelatedClientNumber], client.RelatedClientName [RelatedClientName], splitbill.TimekeeperNumber [TimekeeperNumber], person.LastName [SplitBill_LastName], person.FirstName [SplitBill_FirstName] FROM ERP_ODS_Test.dbo.Client AS client INNER JOIN ERP_ODS_Test.dbo.SplitBillingAttorney AS splitbill ON client.ClientNumber = splitbill.ClientNumber INNER JOIN dbo.Person AS person ON splitbill.TimekeeperNumber = person.TimekeeperNumber WHERE client.ClientActive = 1 AND splitbill.EmployeeActive = 1 AND client.RelatedClientName LIKE '%google%'
Works when run on the sql server.
Change $queryRaw to $executeRawUnsafe - and the sql script executes.
accessPrismaRaw(raw1: string, rawCount: string) {
let Memory = [];
const data = Promise.all([
this.prisma.$executeRawUnsafe(raw1),
this.prisma.$executeRawUnsafe(rawCount),
Memory = this.appService.getMemory()
]).then(([records, total]) => {
return {
records,
metadata: {
count: total,
memory: Memory
},
};
});
return data;
}
Again, $queryRaw used to work in 2.x, but no longer in 3.1.1Kent C. Dodds
09/24/2021, 3:13 PMconst users = await prismaRead.user.findMany({
select: {
firstName: true,
email: true,
id: true,
team: true,
},
orderBy: {
createdAt: 'asc',
},
})
const data: LoaderData = {users}
return data // this gets sent over the network as json
// then later, on the other side of a network request, in a React component for example:
const data = useLoaderData()
assert(data, LoaderData)
data.users[0].firstName // <-- autocompletes
Brian de la Motte
09/24/2021, 3:44 PM"message": "ReferenceError: prisma is not defined\n at Object.2132 (/var/task/.next/server/chunks/7133.js:15:10)\n at __webpack_require__ (/var/task/.next/server/webpack-runtime.js:25:42)\n at Object.7133 (/var/task/.next/server/chunks/7133.js:30:69)\n at __webpack_require__ (/var/task/.next/server/webpack-runtime.js:25:42)\n at Object.8316 (/var/task/.next/server/pages/api/auth/[...nextauth].js:28:13)\n at __webpack_require__ (/var/task/.next/server/webpack-runtime.js:25:42)\n at __webpack_exec__ (/var/task/.next/server/pages/api/auth/[...nextauth].js:137:52)\n at /var/task/.next/server/pages/api/auth/[...nextauth].js:138:80\n at Function.__webpack_require__.X (/var/task/.next/server/webpack-runtime.js:108:21)\n at /var/task/.next/server/pages/api/auth/[...nextauth].js:138:47",
Chip Clark
09/24/2021, 3:49 PM102
. Message: Incorrect syntax near '='.
If I change last line to WHERE contcomp.ContactCompanyID = 7247
error: Raw query failed. Code: 102
. Message: Incorrect syntax near '.'.
This suggests the query is not able to process the field name ContactCompanyID for WHERE.Chris V
09/24/2021, 4:39 PMCarlos Gomez
09/24/2021, 8:58 PM{
"id": "uuid",
"members": [ { "id": 1 } ],
}
If I have a specific member
ID, how would I find rows that have a members
array containing a member
object with that ID? I'm using the new JSON filtering API.Sai Krishna
09/25/2021, 7:31 AMJon Insley
09/25/2021, 8:55 AMNditah Samweld
09/25/2021, 9:48 AMIvan
09/25/2021, 10:04 AMTemm
09/25/2021, 10:43 AMNditah Samweld
09/25/2021, 1:40 PMexport enum MediaType {
IMAGE = 'IMAGE',
VIDEO = 'VIDEO',
}
registerEnumType(MediaType, {
name: 'MediaType',
description: 'Media type',
});
======
return this.prisma.media.create({
data: {
type: data.type,
fileItem: data.fileItem && { connect: { id: data.fileItem } },
},
});
Phil Bookst
09/25/2021, 8:01 PMHristijan
09/25/2021, 10:37 PMAndrew Ross
09/26/2021, 3:07 AM[next-auth][error][OAUTH_CALLBACK_HANDLER_ERROR]
<https://next-auth.js.org/errors#oauth_callback_handler_error> getUserByAccount is not a function {
message: 'getUserByAccount is not a function',
stack: 'TypeError: getUserByAccount is not a function\n' +
' at Object.callback (/home/dopaminedriven/prisma-nexus-next-ts/cortina-crm/cortina-tracking/.next/server/pages/api/auth/[...nextauth].js:2583:39)\n' +
' at runMicrotasks (<anonymous>)\n' +
' at processTicksAndRejections (node:internal/process/task_queues:96:5)\n' +
' at async NextAuthHandler (/home/dopaminedriven/prisma-nexus-next-ts/cortina-crm/cortina-tracking/.next/server/pages/api/auth/[...nextauth].js:832:18)\n' +
' at async Object.apiResolver (/home/dopaminedriven/prisma-nexus-next-ts/cortina-crm/cortina-tracking/node_modules/next/dist/server/api-utils.js:101:9)\n' +
' at async DevServer.handleApiRequest (/home/dopaminedriven/prisma-nexus-next-ts/cortina-crm/cortina-tracking/node_modules/next/dist/server/next-server.js:770:9)\n' +
' at async Object.fn (/home/dopaminedriven/prisma-nexus-next-ts/cortina-crm/cortina-tracking/node_modules/next/dist/server/next-server.js:661:37)\n' +
' at async Router.execute (/home/dopaminedriven/prisma-nexus-next-ts/cortina-crm/cortina-tracking/node_modules/next/dist/server/router.js:205:32)\n' +
' at async DevServer.run (/home/dopaminedriven/prisma-nexus-next-ts/cortina-crm/cortina-tracking/node_modules/next/dist/server/next-server.js:841:29)\n' +
' at async DevServer.run (/home/dopaminedriven/prisma-nexus-next-ts/cortina-crm/cortina-tracking/node_modules/next/dist/server/dev/next-dev-server.js:355:20)',
name: 'TypeError'
}
that's after the oauth callback logs all of my github info to the console in json format correctly...Phil Bookst
09/26/2021, 10:04 AMmodel Profile {
id String? @unique
username String @id
is_private Boolean?
is_verified Boolean?
full_name String?
biography String?
profile_pic_url String?
post_amount Int?
follower Int?
following Int?
imageTags ImageTags[]
nodes Image[] // this is the slow relation
SearchProfiles SearchProfiles[]
@@map("profile")
}
model Image {
id String @id
thumbnail String
shortcode String @unique
liked Int
comment_count Int
engagement_rate Float?
day Int?
hour Int?
date String
caption String?
profile Profile? @relation(fields: [profileUsername], references: [username])
profileUsername String?
hashtag Hashtag? @relation(fields: [hashtagName], references: [name])
hashtagName String?
location Location? @relation(fields: [locationId], references: [id])
locationId String?
imageHashtags ImageHashtags[]
imageTags ImageTags[]
imageLocations ImageLocations[]
@@map("image")
}
if i run this query, it takes about 4-5 seconds to give me the results
const user = await prisma.profile.findUnique({
where: {
username,
},
include: {
nodes: true,
},
});
if i run it without the include it takes around 200ms
const user = await prisma.profile.findUnique({
where: {
username,
},
});
the profile table has around 370k entries and and image table around 620kPeter Boomsma
09/26/2021, 10:30 AMUser
table, each User
can have multiple FollowedBy
records (a many to many relation to other Users).
I want to push a record (a notification) to each of the FollowedBy
users of the current user if a certain action has been done.
model User {
id Int @id @default(autoincrement())
email String @unique
name String
user_name String @unique
password String
movies Movie[]
notifications Notification[]
followedBy User[] @relation("UserFollows", references: [id])
following User[] @relation("UserFollows", references: [id])
}
model Notification {
id Int @id @default(autoincrement())
link String?
movie_id Int?
message String
icon String?
thumbnail String?
user User @relation(fields: [userId], references: [id])
userId Int
watched Boolean
}
So I need a create function on the notification:
createNotification: async (_, args, {req, res}) => {
const notification = await prisma.notification.create({
});
return notification;
},
What would be the best way to go through the list of FollowedBy
users for the current user? (current user id is available on the req req.userId
Thomas Morice
09/26/2021, 7:12 PMuser
09/26/2021, 11:00 PMCharles Dimino
09/27/2021, 5:08 AMAndrew Ross
09/27/2021, 5:55 AMconst userCreate = ({
email,
name,
dob,
role,
type,
provider,
accessToken,
providerAccountId,
isAdmin
}: {
isAdmin: boolean;
email: string;
name: string;
dob: string;
role: Role;
type: string;
provider: string;
accessToken: string;
providerAccountId: string;
}) => {
return Prisma.validator<
Prisma.UserCreateInput extends Prisma.AccountCreateInput
? Prisma.UserCreateInput & Partial<Prisma.AccountCreateInput>
: Prisma.UserCreateInput
>()({
email,
isAdmin: role === "USER" ? !isAdmin : !!isAdmin,
name,
accounts:
{
create: {
type,
provider,
accessToken,
providerAccountId,
dob,
role
}
} ?? {}
});
};
Manthan Mallikarjun
09/27/2021, 6:35 AMexport const prisma = new PrismaClient({
datasources: { db: { url: generateDatabaseURL(schemaId) } },
});
and I know it works because doing console.log shows:
datasourceOverrides: [Object: null prototype] {
db: '<postgresql://example:example@localhost:54321/example?schema=test-9d1a4b74-2304-4edf-8663-92ec3bb55a7a>'
},
in the mess. However when I query the data, its actually coming from the default schema and not the schema listed above (I used a postgres viewer to go check the data in the tables of each of those schemas). Any idea why this would be happening?Harun
09/27/2021, 6:49 AMHarsha MV
09/27/2021, 8:01 AMPrismaClientValidationError: Unknown arg `youtube` in data.youtube for type ProjectCreateInput. Did you mean `about`?
I added this as a new migrate and its reflecting in the database as well. but am getting the following error when I try to create the recordCharity Darko
09/27/2021, 9:10 AMmodel Company {
id Int @id
name String
users User[]
}
model User {
userId Int @default(autoincrement()) @id
companyId Int?
worksAt Company? @relation(fields: [companyId], references: [id])
email String? @unique
name String
password String
@@map(name: "users")
When I run $ prisma db push I get this error. Any assistance will be appreciatedHarsha MV
09/27/2021, 9:29 AMPrismaClientUnknownRequestError: Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error { kind: ToSql(0), cause: Some(Error(Parser(InvalidLength { expected: Any([36, 32]), found: 0 }))) }) })
at cb (/var/task/node_modules/@prisma/client/runtime/index.js:36956:17)
at async handler (/var/task/.next/server/pages/api/projects.js:261:29)
at async Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils.js:101:9)
at async Server.handleApiRequest (/var/task/node_modules/next/dist/server/next-server.js:760:9)
at async Object.fn (/var/task/node_modules/next/dist/server/next-server.js:651:37)
at async Router.execute (/var/task/node_modules/next/dist/server/router.js:205:32)
at async Server.run (/var/task/node_modules/next/dist/server/next-server.js:825:29)
at async Server.handleRequest (/var/task/node_modules/next/dist/server/next-server.js:292:20)
at async Server.<anonymous> (/var/task/___next_launcher.js:32:9) {
clientVersion: '3.1.1'
}
Any idea why this error happens?