forbeslindesay / sync-mysql Goto Github PK
View Code? Open in Web Editor NEWMake synchronous queries to a mysql database
License: MIT License
Make synchronous queries to a mysql database
License: MIT License
~I use Google translate
After I make a query to mysql, the userid parameter is distorted, meaning instead of 282799894585147392, I get 282799894585147400
Does Pool Connection work on your module?
Also, is there a connection pool?
I want to access the fields property after I have made a query. In the normal async mysql package this would be the third argument passed into the callback of the query-function.
The current implementation always only returns the result-rows. To enable it to return both, the result-rows and the fields, the then-mysql package (also authored by you) would have to be changed as well. In connection.js only a small change would have to be made to the lines 45-47, so when the Promise is resolved it also returns the fields. However, in order not to break existing code, either a second version of the query-method would have to be added which is nearly a clone of the existing one, or you could add a parameter that defaults to the current behaviour, but can be configured so the promise returns e.g. an object like { result, fields }.
With that change in then-mysql, it would be easy to adapt sync-mysql to work with it.
I could write that myself and provide a PR, but I'm not sure in what style you would like the change to be implemented.
Hi,
how can I get the rows-object from a query?
Thanks for your reply!
Hello! How to set another encoding on connection from nodejs?
How can I escape a Query?
This doesn't work;
connection.query('SELECT * FROM channels WHERE id = ' + connection.escape(id) + ' LIMIT 1');
Thanks for your toolkit.
can use multiple inserts?
connection.query("INSERT INTO table(title
,content
) VALUES ?", [ ['title', 'content'],[...] ])
It's a pretty dumb question, sorry. Still I do need to get the result, meaning what MySQL command line client would return as "<this many rows> were affected", or "Error: <error message>". Or, if you would, what the Workbench calls "Action Output". The regular node js means like the following:
db_conn.query('USE <db name>', (db_err, db_res) => {
if (db_err) {
console.log(db_err);
} else {
console.log(db_res);
}
});
... do not seem to be working here.
Thanks!
@ForbesLindesay
As we can end the connection in all other async based mysql node modules by using the "connection.end()" but in "sync-mysql" we don't know how to end it.
As i said in title.
Where i can select db?
cause it shows this error: ER_NO_DB_ERROR
Can You, please explain how to call the proc properly using your module? Thank You in advance!
For exmple i try to run the next:
db.call(procs.registration, "hello");
and have the next feedback from node:
TypeError: Expected args to be strings
at Connection.call (/aut/ufo/node_modules/sync-mysql/lib/index.js:43:15)
at Object.<anonymous> (/aut/ufo/lib/test.js:23:4)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
I wanted to write so many data to my database. I have written queries to write to different tables. Is there any possible way to put all the queries inside a transaction, so that I can commit/rollback the queries ?
The example in the README file will throw an error:
TypeError: Expected args to be strings
at Connection.query (/home/krm/dev/sync-mysql-test/node_modules/sync-mysql/lib/index.js:63:15)
However the code below will work:
var MySql = require('sync-mysql');
var assert = require('assert');
var connection = new MySql({
host: 'localhost',
user: 'me',
password: 'secret'
});
const result = connection.query('SELECT 1 + 1 AS solution', []);
assert(result[0].solution==2);
Hi,
how can i catch database or query error with your library?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.