Hi

I'm creating a nodejs app and making use of the sqlanywhere module. Everything works great until I involve "Electron" to build a UI for this app. Is Electron supported by the sqlanywhere package?

I'm doing a very basic test, and sqlanywhere is throwing an error immediately when it is trying to load its drivers.

Here is my sample code:

const sqlanywhere = require('sqlanywhere');
const url = require('url');
const path = require('path');
const { app, BrowserWindow, Menu, Tray, ipcMain } = require('electron');

let conn = sqlanywhere.createConnection();

var conn_params = {
    Host  : 'localhost:2638',
    UserId  : 'user',
    Password: 'password',
    ConnectionPool: 'YES(MaxCached=10)'
};


conn.connect(conn_params, function(err) {

  if (err) throw err;

  conn.exec('SELECT * from mytable', function (err, result) {    
      if (err) throw err;  
      console.log(result[0]);      
      conn.disconnect();
  })
});



let mainWindow;

  app.on('ready', () => {

  console.log("Started...");

  // Create Window
  mainWindow = new BrowserWindow({
      width: 200,
      height: 200        
  });

  // Load HTML file into Window
  mainWindow.loadURL(url.format({
      pathname: path.join(__dirname, 'mainWindow.html'),
      protocol: 'file:',
      slashes: true
  }));

});

The error thrown is:

"Uncaught Exception: Error: Could not load modules for Platform: 'win32', Process Arch: 'x64', and Version: 'v7.9.0"

It seems to me that the way Electron is handling the 'require' statements in the sqlanywhere module is causing the problem. The value returned by db below is NULL whenever I include Electron in my app

    // ***************************************************************************
    // Copyright (c) 2017 SAP SE or an SAP affiliate company. All rights reserved.
    // ***************************************************************************
    var db = null;
    var driver_file = "sqlanywhere"

    var v = process.version;
    var match = v.match( 'v([0-9]+)\.([0-9]+)\.[0-9]+' );
    driver_file += '_v' + match[1];
    if( match[1]+0 == 0 ) {
        driver_file += '_' + match[2];
    }

    try {
        if( process.arch == "x64" ) {
        // db = require( "./../bin64/" + driver_file );
        console.log("DIR: " + __dirname);
        db = require( "/node_modules/sqlanywhere/bin64/" + driver_file );

        } else if( process.arch == "ia32" ) {
        db = require( "./../bin32/" + driver_file );

        } else {
        throw new Error( "Platform Not Supported" );
        }
    } catch( err ) {
        try {
        // Try finding natively compiled binaries
        console.log("Error thrown");
        console.log("DB: " + db);
        db = require( "./../build/Release/sqlanywhere.node" ); 
        } catch( err ) {
        throw new Error( "Could not load modules for Platform: '" + 
                process.platform + "', Process Arch: '" + process.arch +
                "', and Version: '" + process.version +"'" ); 
        }
    }
    module.exports = db;

Any help would be GREATLY appreciated!

Thanks

asked 29 Nov, 15:57

gandotee's gravatar image

gandotee
314
accept rate: 0%

edited 29 Nov, 15:58


It looks like external modules need to be rebuilt in order to be used with electron, and the error you're seeing is due to the fact that the sqlanywhere module wasn't rebuilt. We install pre-built binaries on Windows so we can't rebuild it in place. I'll have to do some more investigation and get back to you.

permanent link

answered 30 Nov, 08:21

Graeme%20Perrow's gravatar image

Graeme Perrow
8.7k374112
accept rate: 52%

Thanks this is exactly what it was - I was able to use electron-rebuild to rebuild the module.

The current version of node is 9.2 - sqlanywhere currently caters for drivers up to node 8.x. Do you know if there is a v9 driver in the works?

Many thanks

(03 Dec, 14:48) gandotee
Replies hidden

Excellent, I didn't think electron-rebuild would work but I'm glad it did. A v9 driver is in the works but I don't have an ETA.

(03 Dec, 21:40) Graeme Perrow
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×15

question asked: 29 Nov, 15:57

question was seen: 74 times

last updated: 03 Dec, 21:40