update firestore to FieldFilter
This commit is contained in:
@@ -2,6 +2,7 @@ import asyncio
|
|||||||
from typing import Optional, Any
|
from typing import Optional, Any
|
||||||
import firebase_admin
|
import firebase_admin
|
||||||
from firebase_admin import credentials, firestore as fs
|
from firebase_admin import credentials, firestore as fs
|
||||||
|
from google.cloud.firestore_v1.base_query import FieldFilter
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
from app.internal.logger import logger
|
from app.internal.logger import logger
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ async def collection_list(collection: str, **filters) -> list[dict]:
|
|||||||
def _query():
|
def _query():
|
||||||
ref = db.collection(collection)
|
ref = db.collection(collection)
|
||||||
for field, value in filters.items():
|
for field, value in filters.items():
|
||||||
ref = ref.where(field, "==", value)
|
ref = ref.where(filter=FieldFilter(field, "==", value))
|
||||||
return [doc.to_dict() for doc in ref.stream()]
|
return [doc.to_dict() for doc in ref.stream()]
|
||||||
|
|
||||||
return await asyncio.to_thread(_query)
|
return await asyncio.to_thread(_query)
|
||||||
@@ -69,7 +70,7 @@ async def collection_where(
|
|||||||
def _query():
|
def _query():
|
||||||
ref = db.collection(collection)
|
ref = db.collection(collection)
|
||||||
for field, op, value in conditions:
|
for field, op, value in conditions:
|
||||||
ref = ref.where(field, op, value)
|
ref = ref.where(filter=FieldFilter(field, op, value))
|
||||||
return [doc.to_dict() for doc in ref.stream()]
|
return [doc.to_dict() for doc in ref.stream()]
|
||||||
|
|
||||||
return await asyncio.to_thread(_query)
|
return await asyncio.to_thread(_query)
|
||||||
|
|||||||
Reference in New Issue
Block a user