TryGhost / node-sqlite3

SQLite3 bindings for Node.js
BSD 3-Clause "New" or "Revised" License
6.2k stars 813 forks source link

atom-shell #357

Closed daiyam closed 3 years ago

daiyam commented 9 years ago

Hi,

How can I compile node-sqlite3 for atom-shell? I want to use it in the web-page side to avoid any unnecessary ipc call.

Thx

bengotow commented 9 years ago

Hi @daiyam were you able to get this working? I'm interested in doing this too. I'll let you know if I make any headway.

daiyam commented 9 years ago

I'm using a wrapper around sqlite3 like dblite without its bugs. But the performance isn't that great: half the speed of node-sqlite3 due to the extra parsing and the error handling.

kkaefer commented 9 years ago

Please see https://github.com/atom/atom-shell/blob/master/docs/tutorial/using-native-node-modules.md

daiyam commented 9 years ago

I tried...

$ export ATOM_NODE_VERSION=0.18.2
$ apm install .

will give out

> sqlite3@3.0.2 install /Users/.../node-sqlite3-master
> node-pre-gyp install --fallback-to-build

Unsupported target version: 0.18.2

node-pre-gyp ERR! install error 
node-pre-gyp ERR! stack Error: Unsupported target version: 0.18.2

or

$ node-gyp rebuild --target=0.18.2 --arch=x64 --dist-url=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist
gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1

or

$ ./node_modules/.bin/node-pre-gyp build --target=0.18.2 --arch=x64 --dist-url=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@0.5.31
node-pre-gyp info using node@0.11.14 | darwin | x64
node-pre-gyp ERR! UNCAUGHT EXCEPTION 
node-pre-gyp ERR! stack Error: Unsupported target version: 0.18.2
Mithgol commented 9 years ago

That's because the issue mapbox/node-pre-gyp#110 is not yet closed (in other words, because node-pre-gyp does not support Atom Shell as a target yet).

bengotow commented 9 years ago

I was curious about how Mapbox was using SQLite inside their Mapbox Studio app (an atom-shell application). It looks like they're still using atom-shell 0.16.x, which happened to define the node_ami version number as "16", which matches up with an available binary in node-pre-gyp. I don't fully understand the different versioning approaches used in node-pre-gyp. I'm not sure if 0.16.x is actually compatible or just happens to not fail. At any rate, it works and SQLite 3 is usable with atom-shell 0.16.x.

For technical reasons we can't move our project back to atom-shell 0.16.x, and we're stuck with 0.19.x, which has node_ami = 18. @Mithgol, if there's anything I can do to help close that issue, let me know!

springmeyer commented 9 years ago

Mapbox studio is not using atom shell and node-sqlite3 in the same process. The lack of binary compatibility with node was a major deterant. Because we have multiple node c++ addons and support multiple platforms having to provide 2x the binaries for atom-shell is not viable for us at this point. So Mapbox Studio is only using atom shell for the browser and not taking advantage of the ability to call into node modules.

Mithgol commented 9 years ago

@bengotow You can help by adding a commit or two towards the final goal of mapbox/node-pre-gyp#112.

bwin commented 9 years ago

You could also wait for PR https://github.com/mapbox/node-sqlite3/pull/369 and then manually build with node-gyp

npm install sqlite3 # or another way of obtaining source
cd node_modules/sqlite3
node-gyp rebuild --target=0.19.5 --arch=ia32 --dist-url=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist --module_name=node_sqlite3 --module_path=..\lib\binding

edit: corrected typo in snippet

bengotow commented 9 years ago

Thanks @bwin, @mithgol - I looked into the changes that needed to be made and figured it'd be best to wait for folks with a deeper understanding of the V8 headers and versioning involved to update things. In the meantime, we've started using the (deprecated) WebSQL API in Chromium. It's surprisingly performant (simple indexed SELECT queries in 1-2msec), and good enough for us to build on top of until the dust settles a bit with all this stuff. Thanks for the help - we'll be rolling onto node-sqlite3 as soon as we can!

max-mapper commented 9 years ago

I just wanted to chime in and say it would be super awesome if this worked with atom-shell out of the box!

springmeyer commented 9 years ago

Thanks @maxogden! - https://github.com/mapbox/node-pre-gyp/pull/112 is on my radar.

jasonhinkle commented 9 years ago

I was able to get sqlite3 working with Electron after install with the following. Note that the version numbers are hard-coded into the arguments which are Electron 0.27.1 and v43 (by the way anybody know where 43 come from? It seems to refer to modules versioning that is related to the version of Electron, but I can't find any translation of these numbers - the only way to find it is to just let your app throw an error and see what the foldername is that it's looking for.)

cd node_modules/sqlite3
npm run prepublish
node-gyp configure --module_name=node_sqlite3 --module_path=../lib/binding/node-v43-darwin-x64
node-gyp rebuild --target=0.27.1 --arch=x64 --target_platform=darwin --dist-url=https://atom.io/download/atom-shell --module_name=node_sqlite3 --module_path=../lib/binding/node-v43-darwin-x64
max-mapper commented 9 years ago

43 is the NODE_MODULE_VERSION which is similar to the ABI version, node, iojs and electron all have their non-overlapping own version ranges that they increment whenever the native API changes. I don't think this is written down anywhere (i've been trying to get core people to document it)

ekryski commented 9 years ago

Gonna also throw in my hat. Would love to see this work out of the box. I can confirm that @jasonhinkle's solution does work.

I still haven't tried with ASPM as documented here. I tried with electron-build but it didn't seem to work as my require statement still bombed but I didn't dig any deeper there.

olimsaidov commented 9 years ago

For anyone having same issue: http://verysimple.com/2015/05/30/using-node_sqlite3-with-electron/

ekryski commented 9 years ago

@olimsaidov Nice! I should have written something up myself. I have the exact same process going on Delicious. Works perfectly. Pretty much the same process for compiling any native lib, other dbs included.

thefinn93 commented 9 years ago

Lots of these have the word "darwin" in them (and aren't working for me), are they mac-specific?

ekryski commented 9 years ago

@thefinn93 Yes. You need to specify which platform you are targeting. I haven't built for other platforms just yet, so I'm not entirely sure what options you need to change.

jasonhinkle commented 9 years ago

The target_platform and target_arch need to be changed for your environment - the options can be found at https://www.npmjs.com/package/node-pre-gyp

zcbenz commented 9 years ago

Refs https://github.com/mapbox/node-pre-gyp/pull/175.

springmeyer commented 9 years ago

@zcbenz - thank you for mapbox/node-pre-gyp#175 - it is now merged and part of node-pre-gyp v0.6.12. Would it be possible for you to create a pull that starts building binaries for electron on travis?