Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySql Changes for JS #319

Open
wants to merge 6 commits into
base: v4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
HttpHandler,
HttpMethod,
HttpMethodFunctionOptions,
MySqlFunctionOptions,
ServiceBusQueueFunctionOptions,
ServiceBusTopicFunctionOptions,
SqlFunctionOptions,
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ export enum SqlChangeOperation {
Update = 1,
Delete = 2,
}

export enum MySqlChangeOperation {
Update = 0,
}
9 changes: 9 additions & 0 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
CosmosDBInputOptions,
FunctionInput,
GenericInputOptions,
MySqlInput,
MySqlInputOptions,
SqlInput,
SqlInputOptions,
StorageBlobInput,
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
GenericOutputOptions,
HttpOutput,
HttpOutputOptions,
MySqlOutput,
MySqlOutputOptions,
ServiceBusQueueOutput,
ServiceBusQueueOutputOptions,
ServiceBusTopicOutput,
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions src/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
GenericTriggerOptions,
HttpTrigger,
HttpTriggerOptions,
MySqlTrigger,
MySqlTriggerOptions,
ServiceBusQueueTrigger,
ServiceBusQueueTriggerOptions,
ServiceBusTopicTrigger,
Expand Down Expand Up @@ -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);
}
Expand Down
16 changes: 15 additions & 1 deletion types/InvocationContext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -138,7 +145,7 @@ export interface InvocationContextExtraInputs {
* Set a secondary generic input for this invocation
* @inputOrName the configuration object or name for this input
* @value the input value
*/
*/
guptaheena marked this conversation as resolved.
Show resolved Hide resolved
set(inputOrName: FunctionInput | string, value: unknown): void;
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions types/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 6 additions & 0 deletions types/input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
73 changes: 73 additions & 0 deletions types/mySql.d.ts
Original file line number Diff line number Diff line change
@@ -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<FunctionOptions> {
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;
6 changes: 6 additions & 0 deletions types/output.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions types/trigger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading