当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Connection.on方法代码示例

本文整理汇总了TypeScript中tedious.Connection.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Connection.on方法的具体用法?TypeScript Connection.on怎么用?TypeScript Connection.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tedious.Connection的用法示例。


在下文中一共展示了Connection.on方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

router.post('/', function(req, res) {
    var managers = new Managers.Managers();
    var userId = req.body.userId;
    var apiKey = req.body.apiKey;
    var deviceId = req.body.deviceId;
    var pilotValue = req.body.pilotValue;

    var connection = new Connection(managers.dbManager.generateTediousConfig());

    connection.on('connect', function(err) {
        // If no error, then good to proceed.
        if(err) {
            console.log('ERROR: %s', err);
            res.status(500).send("Error");
        }
        else {
            console.log("Connected");
            executeStatement(res, deviceId, pilotValue);
        }
    });

    function executeStatement(res, deviceId, pilotValue) {
        managers.dbManager.allowRequest(userId, apiKey, function(authorised) {
            if(!authorised) {
                res.status(500).send();
            }
            else {
                var request = new Request('dbo.UpdatePilotDevices',
                    function(err, rowCount) {
                        if (err) {
                            console.log(err);
                            res.status(500).send("Error");
                        }
                        else {
                            console.log('Complete: %s row(s) returned', rowCount);
                            connection.close();
                            res.send('Complete: ' + rowCount + ' row(s) returned');
                        }
                    }
                );

                request.addParameter('DeviceId', TYPES.NVarChar, deviceId);
                request.addParameter('IsPilot', TYPES.NVarChar, pilotValue);

                connection.callProcedure(request);
            }
        });
    }
});
开发者ID:MattGauler,项目名称:support-portal-uat,代码行数:49,代码来源:markPilot.ts

示例2: function

app.get("/api/awards", function(req, res){
    var connection = new tedious.Connection(config);
    connection.on('connect', err => {
        var request = new tedious.Request(sql.GetAwards, (err, rc, rows) => {
            if (err){
                console.log(err);
                res.status(500).send("database error");
            } else {
                var awards = rows.map(row => {return {id: row.ID.value, awardName: row.AwardName.value}});
                res.json(awards);
            }
            connection.close();
        });
        
        connection.execSql(request);
    });
})
开发者ID:sweko,项目名称:WebDemo,代码行数:17,代码来源:server.ts

示例3: Promise

  new Promise((res, rej) => {
    const rows: A[] = [];
    let columns: string[] = [];
    const connection = new Connection(config);
    connection.on("connect", (err: any) => {
      if (err) {
        rej(err);
      } else {
        const request = new Request(query.sql, (err: any, count: number) => {
          if (err) {
            rej(err);
          } else {
            res(rows);
          }
          connection.close();
        })
          .on("row", row => {
            const obj = row.reduce(
              (p: any, c: any, i: number) => ({
                ...p,
                [columns[i]]: c.value
              }),
              {}
            );
            rows.push(obj);
          })
          .on("columnMetadata", (meta: any[]) => {
            columns = meta.map(x => x.colName);
          });

        if (query.params) {
          Object.keys(query.params).forEach(x => {
            const val = query.params[x];
            request.addParameter(x, getType(val), val);
          });
        }
        connection.execSql(request);
      }
    });
  });
开发者ID:reidev275,项目名称:LessTedious,代码行数:40,代码来源:index.ts

示例4: function

