Naresh Bhatia
10/29/2021, 2:22 AMNaresh Bhatia
10/29/2021, 3:10 AMChris Tsongas
10/29/2021, 4:32 AM.prisma/client
vs @prisma/client
? Both seem to work.Gelo
10/29/2021, 5:54 AMYerzhan
10/29/2021, 9:48 AMMessage: Error in Prisma Client request:
Invalid `prisma.user.findMany()` invocation:
connect ECONNREFUSED ::1:55237
Dev__
10/29/2021, 10:10 AM3.6666666666666666667
to
3.67
Harun
10/29/2021, 11:12 AMP V
10/29/2021, 12:17 PMChristophe Rudyj
10/29/2021, 1:15 PMprisma
// 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"
}
model Games {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
short_hand String @unique @db.VarChar(255)
name String @unique @db.VarChar(255)
in_boxes Box[]
set Sets[]
}
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
username String @unique @db.VarChar(255)
password String @db.VarChar(255)
role Role @default(USER)
first_name String? @db.VarChar(255)
last_name String? @db.VarChar(255)
store String? @db.VarChar(255)
boxes Box[]
}
model Store {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @unique @db.VarChar(255)
}
model Box {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
box_number String @db.VarChar(100)
box_second_number String? @db.VarChar(100)
set String @db.VarChar(255)
set_list Sets @relation(fields: [set], references: [name])
gameid Int? @default(1)
game Games? @relation(fields: [gameid], references: [id])
User User? @relation(fields: [userId], references: [id])
userId Int?
}
model Sets {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String @unique @db.VarChar(255)
code String @unique @db.VarChar(255)
children String[]
in_boxes Box[]
game String? @db.VarChar(255)
gamerel Games? @relation(fields: [game], references: [short_hand])
edition String?
}
enum Role {
USER
ADMIN
CHRIS
}
Basically a user will have boxes that they own (
The boxes has a Game Type and contains a parent Set which
Has it own set code and contain set children (array)
The game type it self has only name and shortcode
My main issue is that when I try to create a set with the resolver code
graphql
//the graphql
mutation {
createBox (input:{box_number:"001", secondary_number:"A", game:{name:"yu"}, set:"Crucibile of War Unlimit"}) {
box_number
set
game
id
}
}
`
the resolver
ts
createBox: async (_: any, { input }: any, context: Context) => {
const find = await context.prisma.games.findFirst({
where: {name: {contains:input.game[0].name,
mode:"insensitive"}}
}
);
console.log(find);
console.log(input.set);
return await context.prisma.box.create({
data: {
box_number: input.box_number,
box_second_number: input.secondary_number,
gameid: find?.id,
set: {connect: {
name: input.set
},
},
},
});
},
I get
75 return await context.prisma.box.create(",
" Foreign key constraint failed on the field: `Box_set_fkey (index)`",
" at cb
I'm really confused on how to make it workper
10/29/2021, 1:48 PMconnect
to create a relation to the already existing player
in the database, which works perfectly.
I can’t seem to find how to make this connect
conditional though. The player 1 will always be there, but player 2 is not always provided (if the team only consists of only one player).
Prisma stops record creation that is sees that player 2 is not specified of course. How can I solve this issue?
Code below
export default async function createTeam(
req: NextApiRequest,
res: NextApiResponse
) {
const teamData = JSON.parse(req.body)
const team = await prisma.team.create({
data: {
player1: {
connect: {
id: teamData?.player1?.id,
},
},
player2: {
connect: {
id: teamData?.player2?.id,
},
},
groups: {
connect: {
id: 'group1-id-test',
},
},
},
})
Austin Zentz
10/29/2021, 2:30 PMconst data = {
player1: {
connect: {
id: teamData?.player1?.id,
},
},
groups: {
connect: {
id: 'group1-id-test',
},
},
};
if (teamData?.player2) {
data.player2 = {
connect: {
id: teamData?.player2?.id,
},
}
}
const team = await prisma.team.create({
data
});
Julien Goux
10/29/2021, 8:08 PMJulien Goux
10/29/2021, 8:11 PMp0wl
10/30/2021, 9:29 AMWingy
10/30/2021, 2:35 PMcreate({ data: ... })
on every record I get this issue:
[Ingest] [ship-kills] 793828176027320321n failed PrismaClientUnknownRequestError:
Invalid `this.GalaxyInfo.prisma.kills.create()` invocation in
/home/wingy/Code/Personal/Discord Bots/galaxy-info-v2/dist/ingest/shipKills.js:138:64
135 if (!firstMessage || messages.map(message => message.id).includes(mostRecentKillId)) {
136 for (const kill of alreadyParsed) {
137 try {
→ 138 await this.GalaxyInfo.prisma.kills.create(
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(SqliteFailure(Error { code: DatabaseCorrupt, extended_code: 11 }, Some("database disk image is malformed"))) })
at cb (/home/wingy/Code/Personal/Discord Bots/galaxy-info-v2/node_modules/@prisma/client/runtime/index.js:38541:17)
at async fetchOldKills (/home/wingy/Code/Personal/Discord Bots/galaxy-info-v2/dist/ingest/shipKills.js:138:29) {
clientVersion: '3.3.0'
}
Is this too much for sqlite? Would I be better off using postgres?Yazid Daoudi
10/30/2021, 5:28 PMaspect
10/30/2021, 10:13 PMaspect
10/30/2021, 10:13 PMA DSJ
10/31/2021, 5:55 PMawait prisma.Item.updateMany({
data: [...updatedItems],
})
Maybe an identifier ? PK are ID's that are present inside ;y objects, but I don't know how to let prisma see those ID and update the right records (maybe its automatic ?)A DSJ
10/31/2021, 5:56 PMA DSJ
10/31/2021, 5:59 PMdata: updatedItems,
And I get the same errorPerry Raskin
10/31/2021, 6:59 PMChris Packett
10/31/2021, 8:21 PMMoh
10/31/2021, 9:20 PMSELECT SCOPE_IDENTITY()
koriner
10/31/2021, 10:43 PMError validating model "Directory": Ambiguous self relation detected. The fields `parent` and `directories` in model `Directory` both refer to `Directory`. If they are part of the same relation add the same relation name for them with `@relation(<name>)`.
John Smeeth
11/01/2021, 4:08 AMconst groupLeader = await ctx.prisma.transaction.groupBy({
by: ['userId'],
where: {...},
_sum: {
quantity: true,
},
orderBy: {
_sum: {
quantity: 'desc',
},
},
})
John Smeeth
11/01/2021, 4:09 AMKJReactor
11/01/2021, 10:44 AMYossef Wakslicht
11/01/2021, 11:18 AMYaakov
11/01/2021, 1:11 PM