@SanduCuragau wrote:
Cheers, I’ve seen around a couple of posts about doing this but I can’t figure out how to get it done in ionic and typescript
Here is my insert
/** * Inserir na DB */ public insert(appointment: Appointment){ return this.databaseService.getDB() .then((db: SQLiteObject) => { db.sqlBatch([ ["INSERT INTO Appointment (dia, horaInicial, horaFinal, description, area) values (?,?,?,?,?)", [appointment.dia, appointment.horaInicial, appointment.horaFinal, appointment.description, appointment.area]] ]) .then(() => console.log('Appointment inserido com sucesso.')) .catch(e => console.error('Erro ao inserir o Appointment', e)); }) .catch((e) => console.error(e)); }
From what I know I should be getting a variable in then and accessing the last inserted id from that variable, i tried some things but nothing worked, anyone has any idea how to do it?
EDIT: now that I think about it, optimally it would be amazing to get the ID exactly when I insert, while doing the insert, that way there will be no mistakes, imagine a database getting manyyy inserts at the same time, that thing of getting last inserted ID might be wrong, but yeah if that’s not possible to get ID when we insert, then I’ll do with get last inserted ID
Posts: 1
Participants: 1