How to bulk insert CSV from Azure Blob to Azure Sql using Azure Function v2 (python)

jim01011 0 Reputation points
2024-04-22T11:00:24.2666667+00:00

I have the following code below that inserts one line into an azure sql DB. How would I modify this code to bulk insert from Azure Blob (csvs) to Azure Sql using Azure Function v2 (python)?


import azure.functions as func
import logging
from azure.functions.decorators.core import DataType
import uuid

app = func.FunctionApp()

@app.function_name(name="HttpTrigger1")
@app.route(route="hello", auth_level=func.AuthLevel.ANONYMOUS)
@app.generic_output_binding(arg_name="toDoItems", type="sql", CommandText="dbo.ToDo", ConnectionStringSetting="SqlConnectionString",
    data_type=DataType.STRING)
def test_function(req: func.HttpRequest, toDoItems: func.Out[func.SqlRow]) -> func.HttpResponse:
        item_id = str(uuid.uuid4())  # Convert UUID to string
        toDoItems.set(func.SqlRow({"Id": item_id, "title": "name", "completed": False, "url": "www"}))
        return func.HttpResponse(f"Hello John") 
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,367 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,481 questions
{count} votes