Every line of 'connection query mysql' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
44 public connectionQuery(sql: string, args?: number | News): Promise<{}> { 45 const connection = MySQLConnector.getDatabase(); 46 return new Promise((resolve, reject) => { 47 connection.query(sql, args,(error: string, result: Array | MySQLQueryOkPacket)=> { 48 connection.end(); 49 if(error){reject(error);} 50 resolve(result); 51 }); 52 }); 53 }
48 function query(sqlString, values) { 49 // Initialize the pool lazily, in case SQL access isn't needed for this 50 // GCF instance. Doing so minimizes the number of active SQL connections, 51 // which helps keep your GCF instances under SQL connection limits. 52 if (!mysqlPool) { 53 logger.debug('creating sql pool'); 54 mysqlPool = mysql.createPool(mysqlConfig); 55 } 56 57 if (!values) values = []; 58 59 return new Promise((resolve, reject) => { 60 logger.debug('sending sql query'); 61 mysqlPool.query(sqlString, values, (err, results) => { 62 if (err) { 63 reject(err); 64 return; 65 } 66 logger.debug('query succeeded'); 67 resolve(results); 68 }); 69 }); 70 }
32 open(url) { 33 if (!url) url = this.url; 34 // if (typeof url !== 'string') { 35 // throw new TypeError('MySql uri must be a string.'); 36 // } 37 this.url = url; 38 this.db = mysql.createConnection(this.url); 39 return new Promise((res, rej) => { 40 this.db.connect(err => { 41 if (err) { 42 this.emitter.emit('error', err); 43 return rej(err); 44 } 45 this.emitter.emit('connected', this); 46 res(this.db); 47 }); 48 }); 49 }
7 function getConnection(){ 8 if(connection == null){ 9 connection = mysql.createConnection({ 10 host : config.mysqld.host, 11 user : config.mysqld.user, 12 password : config.mysqld.password, 13 database: config.mysqld.database 14 }); 15 connection.connect(); 16 } 17 return connection; 18 }
45 public connect(): void { 46 this.connection.connect(); 47 }
27 connect() { 28 this.connection.connect(); 29 }
43 _getMysqlConnection() { 44 if (!this._conversion._mysql) { 45 this._conversion._sourceConString.connectionLimit = this._conversion._maxDbConnectionPoolSize; 46 const pool = mysql.createPool(this._conversion._sourceConString); 47 48 if (!pool) { 49 generateError(this._conversion, '\t--[getMysqlConnection] Cannot connect to MySQL server...'); 50 process.exit(); 51 } 52 53 this._conversion._mysql = pool; 54 } 55 }
5 function MySQL(host, user, password, database) { 6 return mysql.createPool({ 7 connectionLimit: 20, 8 host, 9 user, 10 password, 11 database, 12 }); 13 }
124 async execQuery(sql, name = 'SQL', binds = [], options = {}) { 125 const prepare = options.prepare || false; 126 // if (this.withoutPreparedStatement(binds)) { 127 // } 128 129 // TODO: without_prepared_statement? 130 const result = binds.length 131 ? await this.executeStmt(sql, name, binds) 132 : await this.execute(sql, name); 133 134 return result; 135 }