(fix) re-connect prisma if not connected

This commit is contained in:
ishaan-jaff 2024-01-05 17:58:23 +05:30
parent d2578f0cd2
commit 90973d92bf

View file

@ -395,6 +395,10 @@ class PrismaClient:
Add a key to the database. If it already exists, do nothing.
"""
try:
# incase prisma is not connected
if self.db.is_connected() == False:
await self.connect()
if table_name == "user+key":
token = data["token"]
hashed_token = self.hash_token(token=token)
@ -473,6 +477,10 @@ class PrismaClient:
Update existing data
"""
try:
# incase prisma is not connected
if self.db.is_connected() == False:
await self.connect()
db_data = self.jsonify_object(data=data)
if token is not None:
print_verbose(f"token: {token}")
@ -515,6 +523,9 @@ class PrismaClient:
Allow user to delete a key(s)
"""
try:
# incase prisma is not connected
if self.db.is_connected() == False:
await self.connect()
hashed_tokens = [self.hash_token(token=token) for token in tokens]
await self.db.litellm_verificationtoken.delete_many(
where={"token": {"in": hashed_tokens}}