Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

81
Vistas
Elctronjs and SQLite 3 not returning last id

I am developing electron app with sqlite 3 Database. I would like to get Last inserted ID after save data in database.

i have run below query but call result always showing undefined. can anybody help me to solve this issue?

db.run(`INSERT INTO  myTable (data1, data2) VALUES (aa, bb)`, (err) => {
            console.log(this.lastID)
            if (err) {
                console.log(err)
            } else {

                console.log( this.lastID)
            }

Data base inserted successfully but result, this.lastID result is undefine.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It's because you are using arrow syntax. Arrow syntax setting the this context to the parent. You should do:

db.run(`INSERT INTO  myTable (data1, data2) VALUES (aa, bb)`, function (err)  {  
            console.log(this.lastID)
            if (err) {
                console.log(err)
            } else {

                console.log( this.lastID)
            })

The call, apply and bind methods are NOT suitable for Arrow functions -- as they were designed to allow methods to execute within different scopes -- because Arrow functions establish "this" based on the scope the Arrow function is defined within.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda