查询对象所在的函数过滤器

时间:2012-12-26 17:36:36

标签: mobile service azure

我正在尝试在Azure层中实现我的业务逻辑,而我只是没有在Insert上掌握这个node.js样式的脚本。

我有适用于此

的T-SQL
declare @latitude decimal(23,20)
declare @longitude decimal(23,20)
declare @timeStamp datetime

set @latitude = 37.7858340000000012537
set @longitude = -122.4064170000000046911
set @timeStamp = '2012-12-25 02:58:23'

select longitude, latitude, userid
from blah.actions ba
where 
(
    datediff(second, ba.TimeStamp, @timeStamp) < 5 and
    (ba.longitude - 0.0001 <= @longitude and ba.longitude + 0.0001 >= @longitude) and
    (ba.latitude - 0.0001 <= latitude and ba.latitude + 0.0001 >= latitude) 
)

问题是,如何使用函数在Insert?上的Azure脚本中过滤表查询?

这样多一点工作。我想出了如何使用函数进行过滤(但我仍然在努力调试Azure脚本)。我的插入内容中包含以下内容。我有它&#34;工作&#34;,因为我不再收到&#34;内部服务器错误&#34;,但我不知道如何记录结果或查看它们(这个Azure上的任何提示东西非常感谢)。我开始意识到我需要在这个应用程序上做多少工作。

function dateDiff(date1, date2) 
{
    return date1.getTime() - date2.getTime() / 1000;
}

function insert(item, user, request) {

    request.execute();

    var actionsTable = tables.getTable('BlahActions');

    actionsTable.where(function(currentLat, currentLon, currentTime)
    {
        return (this.Latitude - 0.0001 <= currentLat && this.Latitude + 0.0001 >= currentLat) &&
               (this.Longitude - 0.0001 <= currentLon && this.Longitude + 0.0001 >= currentLon) &&
               (this.TimeStamp == currentTime);
               //(dateDiff(this.TimeStamp, currentTime) <= 5);
    }, item.Latitude, item.Longitude, item.TimeStamp)
    .read(
    {
        success:function(results)
        {
        }
    });
}

使用getTime()时,上面脚本的问题是Azure pukes。我需要抓住所有接近相同纬度和经度并且在过去X秒内发生的条目(是的,基本上重新发明&#34; bump&#34;)。这是我目前卡住的地方。如果我通过这部分,我会更新。

1 个答案:

答案 0 :(得分:0)

这里吸取了一些教训。 首先,可以通过移动服务根目录顶部的菜单查看日志文件,其中显示“LOGS”...#epicFacePalm。 其次,现在我可以在我的XCode IDE中看到实际的错误消息而不是通用的

  • where方法的谓词中的return语句只能进行简单的比较 - 你不能调用另一个方法并检查条件语句中的返回值 - 这就是我的意思。
  • 其他技术细节是将我的TimeStamp列从DateTime更改为double - 完全简化了时间戳的减法,无需转换 - 简单

话虽如此,我现在在where方法中有这个

    actionsTable.where(function(currentLat, currentLon, currentTime)
    {
        return (this.Latitude - 0.0001 <= currentLat && this.Latitude + 0.0001 >= currentLat) &&
            (this.Longitude - 0.0001 <= currentLon && this.Longitude + 0.0001 >= currentLon) &&
           (currentTime - this.TimeStamp <= 5);
    }, item.Latitude, item.Longitude, item.TimeStamp)

在我在成功回调

中过滤结果之前过滤结果
.read(
{
    success:function(results)
    {            
       for (var i = 0; i < results.length; i++)
       {
            var obj = results[i];

            for(var key in obj)
            {
                if (key === "id" && 
                    distance(obj.Longitude, obj.Latitude, item.Longitude, item.Latitude) < 30)
                {                        
                }
            }
       }
    }
}

语法清晰的全部内容

function insert(item, user, request) {
request.execute();

var actionsTable = tables.getTable('blahActions');
console.log("Inserting new action '%j'", item);

actionsTable.where(function(currentLat, currentLon, currentTime)
{
    return (this.Latitude - 0.0001 <= currentLat && this.Latitude + 0.0001 >= currentLat) &&
           (this.Longitude - 0.0001 <= currentLon && this.Longitude + 0.0001 >= currentLon) &&
           (currentTime - this.TimeStamp <= 5);
}, item.Latitude, item.Longitude, item.TimeStamp)
.read(
{
    success:function(results)
    {            
       for (var i = 0; i < results.length; i++)
       {
            var obj = results[i];

            for(var key in obj)
            {
                if (key === "id" && 
                    distance(obj.Longitude, obj.Latitude, item.Longitude, item.Latitude) < 30)
                {                        
                }
            }
       }
    }
});

}