Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

Commit

Permalink
Merge branch 'main' into 491-markv-apple-sillicon-support
Browse files Browse the repository at this point in the history
  • Loading branch information
vanakema authored Jul 12, 2024
2 parents 37206d5 + cc3af1f commit 311c389
Show file tree
Hide file tree
Showing 18 changed files with 625 additions and 244 deletions.
21 changes: 12 additions & 9 deletions src/leapfrogai_api/data/crud_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ async def create(self, object_: ModelType) -> ModelType | None:
if "user_id" in response[0]:
del response[0]["user_id"]
return self.model(**response[0])
except Exception:
return None
except Exception as e:
raise e

async def get(self, filters: dict | None = None) -> ModelType | None:
"""Get row by filters."""
Expand All @@ -56,8 +56,10 @@ async def get(self, filters: dict | None = None) -> ModelType | None:
if "user_id" in response[0]:
del response[0]["user_id"]
return self.model(**response[0])
except Exception:
except IndexError:
return None
except Exception as e:
raise e

async def list(self, filters: dict | None = None) -> list[ModelType]:
"""List all rows."""
Expand All @@ -75,8 +77,8 @@ async def list(self, filters: dict | None = None) -> list[ModelType]:
if "user_id" in item:
del item["user_id"]
return [self.model(**item) for item in response]
except Exception as exc:
raise Exception from exc
except Exception as e:
raise e

async def update(self, id_: str, object_: ModelType) -> ModelType | None:
"""Update a row by its ID."""
Expand All @@ -93,8 +95,10 @@ async def update(self, id_: str, object_: ModelType) -> ModelType | None:
if "user_id" in response[0]:
del response[0]["user_id"]
return self.model(**response[0])
except Exception:
except IndexError:
return None
except Exception as e:
raise e

async def delete(self, filters: dict | None = None) -> bool:
"""Delete a row by filters."""
Expand All @@ -115,9 +119,8 @@ async def _get_user_id(self) -> str:
"""Get the user_id from the API key."""

if self.db.options.headers.get("x-custom-api-key"):
data, _count = await self.db.table("api_keys").select("user_id").execute()
_, tmp = data
user_id: str = tmp[0]["user_id"]
result = await self.db.table("api_keys").select("user_id").execute()
user_id: str = result.data[0]["user_id"]
else:
user_id = (await self.db.auth.get_user()).user.id

Expand Down
Loading

0 comments on commit 311c389

Please sign in to comment.