forked from JocaPC/sql-server-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathODataResult.cs
32 lines (30 loc) · 1.08 KB
/
ODataResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using MsSql.RestApi;
using System;
using System.Threading.Tasks;
namespace TestFunction
{
public static class ODataResult
{
[FunctionName("ODataResult")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
try
{
var tableSpec = new TableSpec(schema: "sys", table: "objects", columns: "object_id,name,type,schema_id,create_date");
return await req.OData(tableSpec).GetResult(Environment.GetEnvironmentVariable("SqlDb"));
}
catch (Exception ex)
{
log.LogError($"C# Http trigger function exception: {ex.Message}");
return new StatusCodeResult(500);
}
}
}
}