查询在Azure Table中存储的插入功能的其它表 [英] Query other tables in insert function of Azure Table Storage

查看:208
本文介绍了查询在Azure Table中存储的插入功能的其它表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Azure表存储,一旦新项目被插入发送推送通知。目前,我尝试查询第二个表检索,我要使用推送通知的字符串。

我很新的Node.js的,所以我通过一些code工作,并尝试了以下启动的TestTable的查询来查找与​​基于TestProperty正确的实体。一旦我找到了正确的实体我想使用一个特定的属性由它去努力。

这是错误我与我目前的code得到:

 类型错误:无法读取属性'表'未定义

我的code的一部分,我尝试查询第二个表

  VAR azureMobileApps =要求('Azure的移动应用程序),
表=要求('Azure的移动应用程序/ src目录/ EX preSS /表),
查询=要求('Azure的移动应用程序/ src目录/查询),
记录=要求('Azure的移动应用程序/ src目录/记录器');变种表= azureMobileApps.table();table.insert(功能(上下文){
    logger.info('运行TestTable1.insert');
    变种TestTable的= azureMobileApps.tables.table('TestTable2');
    变种查询= queries.create('TestTable2'),其中({TestProperty:context.item.testproperty})。    返回context.execute()
        。然后(功能(结果){
        .....


解决方案

随着Azure的表的存储是在云中存储非结构化数据的NoSQL服务,你可以参考的https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-tables/得到更多。

不过,在Azure的移动应用程序节点SDK中的模块包含添加表到Azure的移动应用功能。它返回一个可以连接到前preSS应用与登记表的一些附加功能的路由器。这实际上利用SQL Azure的(在Azure上的SQL Server数据库服务)。

根据您的code片段,看来你是用第二个概念实施。

和根据您的描述,如果我不要误会,你要查询表2 表1 在EasyTables操作脚本。

我们可以利用使用()自定义中间件来指定中间件对表中的每个要求作为的文件说明将要执行Azure的移动应用SDK的<一个href=\"http://azure.github.io/azure-mobile-apps-node/module-azure-mobile-apps_ex$p$pss_tables_table.html#~use\" rel=\"nofollow\">http://azure.github.io/azure-mobile-apps-node/module-azure-mobile-apps_ex$p$pss_tables_table.html#~use.

例如

  VAR的查询=要求('Azure的移动应用程序/ src目录/查询');
VAR insertMiddleware =功能(REQ,资源,下一个){
    变种表= req.azureMobile.tables('表2'),
    查询= queries.create(表2)
            。凡({TestProperty:req.body.testproperty});
    table.read(查询)。然后(功能(结果){
        如果(结果){
            req.someStoreData = somehander(结果); //这里有些弯的操作,让你想储存什么,将在接下来的步骤中使用
            下一个();
        }其他{
            res.send(无数据);
        }
    });
};table.insert.use(insertMiddleware,table.operation);
table.insert(功能(上下文){
   的console.log(context.req.someStoreData);
   返回context.execute();
});

此外,如果需要推EasyTables脚本通知,您可以参考样本在Github上的<一个href=\"https://github.com/Azure/azure-mobile-apps-node/blob/master/samples/push-on-insert/tables/TodoItem.js\" rel=\"nofollow\">https://github.com/Azure/azure-mobile-apps-node/blob/master/samples/push-on-insert/tables/TodoItem.js

I am using Azure Table Storage to send out Push Notifications once a new item is inserted. Currently I am trying to query a second table to retrieve a string which I want to use for push notifications.

I am quite new to Node.js so I worked through some code and tried the following to start a query on the TestTable to find the correct entity with based on TestProperty. Once I have found the correct entity I want to use a specific property from it to work on with.

This is the error I get with my current code:

TypeError: Cannot read property 'table' of undefined

Part of my code where I try to query a second table

var azureMobileApps = require('azure-mobile-apps'),
tables = require('azure-mobile-apps/src/express/tables'),
queries = require('azure-mobile-apps/src/query'),
logger = require('azure-mobile-apps/src/logger');

var table = azureMobileApps.table();

table.insert(function (context) {
    logger.info('Running TestTable1.insert');
    var testTable = azureMobileApps.tables.table('TestTable2');
    var query = queries.create('TestTable2').where({ TestProperty : context.item.testproperty }); 

    return context.execute()
        .then(function (results) {
        .....

解决方案

As Azure Table Storage is a service that stores unstructured NoSQL data in the cloud, you can refer to https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-tables/ to get more.

But, the tables module in azure-mobile-apps-node sdk contains functionality for adding tables to an Azure Mobile App. It returns a router that can be attached to an express app with some additional functions for registering tables. Which actually leverage Azure SQL (SQL Server database service on Azure).

According your code snippet, it seems you are implementing with the second concept.

And per your description, if I do not misunderstand, you want to query table2 in table1 operations in EasyTables scripts.

we can leverage "use()" to custom middleware to specify middleware to be executed for every request against the table as the description on the document of azure-mobile-apps sdk at http://azure.github.io/azure-mobile-apps-node/module-azure-mobile-apps_express_tables_table.html#~use.

E.G.

var queries = require('azure-mobile-apps/src/query');
var insertMiddleware = function(req,res,next){
    var table = req.azureMobile.tables('table2'),
    query = queries.create('table2')
            .where({ TestProperty : req.body.testproperty });
    table.read(query).then(function(results) {
        if(results){
            req.someStoreData = somehander(results); //some hander operations here to get what you want to store and will use in next step
            next();
        }else{
            res.send("no data");
        }
    });
};

table.insert.use(insertMiddleware, table.operation);
table.insert(function (context) {
   console.log(context.req.someStoreData);
   return context.execute();
});

Additionally, if you need to push notifications in EasyTables scripts, you can refer to the sample on Github at https://github.com/Azure/azure-mobile-apps-node/blob/master/samples/push-on-insert/tables/TodoItem.js

这篇关于查询在Azure Table中存储的插入功能的其它表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