Linked Questions

Popular Questions

I'm parsing many text files and inserting data into a table. For one type of file, I need to split the file between two tables. Table A, has a SysId:integer and MyId: integer. Table B has NewId: integer and MyId: Integer. I'm simplifying this as there are many other fields, but these are key. Table A will only have a single instance of MyId. Table B will have multiple instance, so it's one to many. I query MyId in Table A first. if my function returns -1, then it's safe to add. If it doesn't, I get the MyID value, to use to post the many records in Table B. The problem I'm having, is the function I have, never returns anything.

I try to get the Id


But this function never returns anything

Here's the function.

function GetId(pMyId) {
    db.any('SELECT myid FROM mytable WHERE myid=$1', [pMyId])
    .then(function(data) {
        if (data.length>0) {
            return data[0].myid
    .catch(function(error) {
        // error;

Whenever I check FoundMyId, it is undefined.

I realize this is probably an issue with everything running Asynchronously, but there must be a way to do this.

Related Questions