router.post('/', function(req, res, next) {
    var userId = req.body.userId;
    var apiKey = req.body.apiKey;
    var requestMessageId = req.body.requestMessageId;
    console.log('PARAMS: %s, %s, %s', userId, apiKey, requestMessageId);

    var managers = new Managers.Managers();

    var connection = new Connection(managers.dbManager.generateTediousConfig());

    connection.on('connect', function(err) {
        // If no error, then good to proceed.
        if(err) {
            console.log('ERROR: %s', err);
            res.status(500).send();
        }
        else {
            console.log("Connected");
            executeStatement(res);
        }
    });

    connection.on('end', function() { console.log('Db Disconnected') });

    function executeStatement(res) {
        managers.dbManager.allowRequest(userId, apiKey, function(authorised) {
            if(!authorised) {
                res.status(500).send();
            }
            else {
                var result = [];

                var request = new Request(
                    `
                    Select
                        *
                    from
                        SupportRequest
                    where
                        MessageID = @requestMessageId
                    `,
                    function(err, rowCount) {
                        if (err) {
                            console.log(err);
                            res.status(500).send("Error");
                        }
                        else {
                            console.log('Complete: %s row(s) returned', rowCount);
                            connection.close();
                            res.setHeader('content-type', 'application/x-www-form-urlencoded');
                            res.setHeader('Access-Control-Allow-Origin', '*');
                            res.status(200).send(result);
                        }
                    }
                );

                request.addParameter('requestMessageId', TYPES.NVarChar, requestMessageId);

                request.on('row', function(columns) {
                    var row = {};

                    columns.forEach(function(column) {
                        if (column.value === null) {
                            console.log('NULL');
                        } else {
                            row[column.metadata.colName] = column.value;
                        }
                    });

                    result.push(row);
                });

                request.on('done', function(rowCount, more) {
                    console.log(rowCount + ' rows returned');
                });

                connection.execSql(request);
            }
        });
    }
});
开发者ID:MattGauler,项目名称:support-portal-uat,代码行数:81,代码来源:supportResponse.ts

示例5: function

router.post('/', function(req, res) {
    var managers = new Managers.Managers();
    var userId = req.body.userId;
    var apiKey = req.body.apiKey;
    var username = req.body.username;
    var password = req.body.password;
    var depot = req.body.depot;
    var createUsers = req.body.createUsers;

    console.log('LOGIN PARAMS: %s, %s, %s, %s', username, password, depot);

    if(username == "")
        res.status(500).send();
    if(password == "")
        res.status(500).send();
    if(depot == "")
        res.status(500).send();

    var connection = new Connection(managers.dbManager.generateTediousConfig());

    connection.on('connect', function(err) {
        // If no error, then good to proceed.
        if(err) {
            console.log('ERROR: %s', err);
            res.status(500).send("Error");
        }
        else {
            console.log("Connected");
            executeStatement(res);
        }
    });

    function executeStatement(res) {
        managers.dbManager.allowRequest(userId, apiKey, function(authorised) {
            if(!authorised) {
                res.status(500).send();
            }
            else {
                bcrypt.hash(password, 8, function(err, hash) {
                    if(!err) {
                        var request = new Request(
                            '[dbo].[CreateNewUser]',
                            function(err, rowCount) {
                                console.log('RC: ' + rowCount)
                                if (err) {
                                    console.log(err);
                                    res.status(500).send();
                                }
                                else {
                                    connection.close();
                                    res.status(200).send();
                                }
                            }
                        )

                        request.addParameter('UserId', TYPES.NVarChar, username);
                        request.addParameter('Password', TYPES.NVarChar, hash);
                        request.addParameter('Depot', TYPES.NVarChar, depot);
                        request.addParameter('CreatedOn', TYPES.DateTime, new Date());
                        request.addParameter('ApiKey', TYPES.NVarChar, Guid.raw());
                        request.addParameter('ServerKey', TYPES.NVarChar, Guid.raw());
                        request.addParameter('CreateUsers', TYPES.Bit, createUsers)

                        connection.callProcedure(request);
                    }
                });
            }
        });
    }
});
开发者ID:MattGauler,项目名称:support-portal-uat,代码行数:70,代码来源:createUser.ts

示例6: function

router.post('/', function(req, res) {
    var managers = new Managers.Managers();
    var userId = req.body.userId;
    var apiKey = req.body.apiKey;
    var deviceUserId = req.body.deviceUserId;
    var deviceId = req.body.deviceId;
    var instructionType = req.body.instructionType;
    var instructionValues = req.body.instructionValues;

    console.log('INSTRUCTION PARAMS: %s, %s, %s, %s', deviceUserId, deviceId, instructionType, JSON.stringify(instructionValues));

    var connection = new Connection(managers.dbManager.generateTediousConfig());

    connection.on('connect', function(err) {
        // If no error, then good to proceed.
        if(err) {
            console.log('ERROR: %s', err);
            res.status(500).send("Error");
        }
        else {
            console.log("Connected");
            executeStatement(res);
        }
    });

    function executeStatement(res) {
        managers.dbManager.allowRequest(userId, apiKey, function(authorised) {
            if(!authorised) {
                res.status(500).send();
            }
            else {
                var request = new Request(
                    `
                        INSERT INTO [dbo].[CurrentInstructions] (DeviceId, UserId, InstructionType, InstructionValues, RequestedTime, Requester)
                        VALUES (@DeviceId, @UserId, @InstructionType, @InstructionValues, @RequestedTime, @Requester)
                    `,
                    function(err, rowCount) {
                        if (err) {
                            console.log(err);
                            res.status(500).send("Error");
                        }
                        else {
                            console.log('Complete: %s row(s) returned', rowCount);
                            connection.close();
                            res.send('Complete: ' + rowCount + ' row(s) returned');
                        }
                    }
                );

                request.addParameter('DeviceId', TYPES.NVarChar, deviceId);
                request.addParameter('UserId', TYPES.NVarChar, userId);
                request.addParameter('InstructionType', TYPES.NVarChar, instructionType);
                request.addParameter('InstructionValues', TYPES.NVarChar, JSON.stringify(instructionValues));
                request.addParameter('RequestedTime', TYPES.DateTime, new Date());
                request.addParameter('Requester', TYPES.NVarChar, 'Nick');

                connection.execSql(request);
                sendInstructionToDevice();
            }
        });
    }

    function sendInstructionToDevice() {
        var customProperties = {
            id: Guid.raw(),
            channel: deviceUserId.toString(),
            subchannel: '1',
            expiry: 0,
            date: 131007203230000000,
            content: {
                type: instructionType,
                requester: userId,
                instructionValues: instructionValues
            }
        };

        var message = {
            body: JSON.stringify(customProperties),
            customProperties: customProperties
        };

        managers.commsManager.commsWorker.sendAndCreateQueue(message);
    }
});
开发者ID:MattGauler,项目名称:support-portal-uat,代码行数:84,代码来源:instruction.ts

示例7: function

router.get('/', function(req, res, next) {
    var managers = new Managers.Managers();
    var userId = req.param('userId');
    var apiKey = req.param('apiKey');
    
    console.log(req);
    
    var connection = new Connection(managers.dbManager.generateTediousConfig());

    connection.on('connect', function(err) {
        // If no error, then good to proceed.
        if(err) {
            console.log('ERROR: %s', err);
            res.status(500).send();
        }
        else {
            console.log("Connected");
            executeStatement(res);
        }
    });

    connection.on('end', function() { console.log('Db Disconnected') });

    function executeStatement(res) {
        managers.dbManager.allowRequest(userId, apiKey, function(authorised) {
            if(!authorised) {
                res.status(500).send();
            }
            else {
                var result = [];

                var request = new Request(
                    `
                        Select
                            delaybandId as ID,
                            delayBandLabel as [Band],
                            0 as [Occurences]
                        from
                           responseDelayBands 
                    `,
                    function(err, rowCount) {
                        if (err) {
                            console.log(err);
                            res.status(500).send("Error");
                        }
                        else {
                            console.log('Complete: %s row(s) returned', rowCount);
                            connection.close();
                            res.send(result);
                        }
                    }
                );

                request.on('row', function(columns) {
                    var row = {};

                    columns.forEach(function(column) {
                        if (column.value === null) {
                            console.log('NULL');
                        } else {
                            row[column.metadata.colName] = column.value;
                        }
                    });

                    result.push(row);
                });

                request.on('done', function(rowCount, more) {
                    console.log(rowCount + ' rows returned');
                });

                connection.execSql(request);
            }
        });
    }
});
开发者ID:MattGauler,项目名称:support-portal-uat,代码行数:76,代码来源:connectivityDelayBands.ts


注:本文中的tedious.Connection.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。