From e6d4c9e4fbab2f0deb418ff603e7c62bb6ff2ace Mon Sep 17 00:00:00 2001 From: Kazuki Date: Fri, 9 Sep 2016 14:29:38 +0900 Subject: [PATCH 1/3] add custom sql query support --- azure-mobile-apps/azure-mobile-apps-tests.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/azure-mobile-apps/azure-mobile-apps-tests.ts b/azure-mobile-apps/azure-mobile-apps-tests.ts index 093932c2fbca03..6e5aea79e6f64f 100644 --- a/azure-mobile-apps/azure-mobile-apps-tests.ts +++ b/azure-mobile-apps/azure-mobile-apps-tests.ts @@ -84,4 +84,14 @@ mobileApps.logger.debug('a debug message') // Query queries.create('table').where({ x: 10 }).select('col1,col2'); -mobileApps.query.create('table'); \ No newline at end of file +mobileApps.query.create('table'); + +// custom sql query +mobileApp.api.add('query', { authorize: true, get: (req, res, next) => { + req.azureMobile.data.execute({ + sql: "SELECT * FROM TODOITEM WHERE COMPLETE = :complete", + parameters: [ + { name: 'complete', value: 1 } + ] + }).then(x => {}) +}, delete: function () {} }); From 18dab807a0c1a2e5493b32e6ef5b4c9f7829cf68 Mon Sep 17 00:00:00 2001 From: Kazuki Date: Fri, 9 Sep 2016 14:30:46 +0900 Subject: [PATCH 2/3] support custom sql query definitiion --- azure-mobile-apps/azure-mobile-apps.d.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/azure-mobile-apps/azure-mobile-apps.d.ts b/azure-mobile-apps/azure-mobile-apps.d.ts index 0a42fa9ecf24d5..436d88b3cb1fa0 100644 --- a/azure-mobile-apps/azure-mobile-apps.d.ts +++ b/azure-mobile-apps/azure-mobile-apps.d.ts @@ -215,7 +215,7 @@ declare namespace Azure.MobileApps { item: any; req: Express.Request; res: Express.Response; - data: (table: TableDefinition) => Data.Table; + data: ContextData; tables: (tableName: string) => Data.Table; user: User; push: typeof nh; @@ -223,6 +223,21 @@ declare namespace Azure.MobileApps { execute(): Thenable; } + interface ContextData { + (table: TableDefinition): Data.Table; + execute(q: SqlQueryDefinition): Thenable; + } + + interface SqlQueryDefinition { + sql: string; + parameters?: SqlParameterDefinition[]; + } + + interface SqlParameterDefinition { + name: string; + value: any; + } + interface TableDefinition { authorize?: boolean; autoIncrement?: boolean; From 35ab0fe353fbb25e6bfec87e47ce40d9a2389d7f Mon Sep 17 00:00:00 2001 From: Kazuki Date: Fri, 9 Sep 2016 15:29:07 +0900 Subject: [PATCH 3/3] add semicoron --- azure-mobile-apps/azure-mobile-apps-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-mobile-apps/azure-mobile-apps-tests.ts b/azure-mobile-apps/azure-mobile-apps-tests.ts index 6e5aea79e6f64f..6b994b4f059a25 100644 --- a/azure-mobile-apps/azure-mobile-apps-tests.ts +++ b/azure-mobile-apps/azure-mobile-apps-tests.ts @@ -93,5 +93,5 @@ mobileApp.api.add('query', { authorize: true, get: (req, res, next) => { parameters: [ { name: 'complete', value: 1 } ] - }).then(x => {}) + }).then(x => {}); }, delete: function () {} });