What i’m doing is an addon, that fetches data from a website and stores it in a database in our local Network. So that you can access data from every computer in this Network.
What i tried to do is to connect to an sqlite database but everything I found seamt to be old and didn’t work.
Last thing I tried was to install a node.js module named “sqlite3” into the addon. That worked fine.
Is that a right way to access a sqlite db? If not, can anyone give me an introduction or a tutorial link or something like that, that helps me connecting to a sqlite?
If using the node.js module is a good way, how can i solve the error?
What I think is causing this error is simply that Firefox isn’t Node.js
Most node modules are going to be dependent on Node.
What the “node_pre_gyp” module is doing is requiring the module “path”, a core module of node and not a module of Firefox.
You should look for a SQLite library that is meant for the front-end instead of the back-end.
To use sqlite from an addon, you can use the Sqlite.jsm javascript code module. From an sdk addon, you might need to load the Components.utils object as described here.
No, don’t know why it would.
Unless the the node module isn’t dependent on anything of Node itself.
They both use the CommonJS standard, so that part should be compatible.
Maybe you are mixing up CommonJS and Node.js?
BTW, from looking at the links @Endyl posted, it seems that SQLite is focused on local storage.
Are you sure it’s sufficient for your use?
SQLite is a file-based db. It works without any db-server. I hope, i can give my add-on a filepath to the SQLite-file on one of our servers. So anybody in the company can use the addon and has access to the same data.
SQLite can have problems with databases exposed over the network depending upon how well the file-locking semantics are implemented by the file server/protocol in use. See https://www.sqlite.org/faq.html#q5 for more information.
Assuming it works, using a shared database directly like this can also lead to versioning problems. If you need to upgrade the schema of the database, you have to have some plan in-place for dealing with multiple versions of your add-on, etc. The simplest strategy would just be to switch to a new file/path whenever you issue a breaking schema change.
If you’d like to avoid compatibility and versioning issues, running a simple node.js app on a server on your network could work a lot better.
The first parameter to getFile() is not a path, but a “key” that indicates a particular special location. In most cases, use “ProfD” which indicates the profile directory for the currently running browser. Then you specify the filename in the second parameter, which you have done correctly. You can see a list of special location keys here: https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O#Getting_files_in_special_directories
If you want to specify an explicit path, you can do so to the FileUtils.File() constructor. Don’t do this because it isn’t platform independent. It is for rare cases where you might have obtained a native path by some means.
Well, since “V://Tools//data//” is not an “nsIDirectoryService key” (see a list of those here), you cannot use it in FileUtils.getFile().
As the documentation of FileUtils states, if you have an absolute path, you should use the File constructor like so:
var f = new FileUtils.File(mypath);
But that is not even necessary, because Sqlite.jsm expects a path to the database file (an absolute path, or a relative one (that is relative to the current profile directory)), not an nsIFile instance. So you don’t need to instantiate one, just give the path to Sqlite.jsm.
thank you for your answer. In my case, the Filepath is fix. This Addon is only for internal use, where I know, that all Users have the same Path to the File.
To create an nsIFile instance, yes, that is the way. But for Sqlite.jsm you only need something like this:
Sqlite.openConnection({ path: "V://Tools//data//SITop100.sqlite", sharedMemoryCache: false }).then(
function onConnection(connection) {
// connection is the opened SQLite connection (see below for API).
},
function onError(error) {
// The connection could not be opened. error is an Error describing what went wrong.
}
);
I would still recommend that you don’t specify a platform-dependant absolute path. openConnection will accept a relative path, relative to the profile directory. Use a link if you need to. You’ll be cursing that absolute path one day when v: has a different letter.
Thank you for the list, but i am really new to this topic, so for me it is really hard to understand, how to get my File from the Server.
I think, i understood, how to get Files from special directories like my profile, but how do i get a file from our internal network?
I don’t know, if i schould start a new thread, but another great gap in know how, belonging to this project, is to upload files on a ftp-server. Maybe, you can give me a first hint, where to find an example for file-Upload. If it doesn’t fit here, i will open an new thread for that. I only need a simple upload of defined files to a defined remote directory.
Ah ok if its a path on your network, you have no other choice then to use the hard coded path. if that path changes in the future (due to you guys changing your network) then you should update the addon