libere-tes-chaine-de-mots/import_data/utils/documents_to_database.py
2024-10-02 21:53:37 -04:00

11 lines
No EOL
434 B
Python

import tqdm
from .typesense_client import client
def documents_to_database(documents_list, os_client=client):
try:
for document in tqdm.tqdm(documents_list.to_dict(orient='records')):
os_client.collections['social_media_posts'].documents.create(document)
print(f"Successfully inserted {len(documents_list)} documents.")
except Exception as e:
print(f"Error inserting documents: {str(e)}")