Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
What is a set analogue from squel.js in knex.js?

How can I rewrite it using Knex.js?

type === 'insert' ?
        sql = squel.insert()
            .set('id', userId)
            .set('type', 'open')
            .set('server', server)
            .set('created_at', timestamp)
            .set('updated_at', timestamp)
            .into('saved_users') :
        sql = squel.update()
            .table('saved_users')
            .set('updated_at', timestamp)
            .where(`id = "${userId}"`)

    for (const param in player) {
        if (param === 'full_response') continue;
        const value = player[param];
        if (param === 'kill') {
            sql.set(`\`${param}\``, value ?? 0)
        } else {
            sql.set(param, value ?? 0)
        }
    }

I'm using .set(..) to append the insert or update query. How to do it using Knex?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Something like that =/ Maybe it can better

const data = {}

    const query = knex("saved_users")

    for (const param in player) {
        if (param === 'full_response') continue;
        const value = player[param];
        if (param === 'kill') {
            data[param] = value ?? 0
        } else {
            data[param] = value ?? 0
        }
    }
    if (type === "insert") {
        data["id"] = userId;
        data["type"] = "open";
        data["server"] = server;
        data["created_at"] = timestamp;
        data["updated_at"] = timestamp;
        await query.insert(data)
    } else {
        data["updated_at"] = timestamp
        await query.update(data).where({
            id: userId
        })
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!