The Wayback Machine - https://web.archive.org/web/20201121125408/http://github.com/bookshelf/bookshelf/issues/2060
Skip to content
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

electron.js remote and "Invalid knex instance" #2060

Open
panteo opened this issue Mar 3, 2020 · 6 comments
Open

electron.js remote and "Invalid knex instance" #2060

panteo opened this issue Mar 3, 2020 · 6 comments

Comments

@panteo
Copy link

@panteo panteo commented Mar 3, 2020

Introduction

Invalid knex instance if you require knex with electron.js remote.

Issue Description

Here https://github.com/bookshelf/bookshelf/blob/master/lib/bookshelf.js#L32 you check the name of knex instance, but if the instance is initialized with electron.js remote, the name is "remoteFunction".

Steps to reproduce issue

const remote = window.require('electron').remote;
const Knex = remote.require('knex');
const knex = Knex({
  client: 'sqlite3',
  connection: {
    filename: 'db.sqlite'
  }
});
const bookshelf = require('bookshelf')(knex);

Expected behaviour

The expected behaviour is without exception. Infact, I changed that line with: if (!knex) { and everything works as expected.

Actual behaviour

bookshelf.js:33 Uncaught Error: Invalid knex instance
    at Bookshelf (bookshelf.js:33)
@ricardograca
Copy link
Member

@ricardograca ricardograca commented Mar 3, 2020

What's a electron.remote?

@panteo
Copy link
Author

@panteo panteo commented Mar 3, 2020

Electron is an open source framework that allows for the development of desktop GUI applications using web technologies.

https://www.electronjs.org/

Electron remote let you use main process modules from the renderer process.

https://www.electronjs.org/docs/api/remote

Since web technologies does not have access to filesystem (and other native features), electron provides an inter-process communication layer with remote.

@ricardograca
Copy link
Member

@ricardograca ricardograca commented Mar 4, 2020

What kind of object is remote.require('knex') returning then?

@panteo
Copy link
Author

@panteo panteo commented Mar 4, 2020

It returns a knex object but for some reason, its name is remoteFunction instead of knex.

@ricardograca
Copy link
Member

@ricardograca ricardograca commented Mar 4, 2020

I'm not very comfortable changing the current behavior just for this corner case. If you can find a way to continue preventing people from passing random objects and ensuring only valid Knex instances are accepted I can accept a PR.

Also, why are you doing database access in the render process side? Doesn't Electron allow doing that on the remote side and then just send the needed data to the render process?

@panteo
Copy link
Author

@panteo panteo commented Mar 4, 2020

Ok, it makes sense. I will try to find a solution and i'll let you know in case of success, thank you.

I use the remote module just to save me a lots of manual ipc messages back and forth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.