How to use the mysql.format function in mysql

To help you get started, we’ve selected a few mysql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jojoin / TribeDB / lib / mysql / build.js View on Github external
function partitions(err, parts){
		if(err){
			return callback(err);
		}
		//如果没有分表,则直接删除
		if(!parts){
			var sql = queryHead+'`'+obj._table+'` SET ?'+buildCondition(obj);
			return complete(mysql.format(sql, obj._data));
		}
		//分表,采用 union 子查询
		for(var p in parts){
			var one = parts[p]
			  , rtb = one[0]
			  , whe = one[1]
			  , exc = (whe===null ? null : tbconf.divide) //忽略分区键条件
			  , condition = buildWhere(obj, exc, whe)+buildLimit(obj)
			  , sql = queryHead+rtb+' SET ?'+condition;
			// 单表删除语句
			sqls.push(mysql.format(sql, obj._data));
		}
		// console.log(unionsql);
		// 返回 sql
		return complete(sqls.length==1?sqls[0]:sqls);
	}
github jolav / codetabs / __old-version / _lib / stats.js View on Github external
function insertHit (data) {
  let sql = 'INSERT INTO ?? (time, alexa, loc, stars, proxy, headers, weather)';
  sql += ' VALUES (?, 0, 0, 0, 0, 0, 0)';
  sql += ` ON DUPLICATE KEY UPDATE ${data.service} = ${data.service} + 1;`;
  const inserts = [MY_TABLE, data.time];
  sql = mysql.format(sql, inserts);
  con.query(sql, function (err, rows) {
    if (err) {
      console.log('Insert HIT error =>', err);
    // throw err
    } else {
      // console.log(rows)
    }
  });
}
github Bjorn248 / graphql_aws_pricing_api / lambda / lambda.js View on Github external
}
            var queryIdentifiers = [];
            queryIdentifiers.push(tableName);
            if (Object.keys(args).length !== 0) {
                queryString += " WHERE ";
                Object.keys(args).forEach(function(arg, index) {
                    if (index > 0) {
                        queryString += " AND ";
                    }
                    queryString += "?? = ?";
                    queryIdentifiers.push(arg);
                    queryIdentifiers.push(args[arg]);
                });
            }
            queryIdentifiers.unshift(selectionColumns);
            queryString = mysql.format(queryString, queryIdentifiers);
            console.log(queryString);
            return poolPromise.query(queryString);
        };
    }
github Limetric / OpenRCT2.org / src / base / database.js View on Github external
format(sql, inserts) {
        const mysql = require('mysql');
        return mysql.format(sql, inserts);
    }
}
github CIASIE-2018 / Le-6-qui-prend / node / src / controllers / controller.js View on Github external
const tryLogin = function(req, res) {
    let sql = mysql.format('SELECT * FROM `users` WHERE pseudo=?', req.body.pseudo);
    db.query(sql, function(err, result) {
        if (result.length !== 0) {
            bcrypt.compare(req.body.password, result[0].password, function(err, res_hash) {
                if (res_hash) {
                    req.session.pseudo = result[0].pseudo;
                    res.redirect("/home");
                } else {
                    res.redirect("/");
                }
            });
        } else {
            res.redirect("/");
        }
    });
}
github projectOpenRAP / OpenRAP / dbsdk2 / index.js View on Github external
params.table.fields.map((field, index) => {
        query = [
                    mysql.escapeId(field.name),
                    field.type,
                    field.isNullable ? ',' : 'NOT NULL ,',
                    query
                ].join(' ');

        if(field.isPrimary) {
            query += mysql.format('PRIMARY KEY (??)', field.name);
        }

        if(field.references !== undefined) {
            query += mysql.format(', FOREIGN KEY (??) REFERENCES ??(??)', [field.name, field.references.table, field.references.field]);
        }
    });
github XadillaX / Toshihiko / lib / engine / mysql.js View on Github external
MySQL.prototype.makeInsertSQL = function(table, object) {
    var sql = "INSERT INTO `{table}` SET ?".assign({ 
        table: table
    });
    return mysql.format(sql, object);
};
github aserg-ufmg / JSCity / js / server.js View on Github external
if(params.district>0) {
										format = ['tb_building', 'district_id', params.district];
									} else if(params.building>0) {
										format = ['tb_building', 'building_id', params.building];
									}
								break;
								default:
									responseObj.message = msg('Access Denied. {RAD}', JSON.stringify(params));
									writeEnd(JSON.stringify(responseObj), "application/json", 403);
									connection.release();
									return;
								break;
							}

							if(sSQL != '' && format !== null) {
								sSQL = mysql.format(sSQL, format);
								connection.query(sSQL, function(err, rows, fields) {
									if(err) {
										responseObj.message = msg('Internal Error. {FCBD}', err.message);
										writeEnd(JSON.stringify(responseObj), "application/json", 500);
									} else {
										responseObj.message = '';
										if(rows.length==1) {
											responseObj.register = rows[0];
										} else {
											responseObj.registers = rows;
										}
										if(debug) {
											responseObj.campos = fields;
										}

										writeEnd(JSON.stringify(responseObj), "application/json", 200, path.normalize(base + parsed.path));