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

Problem with mysql module #39

Open
carambuco opened this issue Dec 25, 2018 · 1 comment
Open

Problem with mysql module #39

carambuco opened this issue Dec 25, 2018 · 1 comment

Comments

@carambuco
Copy link

carambuco commented Dec 25, 2018

Hi!
I'm experiencing trouble trying to use node-mysql within a pixiedust-node project.

The cell setup is the following:

import pixiedust_node
npm.install('mysql')

This works as expected showing the logos of both pixiedust and pixiedust node and then the stats of the module install.
The problem comes with the nodejs part. The code works perfectly in a nodejs project, but not within pixiedust-node:

%%node
var mysql = require('mysql');
var dburl = 'database-url.com';
var con = mysql.createConnection({
  host: dburl,
  user: 'dbuser',
  password: 'dbpassword',
  database: 'dbdatabase'
});
con.connect(function(err) {
    if (err) throw err;
});
var query ='SELECT user_created_date from user LIMIT 100';
con.query(query, function (err, result, fields) {
            if (err) throw err;
            console.log(result);
});
con.end();

I write it down here as a single block, but I've tried it in different cell layouts to find more precisely where the error is located. And it is located in the mysql.createConnection() call:

... ... ... ... ... TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
at globalVariableChecker (/home/javier/anaconda3/lib/python3.7/site-packages/pixiedust_node/pixiedustNodeRepl.js:26:22)
at REPLServer.writer (/home/javier/anaconda3/lib/python3.7/site-packages/pixiedust_node/pixiedustNodeRepl.js:67:5)
at finish (repl.js:683:38)
at finishExecution (repl.js:310:7)
at REPLServer.defaultEval (repl.js:396:7)
at bound (domain.js:395:14)
at REPLServer.runBound [as eval] (domain.js:408:12)
at REPLServer.onLine (repl.js:639:10)
at REPLServer.emit (events.js:182:13)
/home/javier/anaconda3/lib/python3.7/site-packages/pixiedust_node/pixiedustNodeRepl.js:26
const j = JSON.stringify(r.context[v]);
^
TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
at Timeout.globalVariableChecker [as _onTimeout] (/home/javier/anaconda3/lib/python3.7/site-packages/pixiedust_node/pixiedustNodeRepl.js:26:22)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at unrefdHandle (timers.js:520:7)
at Timer.processTimers (timers.js:222:12)
@glynnbird
Copy link
Member

Try declaring your "global" things as const instead of var. i.e. your identifiers mysql, dburl, con and query can all be consts instead of vars.

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

No branches or pull requests

2 participants