本文整理汇总了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);
}