次の方法で共有


Azure Functions 用の Azure Database for MySQL 入力バインド

関数を実行すると、Azure Database for MySQL 入力バインドはデータベースからデータを取得し、関数の入力パラメーターに渡します。

セットアップと構成の詳細については、 概要を参照してください。

重要

この記事では、タブを使用して、Node.js プログラミング モデルの複数のバージョンに対応しています。 v4 モデルは一般提供されており、JavaScript と TypeScript の開発者にとって、より柔軟で直感的なエクスペリエンスが得られるように設計されています。 v4 モデルの動作の詳細については、Azure Functions Node.js 開発者ガイドを参照してください。 v3 と v4 の違いの詳細については、移行ガイドを参照してください。

C# 関数は、次のいずれかの C# モードを使用して作成できます。

  • 分離されたワーカー モデル: ランタイムから分離されたワーカー プロセスで実行されるコンパイル済みの C# 関数。 .NET および .NET Framework の長期サポート (LTS) および LTS 以外のバージョンで実行されている C# 関数をサポートするには、分離ワーカー プロセスが必要です。
  • インプロセス モデル: Azure Functions ランタイムと同じプロセスで実行されるコンパイル済み C# 関数。
  • C# スクリプト: Azure portal で C# 関数を作成するときに主に使用されます。

Azure Database for MySQL 入力バインドのその他のサンプルは、 GitHub リポジトリで入手できます。

このセクションには、次の例が含まれています。

次の例では Product クラスとそれに対応するデータベース テーブルを参照します。

namespace AzureMySqlSamples.Common
{
    public class Product
    {
        public int? ProductId { get; set; }

        public string Name { get; set; }

        public int Cost { get; set; }

        public override bool Equals(object obj)
    }
}
DROP TABLE IF EXISTS Products;

CREATE TABLE Products (
  ProductId int PRIMARY KEY,
  Name varchar(100) NULL,
  Cost int NULL
);

HTTP トリガー、クエリ文字列から ID で行を取得する

次の例は、単一のレコードを取得する C# 関数を示しています。 この関数は、クエリ文字列を使用して ID を指定する HTTP 要求によってトリガーされます。 その ID は、指定されたクエリを使用して Product レコードを取得するために使用されます。

HTTP クエリ文字列パラメーターは大文字と小文字が区別されます。

using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.MySql;
using Microsoft.Azure.Functions.Worker.Http;
using AzureMySqlSamples.Common;

namespace AzureMySqlSamples.InputBindingIsolatedSamples
{
    public static class GetProductById
    {
        [Function(nameof(GetProductById))]
        public static IEnumerable<Product> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproducts/{productId}")]
            HttpRequestData req,
            [MySqlInput("select * from Products where ProductId = @productId",
                "MySqlConnectionString",
                parameters: "@ProductId={productId}")]
            IEnumerable<Product> products)
        {
            return products;
        }
    }
}

HTTP トリガー、ルート パラメーターから複数の行を取得する

次の例は、クエリが返した行を取得する C# 関数 を示しています。 この関数は、ルート データを使用してクエリ パラメーターの値を指定する HTTP 要求によってトリガーされます。 このパラメーターは、指定されたクエリ内の Product レコードをフィルター処理するために使用されます。

using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Extensions.MySql;
using Microsoft.Azure.Functions.Worker.Http;
using AzureMySqlSamples.Common;

namespace AzureMySqlSamples.InputBindingIsolatedSamples
{
    public static class GetProducts
    {
        [Function(nameof(GetProducts))]
        public static IEnumerable<Product> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproducts")]
            HttpRequestData req,
            [MySqlInput("select * from Products",
                "MySqlConnectionString")]
            IEnumerable<Product> products)
        {
            return products;
        }
    }
}

HTTP トリガー、行の削除

次の例は、HTTP 要求のクエリ パラメーターからの入力を使用してストアド プロシージャを実行する C# 関数 を示しています。

