Dhananjay Takalkar
03/28/2022, 7:29 AMMartin Hoang
03/28/2022, 7:58 AMutf8
charset, prisma is using utf8mb4
and I just can't change existing table to use utf8mb4
Dev__
03/28/2022, 8:01 AMTemporaryData
and Data
. Is there an easy way to copy the rows from TemporaryData
to the Data
table? The model structure will be exactly the sameEko Nur Arifin
03/28/2022, 8:46 AMBlue Nebula
03/28/2022, 8:47 AMprisma.table.upsert({
where:{...},
update:data,
create:data
});
to add something to a table with an unique column, overwriting the row with the same unique value if it already exists?louis-sanna-eki
03/28/2022, 9:08 AMs1w
03/28/2022, 1:29 PMENOENT: no such file or directory, open ../path/to/prisma.schema
(replaced path). More details in thread.superbunches
03/28/2022, 4:34 PMlocalhost:3000
was causing PrismaClient and my project to be out of sync.
I’ll do my best to describe what happened in a thread 👇Mykyta Machekhin
03/28/2022, 6:01 PM.create, .update
etc) are not work at all if I don’t use await
, .then
or .catch
on this methods. Can someone explain me why is it?Andrew Knackstedt
03/29/2022, 3:07 AMChris Bitoy
03/29/2022, 5:56 AMInvalid `prisma.category.create()` invocation:
{
data: {
+ name: String,
? description?: String | null,
? url?: String | null,
subCategories: {
createMany: {
data: {
'0': {
+ name: String,
? description?: String | null,
? url?: String | null,
? image?: String | null,
sub: {
~~~
createMany: {
data: [
{
name: undefined,
description: undefined,
url: undefined,
image: undefined
}
]
}
},
? id?: Int,
? subId?: Int | null,
? createdAt?: DateTime,
? updatedAt?: DateTime
}
}
}
},
? icon?: String | null,
? bgColor?: String | null,
? createdAt?: DateTime,
? updatedAt?: DateTime
}
}
Unknown arg `sub` in data.subCategories.createMany.data.0.sub for type SubcategoryCreateManyCategoryInput. Did you mean `subId`?
Argument name for data.subCategories.createMany.data.0.name is missing.
Argument name for data.name is missing.
Note: Lines with + are required, lines with ? are optional.
Schema:
model Category {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
url String? @db.VarChar(255)
icon String? @db.VarChar(255)
description String? @db.VarChar(255)
bgColor String? @db.VarChar(255)
subCategories Subcategory[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Subcategory {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
description String?
image String?
url String?
category Category @relation(fields: [categoryId], references: [id])
sub Sub[]
categoryId Int
subId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Program Program[]
}
model Sub {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
description String?
image String?
url String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
categoryId Int
category Subcategory? @relation(fields: [subcategoryId], references: [id])
subcategoryId Int?
}
create file:
import { PrismaClient } from '@prisma/client';
import { data } from '../../../categoryData';
const ArtData = async (req, res) => {
const prisma = new PrismaClient({ log: ['query'] });
try {
const categoryData = req.body;
await categoryData.map(async (category) => {
const { name, description, url, subCategories } = category;
const {
subName = name,
subDescription = description,
subUrl = url,
image,
sub,
} = subCategories;
const categories = await prisma.category.create({
data: {
name,
description,
url,
subCategories: {
createMany: {
data: [
{
name: subName,
description: subDescription,
url: subUrl,
sub: {
createMany: {
data: [
{
// name: innerName,
},
],
},
},
image,
},
],
},
},
},
});
});
res.status(201).json({ 'category: ': categoryData });
} catch (error) {
console.error(error);
res.status(500);
res.json({ error: 'something went wrong', error });
} finally {
await prisma.$disconnect();
}
};
export default ArtData;
louis-sanna-eki
03/29/2022, 6:25 AMnpm install prisma --save-dev
then generating from the prisma schema,
npx prisma generate
it breaks the typing of the pre-existing mongoose schema. If I look at the .lock I see no change that could explain it.
Any guesses?louis-sanna-eki
03/29/2022, 6:26 AMJonathan
03/29/2022, 8:07 AMOkan Yıldırım
03/29/2022, 11:30 AMOkan Yıldırım
03/29/2022, 11:30 AMJason
03/29/2022, 2:00 PMMischa
03/29/2022, 2:13 PMshahrukh ahmed
03/29/2022, 2:20 PMTopi Pihko
03/29/2022, 2:49 PMPrisma.service:
async auth(func: any): Promise<any> {
[ignore, result] = await this.$transaction([
this.$executeRaw`SET local "auth.principal" = "1234567890"`,
func,
]);
return result;
}
Usage:
async getUsers(): Promise<User[]>{
return this.prisma.auth(this.prisma.user.findMany());
}
Tryout with $use, but queries are not run inside the same transaction -> auth.principal is not set when actual query is ran resulting empty array.
Prisma.service:
this.$use(async (params, next) => {
// Set auth variable in a transaction
const setTransActionResult = await next({
args: {
query: 'SET local "auth.principal" = "1234567890"',
parameters: {
values: '[]',
__prismaRawParamaters__: true,
},
},
dataPath: [],
runInTransaction: true,
action: 'executeRaw',
model: undefined,
});
params.runInTransaction = true;
// Run original query here
return await next(params);
});
Usage:
async getUsers(): Promise<User[]>{
return this.prisma.user.findMany();
}
Tobias Lins
03/29/2022, 2:57 PMJson
I really want to have a typescript type but it should be stored in the database column as json.
I can't find any issue for that - should I create one or is there a solution for that?Yaakov
03/29/2022, 3:25 PMskipDuplicates
with SQL Server?Richard
03/29/2022, 3:49 PMconnectOrCreate
and disconnect
in a single query when updating many:many relations?Yaakov
03/29/2022, 4:11 PMupsertMany
?Johny Velho
03/29/2022, 5:08 PMDaan Helsloot
03/30/2022, 3:39 AMfindUnique
call compared to a findFirst
call? Is there any difference and if so, how big is it?user
03/30/2022, 9:30 AMJaved Iqbal
03/30/2022, 9:48 AMOrcioly Andrade Alves
03/30/2022, 12:52 PMgenerator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid())
name String
email String @unique
password String
isAdmin Boolean @default(false)
created_at DateTime @default(now())
updated_at DateTime @updatedAt
Client Client[]
@@map("users")
}
model Client {
id String @id @default(uuid())
user_id String
name User @relation(fields: [user_id], references: [id])
address String
city String
district String
state String
zipcode String
cnpj String @unique
stateregistered String
telephone String
mobile String
active Boolean
created_at DateTime @default(now())
updated_at DateTime @updatedAt
Order OrderClient[]
@@map("clients")
}
model Product {
id String @id @default(uuid())
followUp String
fabric String?
name String
size String
color String
status String
code_karsten String
price Decimal @default(0.00)
isActive Boolean
created_at DateTime @default(now())
updated_at DateTime @updatedAt
Order OrderClient[]
@@map("products")
}
model OrderClient {
id String @id @default(uuid())
name Client @relation(fields: [client_id], references: [id])
client_id String
product Product @relation(fields: [product_id], references: [id])
product_id String
quantity Int
size String
color String
status String
code_karsten String
price Decimal @default(0.00)
liquid Decimal @default(0.00)
priceTotal Decimal @default(0.00)
created_at DateTime @default(now())
updated_at DateTime @updatedAt
@@map("orders_clients")
}
CreateOrderClientService.ts:
import { AppError } from '../shared/errors/AppError';
import prismaClient from '../prisma';
import { CreateOrderClientDTO } from '../dtos/order_client/CreateOrderClientDto';
class CreateOrderClientService {
async execute({
client_id,
product_id,
quantity,
size,
color,
status,
code_karsten,
price,
liquid,
priceTotal,
}: CreateOrderClientDTO) {
const order = await prismaClient.orderClient.create({
data: {
client_id,
product_id,
quantity,
size,
color,
status,
code_karsten,
price,
liquid,
priceTotal,
},
include: {
name: {
select: {
name: {
select: {
id: true,
name: true,
email: true,
isAdmin: true,
created_at: true,
updated_at: true,
},
},
},
},
product: true,
},
});
return order;
}
}
export { CreateOrderClientService };
Alex Service
03/30/2022, 2:28 PM{
"data": {
"field_one": {
"field_two": "hello"
}
}
}
In postgres, I could quickly find records matching on field_two’s value like so:
SELECT doc_col FROM "MyTable" WHERE doc_col @> '{"data": {"field_one": {"field_two": "hello"}}}'
I have my table created in schema.prisma
with doc_col set as Json and enabled prisma’s “filterJson” previewFeature. I wrote the following graphql query, which takes 4 seconds:
query { myTables(where: {doc_col: {path: ["data", "field_one", "field_two"], equals: "0004"}}) }