Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jandev/azurefunctions-sqlbinding

A lightweight project with a MS SQL Server binding for Azure Functions
https://github.com/jandev/azurefunctions-sqlbinding

azure azure-functions sql-server

Last synced: 17 days ago
JSON representation

A lightweight project with a MS SQL Server binding for Azure Functions

Awesome Lists containing this project

README

        

# Overview

This project is created to provide a simple
Microsoft SQL Server binding for Azure Functions.

# Supported features

The following commands are supported as of now.

## Input binding

The input binding can be used as like the following
piece of code.

```csharp
[FunctionName(nameof(GetSingleRecord))]
public static IActionResult GetSingleRecord(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = nameof(GetSingleRecord))]
HttpRequest req,
[SqlServer(Query = "SELECT TOP 1 Id, Name, Description FROM MyTable")]
SqlServerModel model)
{
return new OkObjectResult(model.Record.Id);
}

[FunctionName(nameof(GetCollectionFromSqlServer))]
public static IActionResult GetCollectionFromSqlServer(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = nameof(GetCollectionFromSqlServer))]
HttpRequest req,
[SqlServer(Query = "SELECT TOP 100 Id, Name, Description FROM MyTable")]
IEnumerable collection)
{
return new OkObjectResult(collection.Select(m => m.Record.Id));
}
```

In order for this to work you need a `local.settings.json`
file with a proper connectionstring. If not specified
the default name `SqlServerConnectionString` will be used.

```json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
},
"ConnectionStrings": {
"SqlServerConnectionString": "Server=(localdb)\\myInstance;Database=MySqlBindingDatabase;Trusted_Connection=True",
"providerName": "System.Data.SqlClient"
}
}
```