本文整理匯總了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);
}
});
}
示例2: createDbPool
export function createDbPool() {
return createPool({
host: "localhost",
user: "game",
password: "asdf",
database: "test",
connectionLimit: 10
});
}
示例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
});
}
示例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;
}
示例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);
}
}
示例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);
});
}
示例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`);
}
}
示例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();
示例9: constructor
constructor(dbms: 'mysql' | 'postgresql', connection: mysql.IConnectionConfig, tableName: string) {
this.dbms = dbms;
this.tableName = tableName;
this.pool = mysql.createPool(connection);
}
示例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);
}