user
10/19/2021, 9:25 AMSuhani Shah
10/19/2021, 12:06 PMtest
table for column createdDate
but in my case issue is graphql automatically convert into UTC, so, It store UTC date in DB
Also I tried with custom resolver to modify UTC into company timezone but still it stores UTC value, because of the prisma I think
let date = dayjs().tz(authenticated.companyTimezone).format('YYYY-MM-DD HH:mm:ss') (OUTPUT "2021-10-19T13:42:00+02:00")
const payload = {
...data,
CreatedDate: date,
}
return prisma.Test.create({
data: payload,
...select,
})
So, again prisma convert into UTC because of +02.00
in above date value.Mark
10/19/2021, 1:18 PMnpx prisma format
it automatically added @unique
to some of our foreign key columns. Whilst this might be beneficial for some, this automatic addition of directive prohibits us from re-using our featured image across Recipes.user
10/19/2021, 1:33 PMConor Wade
10/19/2021, 3:37 PMorder by id ASC
clause to this:
const answers = await prisma.answer.findMany({
take: 50,
where: {
questionId: questionId,
},
select: {
body: true,
response: {
select: {
year: true,
unit: {
select: {
id: true,
name: true,
},
},
},
},
},
})
(Edit: Please ignore this, as I am an idiot. Order is needed for the limit offset to work)
Yaakov
10/19/2021, 3:57 PMprisma db seed
command? In other words, to get all the insert statements without actually running them?Julien Goux
10/19/2021, 5:52 PMJulien Goux
10/19/2021, 5:53 PMJulien Goux
10/19/2021, 5:53 PMYaakov
10/19/2021, 6:45 PM"No 'State' record(s) (needed to inline the relation on 'Facility' record(s)) was found for a nested connect on one-to-many relation 'FacilityToState'."
.
How can I control the order in which my tables seed?
Here is my code:
seed.js
require('./seeds/stateSeeder');
require('./seeds/facilitySeeder');
stateSeeder.js
const faker = require('faker/locale/en_US');
const prisma = require('../client');
async function main() {
const states = faker.definitions.address.state;
const stateAbbrs = faker.definitions.address.state_abbr;
const data = states.map((state, i) => ({ name: state, abbr: stateAbbrs[i] }));
await prisma.state.createMany({ data });
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
facilitySeeder.js
const prisma = require('../client');
async function main() {
await prisma.facility.create({
name: 'Name',
address: '123 Broad St',
city: 'Chicago',
zip: '60652',
state: {
connect: { abbr: 'IL' }
}
});
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});
client.js
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient({ log: ['query'] });
module.exports = prisma
Ronit Rahaman
10/19/2021, 6:51 PMTyler Bell
10/19/2021, 7:37 PMMoh
10/19/2021, 10:25 PMprisma.parent.update({
name: "Bob",
age: 30,
children: {
upsert: payload.children.map(child => (
where: { id: child.id },
create: { ... },
update: { ... }
))
}
})
Bruno Marques
10/19/2021, 10:27 PMGabe O'Leary
10/19/2021, 11:54 PMschema.prisma
file looks like:
model User {
idStr String @id
name String?
statuses Status[]
}
model Status {
idStr String @id
createdAt DateTime
userIdStr String
user User? @relation(fields: [userIdStr], references: [idStr])
}
But I get this error:
Foreign key constraint failed on the field: `Status_userIdStr_fkey (index)`
when I try to create a status that has a userIdStr
for which there is no corresponding User
.
How do I set up my models such that there doesn't have to be a User
present for a given Status.userIdStr
?Akshay Kadam (A2K)
10/20/2021, 6:47 AMCascade
not working?
Error: Schema parsing
error: No such argument.
--> schema.prisma:26
|
25 |
26 | user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
error: No such argument.
--> schema.prisma:36
|
35 | expires DateTime
36 | user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
Validation Error Count: 2
Akshay Kadam (A2K)
10/20/2021, 6:48 AMprisma
work with next-auth
by following steps suggested here → https://next-auth.js.org/adapters/prismaAkshay Kadam (A2K)
10/20/2021, 6:49 AMonDelete: Cascade
Akshay Kadam (A2K)
10/20/2021, 6:50 AMuser
10/20/2021, 6:54 AMRene Nielsen
10/20/2021, 7:13 AMlet filter = {
include: {
category: true,
instructor: true,
lections: true,
},
where: {
OR: [
{
title: {
startsWith: search,
mode: 'insensitive',
},
},
{
title: {
contains: search,
mode: 'insensitive',
},
},
{
description: {
startsWith: search,
mode: 'insensitive',
},
},
{
description: {
contains: search,
mode: 'insensitive',
},
},
]
}
};
I get the following Typescript error. (Using Prisma 3.3.0)
Argument of type '{ include: { category: boolean; instructor: boolean; lections: boolean; }; where: { OR: ({ title: { startsWith: any; mode: string; contains?: undefined; }; description?: undefined; } | { title: { contains: any; mode: string; startsWith?: undefined; }; description?: undefined; } | { ...; } | { ...; })[]; }; }' is not assignable to parameter of type '{ select?: CourseSelect | null | undefined; include?: CourseInclude | null | undefined; where?: CourseWhereInput | undefined; orderBy?: Enumerable<...> | undefined; cursor?: CourseWhereUniqueInput | undefined; take?: number | undefined; skip?: number | undefined; distinct?: Enumerable<...> | undefined; }'.
The types of 'where.OR' are incompatible between these types.
Type '({ title: { startsWith: any; mode: string; contains?: undefined; }; description?: undefined; } | { title: { contains: any; mode: string; startsWith?: undefined; }; description?: undefined; } | { description: { ...; }; title?: undefined; } | { ...; })[]' is not assignable to type 'Enumerable<CourseWhereInput> | undefined'.
Type '({ title: { startsWith: any; mode: string; contains?: undefined; }; description?: undefined; } | { title: { contains: any; mode: string; startsWith?: undefined; }; description?: undefined; } | { description: { ...; }; title?: undefined; } | { ...; })[]' is not assignable to type 'CourseWhereInput[]'.
Type '{ title: { startsWith: any; mode: string; contains?: undefined; }; description?: undefined; } | { title: { contains: any; mode: string; startsWith?: undefined; }; description?: undefined; } | { description: { ...; }; title?: undefined; } | { ...; }' is not assignable to type 'CourseWhereInput'.
Type '{ title: { startsWith: any; mode: string; contains?: undefined; }; description?: undefined; }' is not assignable to type 'CourseWhereInput'.
Types of property 'title' are incompatible.
Type '{ startsWith: any; mode: string; contains?: undefined; }' is not assignable to type 'string | StringFilter | undefined'.
Type '{ startsWith: any; mode: string; contains?: undefined; }' is not assignable to type 'StringFilter'.
Types of property 'mode' are incompatible.
Type 'string' is not assignable to type 'QueryMode | undefined'.ts(2345)
Tobias Lins
10/20/2021, 7:43 AMMoh
10/20/2021, 10:30 AMEdward Baer
10/20/2021, 1:34 PMconst getSequenceBlock = async (sequenceName, addCount = 1) => {
let data = false;
try {
st [callGetSequenceBlock, getStartEnd] = await prisma.$transaction([
`prisma.$executeRaw(CALL GetSequenceBlock('${sequenceName}', ${addCount}, @start, @end);
),`
`prisma.$queryRaw(SELECT @newSeqStart, @newSeqEnd FROM DUAL;
),
]);`
// Successful result comes back as [ { '@newSeqStart': 146, '@newSeqEnd': 151 } ]
if (Array.isArray(getStartEnd)) {
const row = getStartEnd[0];
if (typeof row === 'object') {
data = {
start: row['@newSeqStart'],
end: row['@newSeqEnd'],
};
}
}
} catch (error) {
throw error;
}
return data;
};
Chip Clark
10/20/2021, 2:47 PMUnknown arg `id` in data.id for type MainSidebarUpdateInput. Available args:
type MainSidebarUpdateInput {
Main_Sidebar?: String | NullableStringFieldUpdateOperationsInput | Null
}
+34621ms
Error:
Invalid `prisma.mainSidebar.update()` invocation:
{
where: { ID: 1 }
service:
async updateMainSidebar(params: {
where: Prisma.MainSidebarWhereUniqueInput;
data: Prisma.MainSidebarUpdateInput;
}) {
const { where, data } = params;
return this.prisma.mainSidebar.update({
where,
data
});
}
controller:
@Put(`${Route}/:id`)
async update(
@Param('id', ParseIntPipe) ID: number,
@Body() data: Prisma.MainSidebarUpdateInput
) {
return this.mainSidebarService.updateMainSidebar({
where: { ID },
data,
});
}
schema
model MainSidebar {
ID Int @id @default(autoincrement())
Main_Sidebar String? @db.VarChar(Max)
}
Application side error:
HttpErrorResponse: {"headers":{"normalizedNames":{},"lazyUpdate":null},"status":500,"statusText":"Internal Server Error","url":"<http://am-web11:3060/api/sidebar/1>","ok":false,"name":"HttpErrorResponse","message":"Http failure response for <http://am-web11:3060/api/sidebar/1>: 500 Internal Server Error","error":{"statusCode":500,"message":"Internal server error"}}
Reuben Porter
10/20/2021, 4:45 PMError querying the database: db error: FATAL: sorry, too many clients already
error?Reuben Porter
10/20/2021, 4:46 PMPerry Raskin
10/20/2021, 5:00 PM{ userId: 50 }
and { User: { connect: { id: 50 } } }
?Perry Raskin
10/20/2021, 5:02 PM{ userId: 50 }
is only allowed in v2.11.0 and above? is that all?Michael Aubry
10/20/2021, 9:45 PMThe provided value for the column is too long for the column's type
the error is straightforward. What I don’t understand is when writing to the same table with the same data in my session it works, but in my employees session he is getting this error.
I have noticed this inconsistency quite often. I am using Vercel serverless functions to interface with PostgreSQL so maybe there is a connection pool issue? We’re starting to grow and have one of the most amount of concurrent users I’ve seen. So I think its a serverless concurrency issue/
Any ideas?
This video seems like it may be helpful