當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript mssql.connect函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。