Skip to content

Commit bf10422

Browse files
MySql Changes for JS (#319)
* mysql changes * fix indentation * fix indentation * fix indentation * fix indentation * Fix comment formatting in InvocationContext.d.ts * Update link to MySQL trigger documentation --------- Co-authored-by: hallvictoria <[email protected]>
1 parent 9259cfc commit bf10422

12 files changed

+151
-0
lines changed

src/app.ts

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
HttpHandler,
1212
HttpMethod,
1313
HttpMethodFunctionOptions,
14+
MySqlFunctionOptions,
1415
ServiceBusQueueFunctionOptions,
1516
ServiceBusTopicFunctionOptions,
1617
SqlFunctionOptions,
@@ -136,6 +137,10 @@ export function sql(name: string, options: SqlFunctionOptions): void {
136137
generic(name, convertToGenericOptions(options, trigger.sql));
137138
}
138139

140+
export function mySql(name: string, options: MySqlFunctionOptions): void {
141+
generic(name, convertToGenericOptions(options, trigger.mySql));
142+
}
143+
139144
export function webPubSub(name: string, options: WebPubSubFunctionOptions): void {
140145
generic(name, convertToGenericOptions(options, trigger.webPubSub));
141146
}

src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ export enum SqlChangeOperation {
2222
Update = 1,
2323
Delete = 2,
2424
}
25+
26+
export enum MySqlChangeOperation {
27+
Update = 0,
28+
}

src/input.ts

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
CosmosDBInputOptions,
77
FunctionInput,
88
GenericInputOptions,
9+
MySqlInput,
10+
MySqlInputOptions,
911
SqlInput,
1012
SqlInputOptions,
1113
StorageBlobInput,
@@ -47,6 +49,13 @@ export function sql(options: SqlInputOptions): SqlInput {
4749
});
4850
}
4951

52+
export function mySql(options: MySqlInputOptions): MySqlInput {
53+
return addInputBindingName({
54+
...options,
55+
type: 'mysql',
56+
});
57+
}
58+
5059
export function webPubSubConnection(options: WebPubSubConnectionInputOptions): WebPubSubConnectionInput {
5160
return addInputBindingName({
5261
...options,

src/output.ts

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
GenericOutputOptions,
1313
HttpOutput,
1414
HttpOutputOptions,
15+
MySqlOutput,
16+
MySqlOutputOptions,
1517
ServiceBusQueueOutput,
1618
ServiceBusQueueOutputOptions,
1719
ServiceBusTopicOutput,
@@ -99,6 +101,13 @@ export function sql(options: SqlOutputOptions): SqlOutput {
99101
});
100102
}
101103

104+
export function mySql(options: MySqlOutputOptions): MySqlOutput {
105+
return addOutputBindingName({
106+
...options,
107+
type: 'mysql',
108+
});
109+
}
110+
102111
export function webPubSub(options: WebPubSubOutputOptions): WebPubSubOutput {
103112
return addOutputBindingName({
104113
...options,

src/trigger.ts

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
GenericTriggerOptions,
1313
HttpTrigger,
1414
HttpTriggerOptions,
15+
MySqlTrigger,
16+
MySqlTriggerOptions,
1517
ServiceBusQueueTrigger,
1618
ServiceBusQueueTriggerOptions,
1719
ServiceBusTopicTrigger,
@@ -110,6 +112,13 @@ export function sql(options: SqlTriggerOptions): SqlTrigger {
110112
});
111113
}
112114

115+
export function mySql(options: MySqlTriggerOptions): MySqlTrigger {
116+
return addTriggerBindingName({
117+
...options,
118+
type: 'mysqlTrigger',
119+
});
120+
}
121+
113122
export function webPubSub(options: WebPubSubTriggerOptions): WebPubSubTrigger {
114123
return addTriggerBindingName({
115124
...options,

types/InvocationContext.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EventGridOutput, EventGridPartialEvent } from './eventGrid';
66
import { EventHubOutput } from './eventHub';
77
import { HttpOutput, HttpResponse } from './http';
88
import { FunctionInput, FunctionOutput, FunctionTrigger, LogLevel } from './index';
9+
import { MySqlInput, MySqlOutput } from './mySql';
910
import { ServiceBusQueueOutput, ServiceBusTopicOutput } from './serviceBus';
1011
import { SqlInput, SqlOutput } from './sql';
1112
import { StorageBlobInput, StorageBlobOutput, StorageQueueOutput } from './storage';
@@ -128,6 +129,12 @@ export interface InvocationContextExtraInputs {
128129
* @input the configuration object for this SQL input
129130
*/
130131
get(input: SqlInput): unknown;
132+
133+
/**
134+
* Get a secondary MySql items input for this invocation
135+
* @input the configuration object for this MySql input
136+
*/
137+
get(input: MySqlInput): unknown;
131138

132139
/**
133140
* Get a secondary generic input for this invocation
@@ -216,6 +223,13 @@ export interface InvocationContextExtraOutputs {
216223
* @message the output event(s) value
217224
*/
218225
set(output: EventGridOutput, events: EventGridPartialEvent | EventGridPartialEvent[]): void;
226+
227+
/**
228+
* Set a secondary MySql items output for this invocation
229+
* @output the configuration object for this MySql output
230+
* @documents the output item(s) value
231+
*/
232+
set(output: MySqlOutput, items: unknown): void;
219233

220234
/**
221235
* Set a secondary Web PubSub output for this invocation

types/app.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { EventGridFunctionOptions } from './eventGrid';
66
import { EventHubFunctionOptions } from './eventHub';
77
import { GenericFunctionOptions } from './generic';
88
import { HttpFunctionOptions, HttpHandler, HttpMethodFunctionOptions } from './http';
9+
import { MySqlFunctionOptions } from './mySql';
910
import { ServiceBusQueueFunctionOptions, ServiceBusTopicFunctionOptions } from './serviceBus';
1011
import { SetupOptions } from './setup';
1112
import { SqlFunctionOptions } from './sql';
@@ -173,6 +174,13 @@ export function warmup(name: string, options: WarmupFunctionOptions): void;
173174
*/
174175
export function sql(name: string, options: SqlFunctionOptions): void;
175176

177+
/**
178+
* Registers a MySql function in your app that will be triggered when a row is created or updated
179+
* @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
180+
* @param options Configuration options describing the inputs, outputs, and handler for this function
181+
*/
182+
export function mySql(name: string, options: MySqlFunctionOptions): void;
183+
176184
/**
177185
* Registers a generic function in your app that will be triggered based on the type specified in `options.trigger.type`
178186
* Use this method if your desired trigger type does not already have its own method

types/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export * from './hooks/logHooks';
1717
export * from './http';
1818
export * as input from './input';
1919
export * from './InvocationContext';
20+
export * from './mySql';
2021
export * as output from './output';
2122
export * from './serviceBus';
2223
export * from './setup';

types/input.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FunctionInput } from './index';
77
import { SqlInput, SqlInputOptions } from './sql';
88
import { StorageBlobInput, StorageBlobInputOptions } from './storage';
99
import { TableInput, TableInputOptions } from './table';
10+
import { MySqlInput, MySqlInputOptions } from './mySql';
1011
import {
1112
WebPubSubConnectionInput,
1213
WebPubSubConnectionInputOptions,
@@ -34,6 +35,11 @@ export function cosmosDB(options: CosmosDBInputOptions): CosmosDBInput;
3435
*/
3536
export function sql(options: SqlInputOptions): SqlInput;
3637

38+
/**
39+
* [Link to docs and examples](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-azure-mysql-input?pivots=programming-language-javascript)
40+
*/
41+
export function mySql(options: MySqlInputOptions): MySqlInput;
42+
3743
/**
3844
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-web-pubsub-input?pivots=programming-language-javascript)
3945
*/

types/mySql.d.ts

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index';
5+
import { InvocationContext } from './InvocationContext';
6+
7+
export type MySqlHandler = (changes: MySqlChange[], context: InvocationContext) => FunctionResult;
8+
9+
export interface MySqlFunctionOptions extends MySqlTriggerOptions, Partial<FunctionOptions> {
10+
handler: MySqlHandler;
11+
12+
trigger?: MySqlTrigger;
13+
}
14+
15+
export interface MySqlTriggerOptions {
16+
/**
17+
* The name of the table monitored by the trigger.
18+
*/
19+
tableName: string;
20+
21+
/**
22+
* An app setting (or environment variable) with the connection string for the database containing the table monitored for changes
23+
*/
24+
connectionStringSetting: string;
25+
}
26+
export type MySqlTrigger = FunctionTrigger & MySqlTriggerOptions;
27+
28+
export interface MySqlChange {
29+
Item: unknown;
30+
Operation: MySqlChangeOperation;
31+
}
32+
33+
export enum MySqlChangeOperation {
34+
Update = 0,
35+
}
36+
37+
export interface MySqlInputOptions {
38+
/**
39+
* The Transact-SQL query command or name of the stored procedure executed by the binding.
40+
*/
41+
commandText: string;
42+
43+
/**
44+
* The command type value
45+
*/
46+
commandType: 'Text' | 'StoredProcedure';
47+
48+
/**
49+
* An app setting (or environment variable) with the connection string for the database against which the query or stored procedure is being executed
50+
*/
51+
connectionStringSetting: string;
52+
53+
/**
54+
* Zero or more parameter values passed to the command during execution as a single string.
55+
* Must follow the format @param1=param1,@param2=param2.
56+
* Neither the parameter name nor the parameter value can contain a comma (,) or an equals sign (=).
57+
*/
58+
parameters?: string;
59+
}
60+
export type MySqlInput = FunctionInput & MySqlInputOptions;
61+
62+
export interface MySqlOutputOptions {
63+
/**
64+
* The name of the table being written to by the binding.
65+
*/
66+
commandText: string;
67+
68+
/**
69+
* An app setting (or environment variable) with the connection string for the database to which data is being written
70+
*/
71+
connectionStringSetting: string;
72+
}
73+
export type MySqlOutput = FunctionOutput & MySqlOutputOptions;

types/output.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { SqlOutput, SqlOutputOptions } from './sql';
1717
import { StorageBlobOutput, StorageBlobOutputOptions, StorageQueueOutput, StorageQueueOutputOptions } from './storage';
1818
import { TableOutput, TableOutputOptions } from './table';
19+
import { MySqlOutput, MySqlOutputOptions } from './mySql';
1920
import { WebPubSubOutput, WebPubSubOutputOptions } from './webpubsub';
2021

2122
/**
@@ -68,6 +69,11 @@ export function cosmosDB(options: CosmosDBOutputOptions): CosmosDBOutput;
6869
*/
6970
export function sql(options: SqlOutputOptions): SqlOutput;
7071

72+
/**
73+
* [Link to docs and examples](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-azure-mysql-output?pivots=programming-language-javascript)
74+
*/
75+
export function mySql(options: MySqlOutputOptions): MySqlOutput;
76+
7177
/**
7278
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-web-pubsub-output?pivots=programming-language-javascript)
7379
*/

types/trigger.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { EventHubTrigger, EventHubTriggerOptions } from './eventHub';
77
import { GenericTriggerOptions } from './generic';
88
import { HttpTrigger, HttpTriggerOptions } from './http';
99
import { FunctionTrigger } from './index';
10+
import { MySqlTrigger, MySqlTriggerOptions } from './mySql';
1011
import {
1112
ServiceBusQueueTrigger,
1213
ServiceBusQueueTriggerOptions,
@@ -23,6 +24,7 @@ import {
2324
import { TimerTrigger, TimerTriggerOptions } from './timer';
2425
import { WarmupTrigger, WarmupTriggerOptions } from './warmup';
2526
import { WebPubSubTrigger, WebPubSubTriggerOptions } from './webpubsub';
27+
2628
/**
2729
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-trigger?&pivots=programming-language-javascript)
2830
*/
@@ -78,6 +80,11 @@ export function warmup(options: WarmupTriggerOptions): WarmupTrigger;
7880
*/
7981
export function sql(options: SqlTriggerOptions): SqlTrigger;
8082

83+
/**
84+
* [Link to docs and examples](https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-azure-mysql-trigger?pivots=programming-language-javascript)
85+
*/
86+
export function mySql(options: MySqlTriggerOptions): MySqlTrigger;
87+
8188
/**
8289
* [Link to docs and examples](https://docs.microsoft.com/azure/azure-functions/functions-bindings-web-pubsub-trigger?pivots=programming-language-javascript)
8390
*/

0 commit comments

Comments
 (0)