从 Windows Azure Mobile Services 中的读取请求中获取 ID

Getting the ID from a read request in Windows Azure Mobile Services

本文关键字:读取 请求 获取 ID Azure Mobile Services Windows      更新时间:2023-09-26

我正在尝试为Windows Azure Mobile Services中的一个表实现服务器端脚本。目前,我的脚本如下所示:

function read(query, user, request) {
    var sql = 'SELECT * FROM nextjet.aircraft AS ac ' +
                'INNER JOIN nextjet.aircraft_type AS act ' +
                'ON ac.aircraft_type_id = act.id AND ac.id = ?';
    console.log('Attempting to fetch an aircraft row');
    mssql.query(sql, [request.id], {
        success: function(results) {
            console.log('aircaft row fetched: ' + results);
            request.respond(statusCodes.OK, results);
        },
        error: function(err) {
            console.log('There was an error when fetching an aircraft row: ' + err);
            request.respond(statusCodes.NOT_FOUND, 'The aircraft was not found in the database');
        }
    });
}

如果我使用 readWithId:(NSNumber *(id 方法从 iOS 调用它,如何在服务器端获取 ID?就像现在一样(只是试图通过调用request.idrequest对象中获取它。这不起作用,日志告诉我这是一个无效的参数类型。

那么,我如何获取 ID?在插入操作中,我将通过item对象访问完整对象,但不能在读取操作中访问。

提前感谢,
延斯

若要访问从 readWithId 发送的 ID,需要使用作为读取脚本参数的查询对象。 在本例中,您将使用 query.id