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


TypeScript mysql.createPool函數代碼示例

本文整理匯總了TypeScript中mysql.createPool函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createPool函數的具體用法?TypeScript createPool怎麽用?TypeScript createPool使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了createPool函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: connect

	// Executes a database statement on a pooled connection. All commands executed
	// on the connection are not guaranteed to run instantly, but are guaranteed to run
	// sequentially and serially.
	public connect(callback: ICallback) {
		if (!this._pool) {
			this._pool = mysql.createPool({
				connectionLimit: 10,
				host: this._config.mysqlHost,
				user: this._config.mysqlUser,
				password: this._config.mysqlPassword,
				database: this._config.mysqlDatabase,
				multipleStatements: true
			});
		}

		this._pool.getConnection((err: any, connection: any) => {
			if (err) {
				callback(err);
			} else {
				if (!this._checkedExists) {
					this.dbInit(connection, (err: any) => {
						if (err)
							return callback(err);
						else {
							this._checkedExists = true;
							return callback(null, connection);
						}
					});
				} else
					return callback(null, connection);
			}
		});
	}
開發者ID:kayateia,項目名稱:flowerbox-server,代碼行數:33,代碼來源:MySQL.ts

示例2: createDbPool

 export function createDbPool() {
   return createPool({
     host: "localhost",
     user: "game",
     password: "asdf",
     database: "test",
     connectionLimit: 10
   });
 }
開發者ID:tbergqvist,項目名稱:moist-silica,代碼行數:9,代碼來源:database.ts

示例3: constructor

	constructor(connectionConfig: DatabaseConnectionConfig, cacheEngine: CacheEngineInterface, notifier?: Notifier) {
		super(cacheEngine, notifier);

		// Lets create the connection pool
		this.pool  = mysql.createPool({
		  connectionLimit : connectionConfig.connectionPoolLimit,
		  host: connectionConfig.host,
		  user: connectionConfig.username,
		  password: connectionConfig.password,
		  database: connectionConfig.database
		});
	}
開發者ID:fabianTMC,項目名稱:smart-query-cache,代碼行數:12,代碼來源:mysql.ts

示例4: createPool

 protected static createPool(cfg, name):mysql.IPool {
     let pool = mysql.createPool({
         connectionLimit: cfg.connectionLimit,
         host: cfg.host,
         database: cfg.database,
         user: cfg.user,
         password: cfg.password,
         dateStrings: true
     });
     winston.info("database(" + name + ") at:" + cfg.host + " pool created.");
     return pool;
 }
開發者ID:xiabin1235910,項目名稱:example-typescript-decorator,代碼行數:12,代碼來源:baseDB.ts

示例5: connect

    connect(profile:DatabaseProfile) {

        this.profile = profile;

        logger.info(`Creando el pool de base de datos: ${this.profile.host}/${this.profile.database}`);
        try {
            this.connectionPool = createPool(this.profile);
        }
        catch(e) {
            logger.error(`Error al conectar con la base de datos: ${this.profile.host}/${this.profile.database}`
                ,e);
            process.exit(1);
        }
    }
開發者ID:antoniohueso,項目名稱:sauron2.0,代碼行數:14,代碼來源:util.ts

示例6: init

 export function init() : void
 {
     db = Mysql.createPool(
     {
         host: process.env.SQL_HOST,
         user: process.env.SQL_USER,
         password: process.env.SQL_PASSWORD,
         database: process.env.SQL_DB,
         connectionLimit : 20
     });
     db.on("error", function(err: any)
     {
         Logging.trace(err);
     });
 }
開發者ID:p0ody,項目名稱:ff2ebook-node,代碼行數:15,代碼來源:DBHandler.ts

示例7: constructor

    constructor(config: IConfig) {
        super();

        if (config.customFormat) {
            config.connection.queryFormat = this.customFormat;
        }

        this.config = config;

        this.pool = mysql.createPool(config.connection);

        if (config.verbose) {
            console.log(`Initialize ${config.name} connection`);
        }
    }
開發者ID:vruden,項目名稱:node-mysql-connection,代碼行數:15,代碼來源:connection.ts

示例8: query

import * as mysql from 'mysql';



// 創建連接池:最大10個連接
export var pool = mysql.createPool({
    connectionLimit: 10,
    host: 'localhost',
    user: 'root',
    password: '1234',
    database: 'test'
});

/** 不允許直接使用連接池,而是通過該方法執行sql */
export function query(sql: string, params?: Object | any[]) {
    return new Promise((resolve, reject) => {
        pool.query(sql, params ? params : [], (err, rows, fields) => {
            if (err) reject(err);
            else resolve(rows);
        });
    });
}


// export async function query(sql: string, params?: any) {
//     return new Promise((resolve, reject) => {
//         pool.getConnection((err, connection) => {
//             connection.query(sql, params ? params : [], (err, rows) => {
//                 if (err) reject(err);
//                 else resolve(rows);
//                 connection.release();
開發者ID:gujiajia,項目名稱:node.js,代碼行數:31,代碼來源:db.ts

示例9: constructor

    constructor(dbms: 'mysql' | 'postgresql', connection: mysql.IConnectionConfig, tableName: string) {
        this.dbms = dbms;
        this.tableName = tableName;

        this.pool = mysql.createPool(connection);
    }
開發者ID:vruden,項目名稱:node-migrate,代碼行數:6,代碼來源:db-helper.ts

示例10: require

var mysql = require('mysql');

var pool = mysql.createPool({
    connectionLimit: 100, // important
    host: "localhost",
    user: "root",
    password: "123",
    database: "koodkaco",
    debug: false
});

export function handle_database(query, callBack) {

    pool.getConnection(function (err, connection) {

        if (err) {
            console.log(err);
            connection.release();
            callBack({ error: true, msg: "Error in connection database: " + err });
            // res.json({ "code": 100, "status": "Error in connection database" });
            // return;
        }

        console.log('connected as id ' + connection.threadId);

        connection.query(query, function (err, rows) {
            connection.release();
            if (!err) {
                callBack({ error: false, data: rows });
                // res.json(rows);
            }
開發者ID:uqutub,項目名稱:NodejsMySql,代碼行數:31,代碼來源:mysql.ts


注:本文中的mysql.createPool函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。