Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5929275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:24:03+00:00 2026-05-22T14:24:03+00:00

I am writing some non-web app helper, and came across a need for a

  • 0

I am writing some non-web app helper, and came across a need for a synchronous query call.

Basically, within a loop I need to check the database to see if the value exists. If it doesn’t then insert the value. Currently, with node-mysql I can only get it to work with a callback. Because of that, node.js treats the call as asynchronous and keeps processing my request before the query is finished. This is a big issue because in the end it could be inserting duplicates because they were in the queue.

Ideal Solution – doesn’t work. Results is actually the object of client, and I can’t find the actual results within. However this does make it synchronous.

results = client.query('SELECT COUNT(md5) as md5Count FROM table WHERE md5 = "' + md5 + '"')

The following does not work. Node.js treats it as asynchronous, and outerResult is still the object of client.

outerResult = client.query('SELECT COUNT(md5) as md5Count FROM board WHERE md5 = "' + md5 + '"',  function  selectCb(err, results, fields) {console.log(results);});

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:24:04+00:00Added an answer on May 22, 2026 at 2:24 pm

    Basically, within a loop I need to check the database to see if the value exists. If it doesn’t then insert the value.

    This is a problem best served with SQL. You don’t solve this problem by talking to the database repeatedly, you solve this problem by having SQL only insert where the index value doesn’t already exist.

    INSERT INTO mytable ( name, address ) 
    SELECT @name, @address FROM DUAL 
    WHERE NOT EXISTS (SELECT * FROM mytable WHERE name = @name, address = @address)
    

    This is a super simplified example, and not the most optimized. You can do the same thing here with sets of data, instead of record by record, if you like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sometimes when writing a class you'll need some helper methods that take care of
Reviewing a stack trace of a non-responsive web-app, I realized that some of the
I'm writing an app and I need to access some json data in the
Im writing some helper functions for a project im working on. I've always wanted
I'm writing a web app which is used a SaS. Each customer has their
We're writing an app that communicates with an internet-based CMS in JSON. Unfortunately, some
I am currently writing a non-web program using mostly python and have gotten to
I'm writing a web app that needs to use several ansi C functions to
Imagine you're writing a web app that will have 1 million users (they all
I'm writing some simple web apps in PHP/HTML/CSS/JS, and am looking for a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.