diff --git a/src/app.ts b/src/app.ts index 7a882a8..e9239ff 100644 --- a/src/app.ts +++ b/src/app.ts @@ -11,6 +11,7 @@ import { HttpHandler, HttpMethod, HttpMethodFunctionOptions, + MySqlFunctionOptions, ServiceBusQueueFunctionOptions, ServiceBusTopicFunctionOptions, SqlFunctionOptions, @@ -135,6 +136,10 @@ export function sql(name: string, options: SqlFunctionOptions): void { generic(name, convertToGenericOptions(options, trigger.sql)); } +export function mySql(name: string, options: MySqlFunctionOptions): void { + generic(name, convertToGenericOptions(options, trigger.mySql)); +} + export function generic(name: string, options: GenericFunctionOptions): void { if (!hasSetModel) { setProgrammingModel(); diff --git a/src/index.ts b/src/index.ts index 496121e..d3e2911 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,3 +22,7 @@ export enum SqlChangeOperation { Update = 1, Delete = 2, } + +export enum MySqlChangeOperation { + Update = 0, +} diff --git a/src/input.ts b/src/input.ts index 087315a..0298f71 100644 --- a/src/input.ts +++ b/src/input.ts @@ -6,6 +6,8 @@ import { CosmosDBInputOptions, FunctionInput, GenericInputOptions, + MySqlInput, + MySqlInputOptions, SqlInput, SqlInputOptions, StorageBlobInput, @@ -43,6 +45,13 @@ export function sql(options: SqlInputOptions): SqlInput { }); } +export function mySql(options: MySqlInputOptions): MySqlInput { + return addInputBindingName({ + ...options, + type: 'mysql', + }); +} + export function generic(options: GenericInputOptions): FunctionInput { return addInputBindingName(options); } diff --git a/src/output.ts b/src/output.ts index 878ff09..a9d9e5b 100644 --- a/src/output.ts +++ b/src/output.ts @@ -12,6 +12,8 @@ import { GenericOutputOptions, HttpOutput, HttpOutputOptions, + MySqlOutput, + MySqlOutputOptions, ServiceBusQueueOutput, ServiceBusQueueOutputOptions, ServiceBusTopicOutput, @@ -97,6 +99,13 @@ export function sql(options: SqlOutputOptions): SqlOutput { }); } +export function mySql(options: MySqlOutputOptions): MySqlOutput { + return addOutputBindingName({ + ...options, + type: 'mysql', + }); +} + export function generic(options: GenericOutputOptions): FunctionOutput { return addOutputBindingName(options); } diff --git a/src/trigger.ts b/src/trigger.ts index a7fc629..78ed5b2 100644 --- a/src/trigger.ts +++ b/src/trigger.ts @@ -12,6 +12,8 @@ import { GenericTriggerOptions, HttpTrigger, HttpTriggerOptions, + MySqlTrigger, + MySqlTriggerOptions, ServiceBusQueueTrigger, ServiceBusQueueTriggerOptions, ServiceBusTopicTrigger, @@ -108,6 +110,13 @@ export function sql(options: SqlTriggerOptions): SqlTrigger { }); } +export function mySql(options: MySqlTriggerOptions): MySqlTrigger { + return addTriggerBindingName({ + ...options, + type: 'mysqlTrigger', + }); +} + export function generic(options: GenericTriggerOptions): FunctionTrigger { return addTriggerBindingName(options); } diff --git a/types/InvocationContext.d.ts b/types/InvocationContext.d.ts index cbd6e40..a0f42e8 100644 --- a/types/InvocationContext.d.ts +++ b/types/InvocationContext.d.ts @@ -6,6 +6,7 @@ import { EventGridOutput, EventGridPartialEvent } from './eventGrid'; import { EventHubOutput } from './eventHub'; import { HttpOutput, HttpResponse } from './http'; import { FunctionInput, FunctionOutput, FunctionTrigger, LogLevel } from './index'; +import { MySqlInput, MySqlOutput } from './mySql'; import { ServiceBusQueueOutput, ServiceBusTopicOutput } from './serviceBus'; import { SqlInput, SqlOutput } from './sql'; import { StorageBlobInput, StorageBlobOutput, StorageQueueOutput } from './storage'; @@ -127,6 +128,12 @@ export interface InvocationContextExtraInputs { * @input the configuration object for this SQL input */ get(input: SqlInput): unknown; + + /** + * Get a secondary MySql items input for this invocation + * @input the configuration object for this MySql input + */ + get(input: MySqlInput): unknown; /** * Get a secondary generic input for this invocation @@ -215,6 +222,13 @@ export interface InvocationContextExtraOutputs { * @message the output event(s) value */ set(output: EventGridOutput, events: EventGridPartialEvent | EventGridPartialEvent[]): void; + + /** + * Set a secondary MySql items output for this invocation + * @output the configuration object for this MySql output + * @documents the output item(s) value + */ + set(output: MySqlOutput, items: unknown): void; /** * Set a secondary generic output for this invocation diff --git a/types/app.d.ts b/types/app.d.ts index c2f7608..2632304 100644 --- a/types/app.d.ts +++ b/types/app.d.ts @@ -6,6 +6,7 @@ import { EventGridFunctionOptions } from './eventGrid'; import { EventHubFunctionOptions } from './eventHub'; import { GenericFunctionOptions } from './generic'; import { HttpFunctionOptions, HttpHandler, HttpMethodFunctionOptions } from './http'; +import { MySqlFunctionOptions } from './mySql'; import { ServiceBusQueueFunctionOptions, ServiceBusTopicFunctionOptions } from './serviceBus'; import { SetupOptions } from './setup'; import { SqlFunctionOptions } from './sql'; @@ -172,6 +173,13 @@ export function warmup(name: string, options: WarmupFunctionOptions): void; */ export function sql(name: string, options: SqlFunctionOptions): void; +/** + * Registers a MySql function in your app that will be triggered when a row is created or updated + * @param name The name of the function. The name must be unique within your app and will mostly be used for your own tracking purposes + * @param options Configuration options describing the inputs, outputs, and handler for this function + */ +export function mySql(name: string, options: MySqlFunctionOptions): void; + /** * Registers a generic function in your app that will be triggered based on the type specified in `options.trigger.type` * Use this method if your desired trigger type does not already have its own method diff --git a/types/index.d.ts b/types/index.d.ts index 84a03eb..d17617a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -17,6 +17,7 @@ export * from './hooks/logHooks'; export * from './http'; export * as input from './input'; export * from './InvocationContext'; +export * from './mySql'; export * as output from './output'; export * from './serviceBus'; export * from './setup'; diff --git a/types/input.d.ts b/types/input.d.ts index 54c0ea8..09e11f9 100644 --- a/types/input.d.ts +++ b/types/input.d.ts @@ -7,6 +7,7 @@ import { FunctionInput } from './index'; import { SqlInput, SqlInputOptions } from './sql'; import { StorageBlobInput, StorageBlobInputOptions } from './storage'; import { TableInput, TableInputOptions } from './table'; +import { MySqlInput, MySqlInputOptions } from './mySql'; /** * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-storage-blob-input?pivots=programming-language-javascript) @@ -28,6 +29,11 @@ export function cosmosDB(options: CosmosDBInputOptions): CosmosDBInput; */ export function sql(options: SqlInputOptions): SqlInput; +/** + * [Link to docs and examples](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-azure-mysql-input?pivots=programming-language-javascript) + */ +export function mySql(options: MySqlInputOptions): MySqlInput; + /** * A generic option that can be used for any input type * Use this method if your desired input type does not already have its own method diff --git a/types/mySql.d.ts b/types/mySql.d.ts new file mode 100644 index 0000000..82eb69d --- /dev/null +++ b/types/mySql.d.ts @@ -0,0 +1,73 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index'; +import { InvocationContext } from './InvocationContext'; + +export type MySqlHandler = (changes: MySqlChange[], context: InvocationContext) => FunctionResult; + +export interface MySqlFunctionOptions extends MySqlTriggerOptions, Partial { + handler: MySqlHandler; + + trigger?: MySqlTrigger; +} + +export interface MySqlTriggerOptions { + /** + * The name of the table monitored by the trigger. + */ + tableName: string; + + /** + * An app setting (or environment variable) with the connection string for the database containing the table monitored for changes + */ + connectionStringSetting: string; +} +export type MySqlTrigger = FunctionTrigger & MySqlTriggerOptions; + +export interface MySqlChange { + Item: unknown; + Operation: MySqlChangeOperation; +} + +export enum MySqlChangeOperation { + Update = 0, +} + +export interface MySqlInputOptions { + /** + * The Transact-SQL query command or name of the stored procedure executed by the binding. + */ + commandText: string; + + /** + * The command type value + */ + commandType: 'Text' | 'StoredProcedure'; + + /** + * An app setting (or environment variable) with the connection string for the database against which the query or stored procedure is being executed + */ + connectionStringSetting: string; + + /** + * Zero or more parameter values passed to the command during execution as a single string. + * Must follow the format @param1=param1,@param2=param2. + * Neither the parameter name nor the parameter value can contain a comma (,) or an equals sign (=). + */ + parameters?: string; +} +export type MySqlInput = FunctionInput & MySqlInputOptions; + +export interface MySqlOutputOptions { + /** + * The name of the table being written to by the binding. + */ + commandText: string; + + /** + * An app setting (or environment variable) with the connection string for the database to which data is being written + */ + connectionStringSetting: string; +} +export type MySqlOutput = FunctionOutput & MySqlOutputOptions; diff --git a/types/output.d.ts b/types/output.d.ts index 7dab65f..89878b6 100644 --- a/types/output.d.ts +++ b/types/output.d.ts @@ -16,6 +16,7 @@ import { import { SqlOutput, SqlOutputOptions } from './sql'; import { StorageBlobOutput, StorageBlobOutputOptions, StorageQueueOutput, StorageQueueOutputOptions } from './storage'; import { TableOutput, TableOutputOptions } from './table'; +import { MySqlOutput, MySqlOutputOptions } from './mySql'; /** * [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-output?&pivots=programming-language-javascript) @@ -67,6 +68,11 @@ export function cosmosDB(options: CosmosDBOutputOptions): CosmosDBOutput; */ export function sql(options: SqlOutputOptions): SqlOutput; +/** + * [Link to docs and examples](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-azure-mysql-output?pivots=programming-language-javascript) + */ +export function mySql(options: MySqlOutputOptions): MySqlOutput; + /** * A generic option that can be used for any output type * Use this method if your desired output type does not already have its own method diff --git a/types/trigger.d.ts b/types/trigger.d.ts index 864479a..e6d8d74 100644 --- a/types/trigger.d.ts +++ b/types/trigger.d.ts @@ -7,6 +7,7 @@ import { EventHubTrigger, EventHubTriggerOptions } from './eventHub'; import { GenericTriggerOptions } from './generic'; import { HttpTrigger, HttpTriggerOptions } from './http'; import { FunctionTrigger } from './index'; +import { MySqlTrigger, MySqlTriggerOptions } from './mySql'; import { ServiceBusQueueTrigger, ServiceBusQueueTriggerOptions, @@ -78,6 +79,11 @@ export function warmup(options: WarmupTriggerOptions): WarmupTrigger; */ export function sql(options: SqlTriggerOptions): SqlTrigger; +/** + * [Link to docs and examples](To be updated) + */ +export function mySql(options: MySqlTriggerOptions): MySqlTrigger; + /** * A generic option that can be used for any trigger type * Use this method if your desired trigger type does not already have its own method