ストアド プロシージャ DeleteProductsCost は、MySQL データベースに作成する必要があります。 この例では、ストアド プロシージャは、パラメーターの値に応じて、1 つのレコードまたはすべてのレコードを削除します。

DROP PROCEDURE IF EXISTS DeleteProductsCost;

Create Procedure DeleteProductsCost(cost INT)
BEGIN
  DELETE from Products where Products.cost = cost;
END
namespace AzureMySqlSamples.InputBindingSamples
{
    public static class GetProductsStoredProcedure
    {
        [FunctionName(nameof(GetProductsStoredProcedure))]
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproducts-storedprocedure/{cost}")]
            HttpRequest req,
            [MySql("DeleteProductsCost",
                "MySqlConnectionString",
                commandType: System.Data.CommandType.StoredProcedure,
                parameters: "@Cost={cost}")]
            IEnumerable<Product> products)
        {
            return new OkObjectResult(products);
        }
    }
}

Azure Database for MySQL 入力バインドのその他のサンプルは、 GitHub リポジトリで入手できます。

このセクションには、次の例が含まれています。

次の例では Product クラスとそれに対応するデータベース テーブルを参照します。

package com.function.Common;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Product {
    @JsonProperty("ProductId")
    private int ProductId;
    @JsonProperty("Name")
    private String Name;
    @JsonProperty("Cost")
    private int Cost;

    public Product() {
    }
DROP TABLE IF EXISTS Products;

CREATE TABLE Products (
  ProductId int PRIMARY KEY,
  Name varchar(100) NULL,
  Cost int NULL
);

HTTP トリガー、複数の行の取得

次の例は、 HTTP 要求がトリガーする Java 関数の Azure Database for MySQL 入力バインドを示しています。 バインドはクエリから読み取り、HTTP 応答で結果を返します。

package com.function;

import com.function.Common.Product;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.HttpRequestMessage;
import com.microsoft.azure.functions.HttpResponseMessage;
import com.microsoft.azure.functions.HttpStatus;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;
import com.microsoft.azure.functions.mysql.annotation.CommandType;
import com.microsoft.azure.functions.mysql.annotation.MySqlInput;

import java.util.Optional;

public class GetProducts {
    @FunctionName("GetProducts")
    public HttpResponseMessage run(
            @HttpTrigger(
                name = "req",
                methods = {HttpMethod.GET},
                authLevel = AuthorizationLevel.ANONYMOUS,
                route = "getproducts}")
                HttpRequestMessage<Optional<String>> request,
            @MySqlInput(
                name = "products",
                commandText = "SELECT * FROM Products",
                commandType = CommandType.Text,
                connectionStringSetting = "MySqlConnectionString")
                Product[] products) {

        return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(products).build();
    }
}

HTTP トリガー、クエリ文字列から ID で行を取得する

次の例は、 HTTP 要求がトリガーする Java 関数の Azure Database for MySQL 入力バインドを示しています。 バインドは、クエリ文字列からパラメーターでフィルター処理されたクエリから読み取り、HTTP 応答の行を返します。

public class GetProductById {
    @FunctionName("GetProductById")
    public HttpResponseMessage run(
            @HttpTrigger(
                name = "req",
                methods = {HttpMethod.GET},
                authLevel = AuthorizationLevel.ANONYMOUS,
                route = "getproducts/{productid}")
                HttpRequestMessage<Optional<String>> request,
            @MySqlInput(
                name = "products",
                commandText = "SELECT * FROM Products WHERE ProductId= @productId",
                commandType = CommandType.Text,
                parameters = "@productId={productid}",
                connectionStringSetting = "MySqlConnectionString")
                Product[] products) {

        return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(products).build();
    }
}

HTTP トリガー、行の削除

次の例は、 HTTP 要求がトリガーする Java 関数の Azure Database for MySQL 入力バインドを示しています。 バインドは、HTTP 要求のクエリ パラメーターからの入力を含むストアド プロシージャを実行します。

ストアド プロシージャ DeleteProductsCost は、データベースに作成する必要があります。 この例では、ストアド プロシージャは、パラメーターの値に応じて、1 つのレコードまたはすべてのレコードを削除します。

DROP PROCEDURE IF EXISTS DeleteProductsCost;

Create Procedure DeleteProductsCost(cost INT)
BEGIN
  DELETE from Products where Products.cost = cost;
END
public class DeleteProductsStoredProcedure {
    @FunctionName("DeleteProductsStoredProcedure")
    public HttpResponseMessage run(
            @HttpTrigger(
                name = "req",
                methods = {HttpMethod.GET},
                authLevel = AuthorizationLevel.ANONYMOUS,
                route = "Deleteproducts-storedprocedure/{cost}")
                HttpRequestMessage<Optional<String>> request,
            @MySqlInput(
                name = "products",
                commandText = "DeleteProductsCost",
                commandType = CommandType.StoredProcedure,
                parameters = "@Cost={cost}",
                connectionStringSetting = "MySqlConnectionString")
                Product[] products) {

        return request.createResponseBuilder(HttpStatus.OK).header("Content-Type", "application/json").body(products).build();
    }
}

Azure Database for MySQL 入力バインドのその他のサンプルは、 GitHub リポジトリで入手できます。

このセクションには、次の例が含まれています。

この例では、次のデータベース テーブルを参照します。

DROP TABLE IF EXISTS Products;

CREATE TABLE Products (
  ProductId int PRIMARY KEY,
  Name varchar(100) NULL,
  Cost int NULL
);

HTTP トリガー、複数の行の取得

次の例は、 HTTP 要求によってトリガーされる Azure Database for MySQL 入力バインドを示しています。 バインドはクエリから読み取り、HTTP 応答で結果を返します。

import { app, HttpRequest, HttpResponseInit, input, InvocationContext } from '@azure/functions';

const mysqlInput = input.generic({
    commandText: 'select * from Products',
    commandType: 'Text',
    connectionStringSetting: 'MySqlConnectionString',
});

export async function httpTrigger1(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
    context.log('HTTP trigger and MySQL input binding function processed a request.');
    const products = context.extraInputs.get(mysqlInput);
    return {
        jsonBody: products,
    };
}

app.http('httpTrigger1', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    extraInputs: [mysqlInput],
    handler: httpTrigger1,
});
const { app, input } = require('@azure/functions');

const mysqlInput = input.generic({
    type: 'mysql',
    commandText: 'select * from Products where Cost = @Cost',
    parameters: '@Cost={Cost}',
    commandType: 'Text',
    connectionStringSetting: 'MySqlConnectionString'
})

app.http('GetProducts', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    route: 'getproducts/{cost}',
    extraInputs: [mysqlInput],
    handler: async (request, context) => {
        const products = JSON.stringify(context.extraInputs.get(mysqlInput));

        return {
            status: 200,
            body: products
        };
    }
});

HTTP トリガー、クエリ文字列から ID で行を取得する

次の例は、 HTTP 要求によってトリガーされる Azure Database for MySQL 入力バインドを示しています。 バインドは、クエリ文字列からパラメーターでフィルター処理されたクエリから読み取り、HTTP 応答の行を返します。

import { app, HttpRequest, HttpResponseInit, input, InvocationContext } from '@azure/functions';

const mysqlInput = input.generic({
    commandText: 'select * from Products where ProductId= @productId',
    commandType: 'Text',
    parameters: '@productId={productid}',
    connectionStringSetting: 'MySqlConnectionString',
});

export async function httpTrigger1(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
    context.log('HTTP trigger and MySQL input binding function processed a request.');
    const products = context.extraInputs.get(mysqlInput);
    return {
        jsonBody: products,
    };
}

app.http('httpTrigger1', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    extraInputs: [mysqlInput],
    handler: httpTrigger1,
});
const { app, input } = require('@azure/functions');

const mysqlInput = input.generic({
    type: 'mysql',
    commandText: 'select * from Products where ProductId= @productId',
    commandType: 'Text',
    parameters: '@productId={productid}',
    connectionStringSetting: 'MySqlConnectionString'
})

app.http('GetProducts', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    route: 'getproducts/{productid}',
    extraInputs: [mysqlInput],
    handler: async (request, context) => {
        const products = JSON.stringify(context.extraInputs.get(mysqlInput));

        return {
            status: 200,
            body: products
        };
    }
});

HTTP トリガー、行の削除

次の例は、 HTTP 要求によってトリガーされる Azure Database for MySQL 入力バインドを示しています。 バインドは、HTTP 要求のクエリ パラメーターからの入力を含むストアド プロシージャを実行します。

ストアド プロシージャ DeleteProductsCost は、データベースに作成する必要があります。 この例では、ストアド プロシージャは、パラメーターの値に応じて、1 つのレコードまたはすべてのレコードを削除します。

DROP PROCEDURE IF EXISTS DeleteProductsCost;

Create Procedure DeleteProductsCost(cost INT)
BEGIN
  DELETE from Products where Products.cost = cost;
END
import { app, HttpRequest, HttpResponseInit, input, InvocationContext } from '@azure/functions';

const mysqlInput = input.generic({
    commandText: 'DeleteProductsCost',
    commandType: 'StoredProcedure',
    parameters: '@Cost={cost}',
    connectionStringSetting: 'MySqlConnectionString',
});

export async function httpTrigger1(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
    context.log('HTTP trigger and MySQL input binding function processed a request.');
    const products = context.extraInputs.get(mysqlInput);
    return {
        jsonBody: products,
    };
}

app.http('httpTrigger1', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    extraInputs: [mysqlInput],
    handler: httpTrigger1,
});
const { app, input } = require('@azure/functions');

const mysqlInput = input.generic({
    type: 'mysql',
    commandText: 'DeleteProductsCost',
    commandType: 'StoredProcedure',
    parameters: '@Cost={cost}',
    connectionStringSetting: 'MySqlConnectionString'
})

app.http('httpTrigger1', {
    methods: ['POST'],
    authLevel: 'anonymous',
    route: 'DeleteProductsByCost',
    extraInputs: [mysqlInput],
    handler: async (request, context) => {
        const products = JSON.stringify(context.extraInputs.get(mysqlInput));

        return {
            status: 200,
            body: products
        };
    }
});

Azure Database for MySQL 入力バインドのその他のサンプルは、 GitHub リポジトリで入手できます。

このセクションには、次の例が含まれています。

この例では、次のデータベース テーブルを参照します。

DROP TABLE IF EXISTS Products;

CREATE TABLE Products (
  ProductId int PRIMARY KEY,
  Name varchar(100) NULL,
  Cost int NULL
);

HTTP トリガー、複数の行の取得

次の例は、function.json ファイル内の Azure Database for MySQL 入力バインドと、 HTTP 要求がトリガーする PowerShell 関数を示しています。 バインドはクエリから読み取り、HTTP 応答で結果を返します。

function.json ファイルのバインド データの例を次に示します。

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "Request",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get"
      ],
      "route": "getproducts/{cost}"
    },
    {
      "name": "response",
      "type": "http",
      "direction": "out"
    },
    {
      "name": "products",
      "type": "mysql",
      "direction": "in",
      "commandText": "select * from Products",
      "commandType": "Text",
      "connectionStringSetting": "MySqlConnectionString"
    }
  ],
  "disabled": false
}

[構成] セクションでは、これらのプロパティについて説明します。

次の例は、run.ps1 ファイル内の関数の PowerShell コードの例です。

using namespace System.Net

param($Request, $TriggerMetadata, $products)

Write-Host "PowerShell function with MySql Input Binding processed a request."

Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
    StatusCode = [System.Net.HttpStatusCode]::OK
    Body = $products
})

HTTP トリガー、クエリ文字列から ID で行を取得する

次の例は、 HTTP 要求がトリガーする PowerShell 関数の Azure Database for MySQL 入力バインドを示しています。 バインドは、クエリ文字列からパラメーターでフィルター処理されたクエリから読み取り、HTTP 応答の行を返します。

function.json ファイルのバインド データの例を次に示します。

{
  "bindings": [
    {
      "authLevel": "function",
      "name": "Request",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get"
      ],
      "route": "getproducts/{productid}"
    },
    {
      "name": "response",
      "type": "http",
      "direction": "out"
    },
    {
      "name": "products",
      "type": "mysql",
      "direction": "in",
      "commandText": "select * from Products where ProductId= @productId",
      "commandType": "Text",
      "parameters": "MySqlConnectionString",
      "connectionStringSetting": "MySqlConnectionString"
    }
  ],
  "disabled": false
}

[構成] セクションでは、これらのプロパティについて説明します。

次の例は、run.ps1 ファイル内の関数の PowerShell コードの例です。

using namespace System.Net

param($Request, $TriggerMetadata, $products)

Write-Host "PowerShell function with MySql Input Binding processed a request."

Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
    StatusCode = [System.Net.HttpStatusCode]::OK
    Body = $products
})

HTTP トリガー、行の削除

次の例は、function.json ファイル内の Azure Database for MySQL 入力バインドと、 HTTP 要求がトリガーする PowerShell 関数を示しています。 バインドは、HTTP 要求のクエリ パラメーターからの入力を含むストアド プロシージャを実行します。

ストアド プロシージャ DeleteProductsCost は、データベースに作成する必要があります。 この例では、ストアド プロシージャは、パラメーターの値に応じて、1 つのレコードまたはすべてのレコードを削除します。

DROP PROCEDURE IF EXISTS DeleteProductsCost;

Create Procedure DeleteProductsCost(cost INT)
BEGIN
  DELETE from Products where Products.cost = 'cost';
END
{
  "bindings": [
    {
      "authLevel": "function",
      "name": "Request",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get"
      ],
      "route": "deleteproducts-storedprocedure/{cost}"
    },
    {
      "name": "response",
      "type": "http",
      "direction": "out"
    },
    {
      "name": "products",
      "type": "mysql",
      "direction": "in",
      "commandText": "DeleteProductsCost",
      "commandType": "StoredProcedure",
      "parameters": "@Cost={cost}",
      "connectionStringSetting": "MySqlConnectionString"
    }
  ],
  "disabled": false
}

[構成] セクションでは、これらのプロパティについて説明します。

次の例は、run.ps1 ファイル内の関数の PowerShell コードの例です。

using namespace System.Net

param($Request, $TriggerMetadata, $products)

Write-Host "PowerShell function with MySql Input Binding processed a request."

Push-OutputBinding -Name response -Value ([HttpResponseContext]@{
    StatusCode = [System.Net.HttpStatusCode]::OK
    Body = $products
}

Azure Database for MySQL 入力バインドのその他のサンプルは、 GitHub リポジトリで入手できます。

このセクションには、次の例が含まれています。

この例では、次のデータベース テーブルを参照します。

DROP TABLE IF EXISTS Products;

CREATE TABLE Products (
  ProductId int PRIMARY KEY,
  Name varchar(100) NULL,
  Cost int NULL
);

Azure Functions バージョン 1.22.0b4 for Python を使用する必要があります。

HTTP トリガー、複数の行の取得

次の例は、function.json ファイル内の Azure Database for MySQL 入力バインドと、 HTTP 要求によってトリガーされる Python 関数を示しています。 バインドはクエリから読み取り、HTTP 応答で結果を返します。

次の例は、function_app.py ファイルのサンプル Python コードです。

import azure.functions as func
import datetime
import json
import logging

app = func.FunctionApp()


@app.generic_trigger(arg_name="req", type="httpTrigger", route="getproducts/{cost}")
@app.generic_output_binding(arg_name="$return", type="http")
@app.generic_input_binding(arg_name="products", type="mysql",
                           commandText= "select * from Products",
                           command_type="Text",
                           connection_string_setting="MySqlConnectionString")
def mysql_test(req: func.HttpRequest, products: func.MySqlRowList) -> func.HttpResponse:
    rows = list(map(lambda r: json.loads(r.to_json()), products))

    return func.HttpResponse(
        json.dumps(rows),
        status_code=200,
        mimetype="application/json"
    )

HTTP トリガー、クエリ文字列から ID で行を取得する

次の例は、 HTTP 要求がトリガーする Python 関数の Azure Database for MySQL 入力バインドを示しています。 バインドは、クエリ文字列からパラメーターでフィルター処理されたクエリから読み取り、HTTP 応答の行を返します。

次の例は、function_app.py ファイルのサンプル Python コードです。

import azure.functions as func
import datetime
import json
import logging

app = func.FunctionApp()


@app.generic_trigger(arg_name="req", type="httpTrigger", route="getproducts/{cost}")
@app.generic_output_binding(arg_name="$return", type="http")
@app.generic_input_binding(arg_name="products", type="mysql",
                           commandText= "select * from Products where ProductId= @productId",
                           command_type="Text",
                           parameters= "@productId={productid}",
                           connection_string_setting="MySqlConnectionString")
def mysql_test(req: func.HttpRequest, products: func.MySqlRowList) -> func.HttpResponse:
    rows = list(map(lambda r: json.loads(r.to_json()), products))

    return func.HttpResponse(
        json.dumps(rows),
        status_code=200,
        mimetype="application/json"
    )

HTTP トリガー、行の削除

次の例は、function.json ファイル内の Azure Database for MySQL 入力バインドと、 HTTP 要求によってトリガーされる Python 関数を示しています。 バインドは、HTTP 要求のクエリ パラメーターからの入力を含むストアド プロシージャを実行します。

ストアド プロシージャ DeleteProductsCost は、データベースに作成する必要があります。 この例では、ストアド プロシージャは、パラメーターの値に応じて、1 つのレコードまたはすべてのレコードを削除します。

DROP PROCEDURE IF EXISTS DeleteProductsCost;

Create Procedure DeleteProductsCost(cost INT)
BEGIN
  DELETE from Products where Products.cost = cost;
END

次の例は、function_app.py ファイルのサンプル Python コードです。

import azure.functions as func
import datetime
import json
import logging

app = func.FunctionApp()


@app.generic_trigger(arg_name="req", type="httpTrigger", route="getproducts/{cost}")
@app.generic_output_binding(arg_name="$return", type="http")
@app.generic_input_binding(arg_name="products", type="mysql",
                           commandText= "DeleteProductsCost",
                           command_type="StoredProcedure",
                           parameters= "@Cost={cost}",
                           connection_string_setting="MySqlConnectionString")
def mysql_test(req: func.HttpRequest, products: func.MySqlRowList) -> func.HttpResponse:
    rows = list(map(lambda r: json.loads(r.to_json()), products))

    return func.HttpResponse(
        json.dumps(rows),
        status_code=200,
        mimetype="application/json"
    )

属性

C# ライブラリでは、MySqlAttribute属性を使用して、関数で MySQL バインドを宣言します。 この属性には、次のプロパティがあります。

属性のプロパティ 説明
CommandText 必須。 バインドが実行される MySQL クエリ コマンドまたはストアド プロシージャの名前。
ConnectionStringSetting 必須。 クエリまたはストアド プロシージャが実行されるデータベースの接続文字列を含むアプリ設定の名前。 この値は実際の接続文字列ではなく、代わりに環境変数名に解決される必要があります。
CommandType 必須。 CommandType値。ストアド プロシージャのクエリとTextStoredProcedureされます。
Parameters 省略可能。 実行時に 1 つの文字列としてコマンドに渡される 0 個以上のパラメーター値。 @param1=param1,@param2=param2 という形式に従う必要があります。 パラメーター名とパラメーター値にコンマ (,) または等号 (=) を含めることはできません。

注釈

Java 関数ランタイム ライブラリで、値が Azure Database for MySQL から取得されるパラメーターに対して@MySQLInput注釈を使用します。 この注釈は、次の要素をサポートします。

要素 説明
commandText 必須。 バインドが実行される MySQL クエリ コマンドまたはストアド プロシージャの名前。
connectionStringSetting 必須。 クエリまたはストアド プロシージャが実行されるデータベースの接続文字列を含むアプリ設定の名前。 この値は実際の接続文字列ではなく、代わりに環境変数名に解決される必要があります。
commandType 必須。 CommandType値。ストアド プロシージャのクエリとTextStoredProcedureされます。
name 必須。 関数バインドの一意の名前。
parameters 省略可能。 実行時に 1 つの文字列としてコマンドに渡される 0 個以上のパラメーター値。 @param1=param1,@param2=param2 という形式に従う必要があります。 パラメーター名とパラメーター値にコンマ (,) または等号 (=) を含めることはできません。

構成

次の表では、options メソッドに渡されるinput.generic() オブジェクトに設定できるプロパティについて説明します。

プロパティ 説明
commandText 必須。 バインドが実行される MySQL クエリ コマンドまたはストアド プロシージャの名前。
connectionStringSetting 必須。 クエリまたはストアド プロシージャが実行されるデータベースの接続文字列を含むアプリ設定の名前。 この値は実際の接続文字列ではなく、代わりに環境変数名に解決される必要があります。 接続文字列値の省略可能なキーワードは MySQL バインドの接続を調整するために使用できます
commandType 必須。 CommandType値。ストアド プロシージャのクエリとTextStoredProcedureされます。
parameters 省略可能。 実行時に 1 つの文字列としてコマンドに渡される 0 個以上のパラメーター値。 @param1=param1,@param2=param2 という形式に従う必要があります。 パラメーター名とパラメーター値にコンマ (,) または等号 (=) を含めることはできません。

構成

次の表では、function.json ファイルで設定するバインド構成プロパティについて説明します。

プロパティ 説明
type 必須。 mysql に設定する必要があります。
direction 必須。 in に設定する必要があります。
name 必須。 関数コード内のクエリ結果を表す変数の名前。
commandText 必須。 バインドが実行される MySQL クエリ コマンドまたはストアド プロシージャの名前。
connectionStringSetting 必須。 クエリまたはストアド プロシージャが実行されるデータベースの接続文字列を含むアプリ設定の名前。 この値は実際の接続文字列ではなく、代わりに環境変数名に解決される必要があります。 接続文字列値の省略可能なキーワードは MySQL バインドの接続を調整するために使用できます
commandType 必須。 CommandType値。ストアド プロシージャのクエリとTextStoredProcedureされます。
parameters 省略可能。 実行時に 1 つの文字列としてコマンドに渡される 0 個以上のパラメーター値。 @param1=param1,@param2=param2 という形式に従う必要があります。 パラメーター名とパラメーター値にコンマ (,) または等号 (=) を含めることはできません。

ローカルで開発する場合は、 コレクション内の Valuesにアプリケーション設定を追加します。

使用方法

属性のコンストラクターは、MySQL コマンド テキスト、コマンドの種類、パラメーター、接続文字列設定の名前を受け取ります。 コマンドには、コマンドの種類が System.Data.CommandType.Text の MySQL クエリ、またはコマンドの種類が System.Data.CommandType.StoredProcedureストアド プロシージャ名を指定できます。 接続文字列設定の名前は、Azure Database for MySQL への 接続文字列 を含むアプリケーション設定 (ローカル開発用の local.settings.json) に対応します。

Azure Database for MySQL 入力バインドの実行時に例外が発生すると、関数コードの実行が停止します。 結果は、500 エラー コードを返す HTTP トリガーなどのエラー コードである可能性があります。