-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
best way to query the db in plugins #2240
Comments
You should not access the db directly or assume there is multiple tables or databases. You should use the db object provided ----- Reply message ----- Hello, How is the best way to query the DB (mysql in my case). I can see in several plugins that the easy way to query the db was like this: var db = require('../../src/node/db/DB').db, But it only works for the table 'store'. How can I ask to query another table, like users, groups,..? The plugin I'm trying to fix (ep_user_pad) manages it this way: var mysql = require('mysql'); exports.expressCreateServer = function (hook_name, args, cb) { But that way, etherpad crashes every x min (depending of the directive 'wait_timeout' of mysql) [ERROR] console - Error: Connection lost: The server closed the connection. I tried to fix the problem by closing the connection at the end of "exports.expressCreateServer", but then, it doesn't have an active connection on the next call and that creates a problem. Maybe it's possible to create and destroy the connection on each call, but it's a big file that manage lots of "args.app.get" & "args.app.post" calls. As, by using the DB lib instead of mysql lib, etherpad doesn't crash because of the wait_timeout directive, I was wondering if it's possible to choose the table on which you want to make the query? Thanks — |
I agree to that. But when using "../../src/node/db/DB", it then calls "var db = new ueberDB.database" that load "node_modules/ueberDB/mysql_db.js", and there, you can only query the table 'store', it's hardcoded in the functions get, set, findKeys, .. So how can I use DB and choose the table I need? |
Don't do that. Use the table provided else your plugin won't be supported I agree to that. But when using "../../src/node/db/DB", it then calls "var db = new ueberDB.database" that load "node_modules/ueberDB/mysql_db.js", and there, you can only query the table 'store', it's hardcoded in the functions get, set, findKeys, .. So how can I use DB and choose the table I need? — |
Well.. it's not that easy. It's a really nice plugin that manages users & groups to have public / private pads. He creates several tables to manage the users & groups credentials. I know there is a project by.. hmm.. a french organization I forgot momentarily the name... to create a similar plugin more robust and official (hopefully), but in the meantime, I would like to have this one working as, except this error because of the wait_timeout, it works very nicely. So, is it possible, by using DB & ueberDB to query other tables? |
The store table should be used for everything for portability. They made a poor design decision. |
Well, after having taking some times to think about this, I must say that I understand and agree completely with your point of view. I found a fork to that plugin that fixed the error. If the plugin from the french organization is not what I hope it will be, I guess I'll create a new fork to do it with the Db lib (the owner of the fork is not intereted by portability it seems) |
Hello,
How is the best way to query the DB (mysql in my case).
I can see in several plugins that the easy way to query the db was like this:
But it only works for the table 'store'.
How can I ask to query another table, like users, groups,..?
(I couldn't find a param to do that)
The plugin I'm trying to fix (ep_user_pad) manages it this way:
But that way, etherpad crashes every x min (depending of the directive 'wait_timeout' of mysql)
I tried to fix the problem by closing the connection at the end of "exports.expressCreateServer", but then, it doesn't have an active connection on the next call and that creates a problem.
Maybe it's possible to create and destroy the connection on each call, but it's a big file that manage lots of "args.app.get" & "args.app.post" calls.
As, by using the DB lib instead of mysql lib, etherpad doesn't crash because of the wait_timeout directive, I was wondering if it's possible to choose the table on which you want to make the query?
Thanks
The text was updated successfully, but these errors were encountered: