| 52 | return response.status_code == 204 |
| 53 | |
| 54 | async def insert(self, table: str, data): |
| 55 | logging.info(f"Inserting to {table} table: {data}") |
| 56 | table_url = f"{self.supabase_url}/rest/v1/{table}" |
| 57 | headers = { |
| 58 | "apiKey": self.supabase_key, |
| 59 | "Authorization": f"Bearer {self.supabase_key}", |
| 60 | } |
| 61 | |
| 62 | async with httpx.AsyncClient() as async_client: |
| 63 | response = await async_client.post(table_url, json=data, headers=headers) |
| 64 | |
| 65 | if not response.is_success: |
| 66 | json = response.json() |
| 67 | raise RuntimeError( |
| 68 | f"Error inserting to {table=}. Postgres: {json['code']=}. {json['message']=}" |
| 69 | ) |
| 70 | |
| 71 | return response |
| 72 | |
| 73 | async def upsert(self, table: str, pkey_name: str, data): |
| 74 | logging.info(f"Upserting to {table} table: {data}") |