Mobile 查询对象中的函数过滤器

Mobile 查询对象中的函数过滤器,mobile,service,azure,Mobile,Service,Azure,我试图在Azure层中实现我的业务逻辑,但我没有掌握插入时的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

我试图在Azure层中实现我的业务逻辑,但我没有掌握插入时的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) 
)
declare@latitude decimal(23,20)
声明@经度十进制(23,20)
声明@timeStamp datetime
设置纬度=37.7858340000000012537
设置经度=-122.4064170000000046911
设置@timeStamp='2012-12-25 02:58:23'
选择经度、纬度和用户ID
从布拉·巴开始
哪里
(
datediff(秒,ba.TimeStamp,@TimeStamp)<5和
(ba.经度-0.0001=@经度)和
(巴纬度-0.0001=纬度)
)
问题是,如何使用函数在插入时过滤Azure脚本中的表查询

所以多做点工作。我知道了如何使用函数进行过滤(但我仍在努力调试Azure脚本)。我的插页上有以下内容。我有它“工作”,事实上,我不再收到“内部服务器错误”,但我不知道如何记录结果或查看它们(任何关于这个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)
        {
        }
    });
}
函数dateDiff(date1,date2) { 返回日期1.getTime()-date2.getTime()/1000; } 函数插入(项、用户、请求){ request.execute(); var actionsTable=tables.getTable('BlahActions'); actionsTable.where(函数(currentLat、currentLon、currentTime) { 返回(此纬度-0.0001=当前纬度)&& (此经度-0.0001=当前经度)&& (this.TimeStamp==当前时间);
//(dateDiff(this.TimeStamp,currentTime)这里有一些经验教训。 首先也是最重要的一点是,可以通过移动服务根目录顶部的菜单查看日志文件,其中显示“日志”…#epicFacePalm。 其次,现在我可以看到实际的错误消息,而不是XCode IDE中的一般信息

  • where方法的谓词中的return语句只能进行简单的比较——您不能调用另一个方法并检查条件语句中的返回值——这让我感到恶心
  • 另一个技术细节是将时间戳列从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)
actionsTable.where(函数(currentLat、currentLon、currentTime)
{
返回(此纬度-0.0001=当前纬度)&&
(此经度-0.0001=当前经度)&&
(currentTime-this.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)
                {                        
                }
            }
       }
    }
});