Skip to content

Missing symbol.iterator on RowDataPacket #918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
igortas opened this issue Feb 14, 2019 · 3 comments
Open

Missing symbol.iterator on RowDataPacket #918

igortas opened this issue Feb 14, 2019 · 3 comments

Comments

@igortas
Copy link

igortas commented Feb 14, 2019

Hi,

I'm making a refactoring to node.js project from callbacks to async await es7 feature, so in that refactoring stage I was migrating from mysql to mysql2 driver. I'm using mysq2/promise so everything works well with new async await keyword, but I have one small problem. When I'm returning promise<RowDataPacket[]> from select, update or insert i can't use for or loop.

export const selectAsync = async (
  sqlStatement: string,
  params: any[]
): Promise<mysql.RowDataPacket[]> => {
  try {
    const connection = await mysql.createConnection({
      host: config.mysql_credentials.db_host,
      user: config.mysql_credentials.db_user,
      password: config.mysql_credentials.db_password,
      database: config.mysql_credentials.db_database,
      multipleStatements: true
    });

    const [rows] = await connection.query<mysql.RowDataPacket[]>(
      sqlStatement,
      params
    );
    return rows;
  } catch (err) {
    console.log('Select query executing error', err);
    return;
  }
};

Now, when I use this selectAsync for example in some function and when the data are fetched from db I can't loop with for of loop when I execute multiples sql queries at once:

 for (let row of result[0]) {
        // some code
      }

result[0] or result[1] gives error that the RowDataPacket must have a symbol iterator. One workaround is to use forEach, but I don't like to change forEeach everywhere where I have for of loop already from previously when for of loop was working with mysql driver.

BR, Igor

@sidorares
Copy link
Owner

though a bit different to your error, I do have plans to add async iterators: #822 (comment)

api might look similar to this example:

const rows = connection.streamQuery(sqlStatement, params);
for await (const row of rows) {
   console.log(row); 
}

@S0c5
Copy link

S0c5 commented Jun 16, 2021

Hey @sidorares, how is going the plan to give streamQuery into the current MySQL2 API

@gordonwho
Copy link

What's the status on this ticket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants