Mohammad Orabi 🇱🇧
Mohammad Orabi 🇱🇧
Explore posts from servers
PPrisma
Created by Mohammad Orabi 🇱🇧 on 11/22/2024 in #help-and-questions
TypedSql generating wrong types from the query
No description
5 replies
PPrisma
Created by Mohammad Orabi 🇱🇧 on 11/22/2024 in #help-and-questions
Bug in TypedSQL in version 5.22
Here is my schema postgres latest
generator client {
provider = "prisma-client-js"
previewFeatures = ["typedSql"]
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["typedSql"]
}
my chest Table
model Chest {
id String @id @default(cuid()) @map("id")
name String @map("name")
imageUrl String? @map("image_url")
description String? @map("description")
rarity Rarity @map("rarity")
amount Int? @map("amount")
gameId String @map("game_id")
game Game @relation(fields: [gameId], references: [id], onDelete: Cascade)
currencies ChestCurrency[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@unique([gameId, rarity])
@@index([gameId])
@@map("chests")
}
model Chest {
id String @id @default(cuid()) @map("id")
name String @map("name")
imageUrl String? @map("image_url")
description String? @map("description")
rarity Rarity @map("rarity")
amount Int? @map("amount")
gameId String @map("game_id")
game Game @relation(fields: [gameId], references: [id], onDelete: Cascade)
currencies ChestCurrency[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@unique([gameId, rarity])
@@index([gameId])
@@map("chests")
}
my test query inside prisma/sql
-- @name test
SELECT *
FROM chests
-- @name test
SELECT *
FROM chests
implemention
try {
const result = await db.$queryRawTyped(test());
log.info({
msg: 'result',
result,
});
} catch (error) {
log.error({
msg: 'Error in test query',
error,
});
}
try {
const result = await db.$queryRawTyped(test());
log.info({
msg: 'result',
result,
});
} catch (error) {
log.error({
msg: 'Error in test query',
error,
});
}
error
ERROR: Error in test query
error: {
"clientVersion": "5.22.0"
}
ERROR: Error in test query
error: {
"clientVersion": "5.22.0"
}
error without a catch
"Cannot read properties of undefined (reading 'map')"
"Cannot read properties of undefined (reading 'map')"
9 replies
PPrisma
Created by Mohammad Orabi 🇱🇧 on 10/29/2024 in #help-and-questions
Live events with prisma pulse for games
Hello , My backend is a traditional transactional backend that serves multiple games at the same time . it stores balance , open chests , give rewards etc , but nothing like a "game server" for real time things , however recently for some games I want to implement real time events such as user is playing (think of it like subway surf) , he reaches some checkpoint/num of minutes , need to grab this event from the game and check if he matches the event requirements and then reward the user with keys , I already have this system with request/response , but now the key should actually directly be spanned into the game , so the game should have a direct instant reward would having web sockets between the game and my server + my server and prisma pulse solve that
4 replies
PPrisma
Created by Mohammad Orabi 🇱🇧 on 7/18/2024 in #help-and-questions
Types are broken because of read replicas extension
I am exporting this singleton in my whole application
const prisma = new PrismaClient({
log: ['info', 'error', 'warn'],
}).$extends(
readReplicas({
url: databaseUrlReplicas,
}),
);

export { prisma };
const prisma = new PrismaClient({
log: ['info', 'error', 'warn'],
}).$extends(
readReplicas({
url: databaseUrlReplicas,
}),
);

export { prisma };
now I want to pass prisma as a type so that I pass transactions for example
await prisma.$transaction(async (prisma) => {
await prisma.gameDailyStreak.create({
data: {
userId,
gameId,
day: 1,
lastStreak: new Date(),
total: 1,
},
});
return await claimReward({ userId, gameId, day: 1, prisma });
});
await prisma.$transaction(async (prisma) => {
await prisma.gameDailyStreak.create({
data: {
userId,
gameId,
day: 1,
lastStreak: new Date(),
total: 1,
},
});
return await claimReward({ userId, gameId, day: 1, prisma });
});
in claimReward I used this
prisma: Prisma.TransactionClient;
prisma: Prisma.TransactionClient;
typescript will shout out me , once I remove the $.extends it works how do I grab the correct type
1 replies
PPrisma
Created by Mohammad Orabi 🇱🇧 on 5/16/2024 in #help-and-questions
Setting Connection limit in gcp cloud run and cloud sql
What is the best practice when setting the connection limit of prisma in gcp cloud run? * I am using postgres from cloud sql * I have a master database with 14 cpu and 20GB ram * 3 replicas each with 10 cpus and 20GB ram , each can handle 500 connections * cloud run with multiple instances , each instance with 2 GiB memory and 2 cpus how can I know what is the best connection limit to set , as I noticed increasing them is disconnecting cloud run from the sql sometimes ps : I am using replicas extension
const prisma = new PrismaClient().$extends(
readReplicas({
url: DATABASE_URL_REPLICAS
})
);
const prisma = new PrismaClient().$extends(
readReplicas({
url: DATABASE_URL_REPLICAS
})
);
20 replies