當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。