(self, table: str, pkey_name: str, data)
| 71 | return response |
| 72 | |
| 73 | async def upsert(self, table: str, pkey_name: str, data): |
| 74 | logging.info(f"Upserting to {table} table: {data}") |
| 75 | table_url = ( |
| 76 | f"{self.supabase_url}/rest/v1/{table}?{pkey_name}=eq.{data.get(pkey_name)}" |
| 77 | ) |
| 78 | headers = { |
| 79 | "apiKey": self.supabase_key, |
| 80 | "Authorization": f"Bearer {self.supabase_key}", |
| 81 | "Prefer": "resolution=merge", |
| 82 | } |
| 83 | |
| 84 | async with httpx.AsyncClient() as async_client: |
| 85 | response = await async_client.put(table_url, json=data, headers=headers) |
| 86 | |
| 87 | if not response.is_success: |
| 88 | json = response.json() |
| 89 | raise RuntimeError( |
| 90 | f"Error upserting to {table=}. Postgres: {json['code']=}. {json['message']=}" |
| 91 | ) |
| 92 | |
| 93 | return response |
| 94 | |
| 95 | async def post_to_bucket( |
| 96 | self, bucket: str, session_id: str, image_bytes, filename: str |
no test coverage detected