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)}")