How to use the format function from mysql

Find comprehensive JavaScript mysql.format code examples handpicked from public code repositorys.

41
42
43
44
45
46
47
48
49
50
if (err) throw err;

// search for existing users in db
const sqlSearch =
  "SELECT * FROM accounts WHERE username = ? AND activestatus = 'active'";
const search_query = mysql.format(sqlSearch, [username]);

await connection.query(search_query, async (err, result) => {
  // connection.release(); // to prevent pool from being depleted
  if (err) throw err;
fork icon0
star icon0
watch icon1

+ 13 other calls in file

62
63
64
65
66
67
68
69
70
71
pool.getConnection(async (err, connection) => {
  if (err) throw err;

  // Check if application already exists in DB
  const applicationSearch = "SELECT * FROM application WHERE app_acronym = ?";
  const applicationSearchQuery = mysql.format(applicationSearch, [
    app_acronym,
  ]);

  // Add application details into application db
fork icon0
star icon0
watch icon1

+ 3 other calls in file

196
197
198
199
200
201
202
203
204
205
async insert(table, params) {
    console.log(`[SQL][INSERT] ${table} -- ${JSON.stringify(params)}`)
    if (params === undefined || Object.values(params).length < 1) {
        throw new DataBaseError({ code: 'DB_MYSQL_WHERE', message: 'INSERT params Undefined' })
    }
    const query = mysql.format(`INSERT INTO ?? (??) VALUES (?)`, [table, Object.keys(params), Object.values(params)])
    return await this.query(query, {})
}

async update(table, params, where) {
fork icon0
star icon0
watch icon1

+ 11 other calls in file