• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript mssql.connect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中mssql.connect函数的典型用法代码示例。如果您正苦于以下问题:TypeScript connect函数的具体用法?TypeScript connect怎么用?TypeScript connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: async

    searchPosSales: async (conditions, context) => {
        let sqlString = `
            SELECT id, payment_no, seat_code, performance_day 
            FROM pos_sales 
            WHERE 1 = 1`;
        
        if (conditions.from != null) {
            sqlString += ` AND performance_day >= '${conditions.from}'`;
        }
        if (conditions.to != null) {
            sqlString += ` AND performance_day <= '${conditions.to}'`;
        }

        sql.close();
        return await sql.connect(configs.mssql).then(async connection => {
            return await connection.request().query(sqlString).then(docs => {
                connection.close();
                return docs.recordset.map(doc => {
                    return { $and: [
                            { payment_no: doc.payment_no },
                            { seat_code: doc.seat_code },
                            { performance_day: moment(doc.performance_day).format('YYYYMMDD') }]}
                });
            });
        });
    },
开发者ID:motionpicture,项目名称:ttts-functions,代码行数:26,代码来源:pos_sales.ts


示例2: query

 query(callback:(err, rows: Array<IRow>) => void) {
     var connectionString = `mssql://${this.config.user}:${this.config.password}@${this.config.host}/${this.config.database}`;
     var sql = `SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = '${this.config.database}'`;
     
     mssql.connect(connectionString)
         .then(() => new mssql.Request().query(sql)
             .then((recordSet: Array<IRowDataPacket>) => callback(null, recordSet.map(row => {
                 return {
                     tableName: row.TABLE_NAME,
                     name: row.COLUMN_NAME,
                     defaultValue: row.COLUMN_DEFAULT,
                     isNullable: row.IS_NULLABLE === "YES",
                     type: row.DATA_TYPE
                 };
             })))
             .catch(err => callback(err, null)))
         .catch(err => callback(err, null));
 }
开发者ID:LarsVonQualen,项目名称:pocostick,代码行数:18,代码来源:MssqlHandler.ts


示例3:

/** Samples from https://github.com/patriksimek/node-mssql#promises */

import * as sql from "mssql";

const config = {
    user: '...',
    password: '...',
    server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
    database: '...',

    options: {
        encrypt: true // Use this if you're on Windows Azure
    }
};

const value = 50;

sql.connect(config).then(function() {
    sql.query`select * from mytable where id = ${value}`.then(function(recordset) {
        console.dir(recordset);
    }).catch(function(err) {
        // ... error checks
    });
}).catch(function(err) {
    // ... error checks
});
开发者ID:typed-contrib,项目名称:node-mssql,代码行数:26,代码来源:taggedtemplates.ts


示例4:

/** Samples from https://github.com/patriksimek/node-mssql#promises */

import * as sql from "mssql";

const config = {
    user: '...',
    password: '...',
    server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
    database: '...',

    options: {
        encrypt: true // Use this if you're on Windows Azure
    }
};

sql.connect(config)
    .then(function() {
        const value = 50;
        
        // Query

        new sql.Request()
            .input('input_parameter', sql.Int, value)
            .query('select * from mytable where id = @input_parameter').then(function(recordset) {
                console.dir(recordset);
            }).catch(function(err) {
                // ... error checks
            });

        // Stored Procedure
开发者ID:typed-contrib,项目名称:node-mssql,代码行数:30,代码来源:promises.ts


示例5: function

        encrypt: true // Use this if you're on Windows Azure
    }
};

sql.connect(config, function(err) {
    // ... error checks

    var request = new sql.Request();
    request.stream = true; // You can set streaming differently for each request
    request.query('select * from verylargetable'); // or request.execute(procedure);

    request.on('recordset', function(columns) {
        // Emitted once for each recordset in a query
    });

    request.on('row', function(row) {
        // Emitted for each row in a recordset
    });

    request.on('error', function(err) {
        // May be emitted multiple times
    });

    request.on('done', function(affected) {
        // Always emitted as the last one
    });
});

sql.on('error', function(err) {
    // ... error handler
});
开发者ID:typed-contrib,项目名称:node-mssql,代码行数:31,代码来源:streaming.ts


示例6: function

    }
};

const value = 50;

sql.connect(config, function(err) {
    // ... error checks

    // Query

    new sql.Request().query('select 1 as number', function(err, recordset) {
        // ... error checks

        console.dir(recordset);
    });

    // Stored Procedure

    new sql.Request()
    .input('input_parameter', sql.Int, value)
    .output('output_parameter', sql.VarChar(50))
    .execute('procedure_name', function(err, recordsets, returnValue) {
        // ... error checks

        console.dir(recordsets);
    });
});

sql.on('error', function(err) {
    // ... error handler
});
开发者ID:typed-contrib,项目名称:node-mssql,代码行数:31,代码来源:nestedcallbacks.ts


示例7:

    .catch((ex) => {
        res.status(500).end();
    })
})
app.get('*', (req, res) => {
    res.sendFile(path.resolve(__dirname, 'public', 'index.html'));
})

var config: sql.config = {
			server: process.env.DB_HOST,
			database: process.env.DB_NAME,
			user: process.env.DB_USERNAME,
			password: process.env.DB_PASSWORD,
			options: {
				encrypt: true // Use this if you're on Windows Azure
			}
			
		};
		

sql.connect(config).then(() => {
    app.listen(app.get('port'), () => {
        console.log(`Tweeter Center Tweet Analyzer Started Up`)
    });  
})
.catch((ex) => {
    console.log('Could not connect to sql database');
    console.log(JSON.stringify(ex));
})

开发者ID:kenstone,项目名称:tweeter-center,代码行数:29,代码来源:app.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript mssql.Connection类代码示例发布时间:2022-05-25
下一篇:
TypeScript mssql.VarChar函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap