Giter VIP home page Giter VIP logo

sqltriggerfa's Introduction

SQLTriggerFA

Example of SQL Trigger Function App and example showing scaling performance on Consumption App Service Plan

The SQL Trigger for the Function App for this Function App looks like this

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "SqlConnectionString": "Server=tcp:myDatabaseServer.database.windows.net,1433;Initial Catalog=myDatabase;Persist Security Info=False;User ID=casecountuser;Password={password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
  }
}
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Microsoft.Azure.WebJobs.Extensions.Sql;
using System.Collections.Generic;

namespace SQLTriggerFA
{
    public static class SQLTrigger
    {
        [FunctionName("ToDoTrigger")]
        public static async Task Run(
            [SqlTrigger("[dbo].[ToDo]", ConnectionStringSetting = "SqlConnectionString")]
            IReadOnlyList<SqlChange<ToDoItem>> changes,
            ILogger logger,
            [Sql("dbo.ToDo", ConnectionStringSetting = "SqlConnectionString")] IAsyncCollector<ToDoItem> toDoItems)
        {
            foreach (SqlChange<ToDoItem> change in changes)
            {
                ToDoItem toDoItem = change.Item;
                logger.LogInformation($"Change operation: {change.Operation}");
                logger.LogInformation($"Id: {toDoItem.Id}, Title: {toDoItem.title}, Url: {toDoItem.url}, Completed: {toDoItem.completed}");
            }

            // List of ToDoItems to be inserted into the ToDo table
            List<ToDoItem> toDoItemsList = new List<ToDoItem>();

            for (int i = 0; i < 10; i++)
            {
                // Add a new ToDoItem to the list
                toDoItemsList.Add(new ToDoItem
                {
                    Id = Guid.NewGuid(),
                    title = "New ToDoItem",
                    url = "https://www.microsoft.com",
                    completed = false
                });
            }

            // Add new ToDo Class to the SQL Table
            foreach (ToDoItem toDoItem in toDoItemsList)
            {
                await toDoItems.AddAsync(toDoItem);
            }

            await toDoItems.FlushAsync();
        }
    }
}

These scenarios allow you to build event-driven systems using modern architectural patterns.

As you build your functions, you have the following options and resources available:

sqltriggerfa's People

Contributors

macavall avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.