-
Notifications
You must be signed in to change notification settings - Fork 2
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
db.lastID is undefined #4
Comments
@ElectroDr3am hey, are you sure you were using Or have you tried: stmt = db.prepare('INSERT INTO foo VALUES (?)')
stmt.run(params, err => {
console.log(err, stmt.lastID)
}) I've just tried (It would take me some time to test it in Windows.) Ref: |
I'm using Electron and Vue.js and create connection in main process like
that
(for test i've changed to `node-sqlite`)
sqlite3 = require('sqlite3')
// else
// sqlite3 = require('cross-sqlcipher')
let db = new sqlite3.Database('db.db')
global.DB = db
then get it from render
let remote = window.require('electron').remote
DB = remote.getGlobal('DB')
Vue.prototype.$db = DB
and using in vue js component
methods: {
createTicket:function () {
this.$db.run(`INSERT INTO foo...`,
{
//params
}, function (err) {
console.log(this.lastID, this)
// that's the point
})
.get('SELECT last_insert_rowid() as id', (err, row) => {
console.log(row.id)
})
}
}
The point I've specified `this` is some global variable, I think it is the
whole App variable.
Maybe you can provide example of better use of node-sqlite?
Thanks.
2017-10-04 7:25 GMT+03:00 Fritz Lin <[email protected]>:
… @ElectroDr3am <https://github.com/electrodr3am> hey, are you sure you
were using function (err) {} instead of err => {}?
Or have you tried:
stmt = db.prepare(sql); stmt.run(params, err => { stmt.lastID })
I've just tried cross-sqlcipher in both node and electron, Mac.
(It would take me some time to test it in Windows.)
Ref:
- TryGhost/node-sqlite3#100
<TryGhost/node-sqlite3#100>
- TryGhost/node-sqlite3#622 (comment)
<TryGhost/node-sqlite3#622 (comment)>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AbiXsK0p2pnoPwkNNIgEXxosRGpcxeHOks5sowi6gaJpZM4Pm7kh>
.
|
Oh you are using electron's remote and Vue stuff, I'm not quite sure. |
Nope, I've tryied your advice, but same result. Nevermind, I'm working of
small enought project so I can simply query SELECT last_insert_rowid()
as idafter
every INSERT if I need it. Thanks for reply!
2017-10-04 11:18 GMT+03:00 Fritz Lin <[email protected]>:
… Oh you are using electron's remote and Vue stuff, I'm not quite sure.
I suggest you to use stmt.lastID syntax. You can try it instead.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AbiXsLuv0AcrpXQqjQGIszRbz53gW4Sjks5soz9NgaJpZM4Pm7kh>
.
|
@ElectroDr3am hah.. anyway I have another advice... You can send ipc messages between them, and don't have to use |
Thanks for advice, I'll consider refactoring my app using that idea.
I think it's worth it and may be usefull to avoid such troubles like I've
got.
2017-10-05 17:27 GMT+03:00 Fritz Lin <[email protected]>:
… @ElectroDr3am <https://github.com/electrodr3am> hah.. anyway I have
another advice...
Personally I think the logic business (db query) should be placed in the
main process,
and you turn off the webPreference.nodeIntegration in renderer processes.
You can send ipc messages between them, and don't have to use
remote.getGlobal,
it could be the ideal model of an electron app?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AbiXsIsfnD9_2BymkH-qNvBuF3lNabfPks5spOdegaJpZM4Pm7kh>
.
|
By the way I've tested using sqlite from main process and it works
correctly as described in docs.
|
@ElectroDr3am does it work for you? with cross-sqlcipher |
@fritx Sorry for offtop but does cross-sqlcipher support Promicess? Maybe you can you provide some example? Thanks
|
Code
db.run('INSERT INTO foo ...', function (err) { console.log(err, this.lastID) })
prints
null undefined
Using Electron 1.8
What am I doing wrong?
The text was updated successfully, but these errors were encountered: