Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MariaDB response from Insert Statement

Iam currently building a small application and everything worked so far, but now Iam really confused about a return value.

Iam using a MariaDB Database with NodeJS and the mariadb connector. All the statments pass without failure, but when I send an INSERT Statement, the DB sends back this:

affectedRows:
1
insertId:
51n
warningStatus:
0

The Database is fine with the statement, but I dont get where the "n" behind the inserted ID is coming. The problem is, it breaks the complete application, because JSON.stringify() says:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    at JSON.stringify (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {stack: 'TypeError: Do not  know how to serialize a Big…ions (node:internal/process/task_queues:96:5)', message: 'Do not know how to serialize a BigInt'}

So it seems, that the DB sends back the ID, wich is the primary key of this table, as a BigInteger and JSON.stringify() can not parse this. But I dont want a BigInteger in the response.

Can anyone help me with this?
Thx in advance

>Solution :

You can pass options to the query method of the connection to return the insertId as string.

await conn.query(stmt, { supportBigNumbers: true, bigNumberStrings: true})

Alternately, you can return it as a Number. The method throws an exception if the insertId can’t be converted from a BigInt to a Number

await conn.query(stmt, { supportBigNumbers: true, insertIdAsNumber: true})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading