Sequelize logging questions marks instead of values after migrating to V5 - javascript

After migrating to v5 from v4, Sequelize logs question marks on the console instead of the values of the SQL queries.
For instance, this is what is shown on the console:
INSERT INTO `Product` (`uid`,`title`,`price`,`isPerishable`,`categoryId`) VALUES (?,?,?,?,?);
This is my Sequelize instance:
db = new Sequelize({
dialect: 'mysql',
database: process.env.DB_NAME,
username: process.env.DB_USER,
password: process.env.DB_PASS,
host: process.env.DB_HOST,
operatorsAliases: operatorsAliases,
logging: console.log,
});
Whether before, on version 4, the values were being displayed correctly.
What I am expecting to be logged is somethings like:
INSERT INTO `Product` (`uid`,`title`,`price`,`isPerishable`,`categoryId`) VALUES (DEFAULT,'iPhone X',999.99,false,'1');

You will still have the question marks, but you will see the input right next to the query.
Just add this to the Sequalize config
logQueryParameters: true

Related

Didn't I supply the dialect?

I'm trying to create a database with Sequelize. I keep getting this error.
Error: Dialect needs to be explicitly supplied as of v4.0.0
at new Sequelize
Here's my "new Sequelize" constructor (or whatever you call it):
var sequelize = new Sequelize("seqGenZoo_db", "root", {
host: "localhost",
dialect: "mysql",
pool: {
max: 5,
min: 0,
idle: 10000
}
});
Looks like the dialect is provided. What's the deal? I've installed the mysql and mysql2 nmp packages, if that means anything.
Error 1045 indeed means you have incorrect user/password pair. And according to the official documentation you should indicate database, username, password and options parameters:
public constructor(database: string, username: string, password: string, options: Object)

Im getting a unknown database error when i try to connect to my database nodejs

im creating a chrome extension and i keep getting this error
code: 'ER_BAD_DB_ERROR',
errno: 1049,
sqlState: '42000',
sqlMessage: "Unknown database 'blinkyblinky'",
sql: undefined
below is the code I'm using
const mysql = require('mysql2');
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
port: 3306,
database: 'blinkyblinky'
});
connection.query('SELECT * FROM userdata',
function(err, results, fields) {
console.log(err);
console.log(results);
console.log(fields);
}
);
this is the database I'm trying to connect to
so i was checking many thing i even create a db and a table and inserted values into it with javascript and it worked but when i checked locahost phpmyadmin none of the db i created was there i was like what hell so when i double check apparently it had been creating in my mysql workbench ๐Ÿ˜‚๐Ÿ˜‚๐Ÿ˜‚

How to save and read special characters in MySql? (Mysqljs & Node)

I got a node app that's connected directly to a mysql database v 8.18, charset utf8mb4 and collation utf8mb4_unicode_ci.
I'm trying to save special characters just like รค, รผ or รถ in some columns but within the database those values are changed into e.g. "รƒโ€“" or "รƒยถ", which as well results in them not being searchible anymore against the original input.
My connection is setup via the npm package mysqljs as followed:
db = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
port: process.env.DB_PORT,
charset: "utf8mb4_unicode_ci"
})
while running queries via db.query according to the documentation.
Question now is, what am I doing wrong and what might need to be changed for that to work.
After all I'm mainly creating a db that saves german and english data.
ADDITION:
Saving special characters in the db via UI (e.g. db forge Studio) gets me the following error: Incorrect string value: '\xD6sterr...' for column 'Name_de' at row 1
thanks a bunch for your input :)
Checkout this -->
https://medium.com/#haotangio/how-to-properly-setup-mysql-5-7-for-production-on-ubuntu-16-04-dd4088286016
https://mathiasbynens.be/notes/mysql-utf8mb4
problem is utf bytes style used in..
worked for me change from utf8 --> utf8mb4

Can't connect to MySQL with Sequelize

I consistently get a SequelizeConnectionRefusedError when trying to connect to a MySQL database on my server.
The login credentials are correct, the port is open, everything seems good (and works like a charm in the dev environment).
Sorry for the scarce background information, but I'm dumbfounded here - I really don't know what could be causing this problem.
This is my output from mysql --version
mysql Ver 14.14 Distrib 5.5.43, for debian-linux-gnu (x86_64) using readline 6.3
And this is the code I'm using to initialize Sequelize. The table I want it to use doesn't exist yet, but I'm fairly sure that hasn't got anything to do with this problem. I've tried logging in with the root user as well, but no dice - I still get the same error.
var sequelize = new Sequelize("database", username, password, {
host: "localhost",
dialect: "mysql",
port: 3306,
define: {
paranoid: true
}
});
var Model = sequelize.define("Model", {
md5: {type: Sequelize.STRING(128)},
ip: {type: Sequelize.STRING(256)},
url: {type: Sequelize.STRING(1024)}
});
sequelize.sync();
This is running on Ubuntu 14.04, where node is being run behind Passenger (although the error appears if I run the application with node directly as well). I'm running nginx and PHP on the same server, where another PHP application is connecting to the database, if that's of any relevance.
What could be causing this problem?
I tried to connect to the database directly with the MySQL module as well, but that gave me the same error. When looking for solutions to the same problem, but related to the MySQL module rather than Sequelize, I found this: connect ECONNREFUSED - node js , sql.
What I needed was to supply the mysql module with a socketPath key. Here's how I changed my code to make it work:
var sequelize = new Sequelize("database", username, password, {
host: "localhost",
dialect: "mysql",
logging: function () {},
pool: {
max: 5,
min: 0,
idle: 10000
},
dialectOptions: {
socketPath: "/var/run/mysqld/mysqld.sock"
},
define: {
paranoid: true
}
});

Connecting Postgres Heroku with Knex not working

We're having difficulty setting up a Heroku/Postgres database with Knex running our queries. We've set up our heroku/postgres db and created our tables, but we're having difficulty connecting to it with Knex. To make matters worse, there's almost no documentation on connecting Heroku/Postgres with Knex or any ORM so trying to figure this stuff out has been a real pain.
These are the connection patterns that I've tried.
var knex = require('knex')({
client: 'pg',
connection: {
user: username,
password: password,
host: host,
port: port,
database: database,
ssl: true
}
}
});
And... Note the ssl true was toggle and removed all together to no avail.
var knex = require('knex')({
client: 'pg',
connection: HEROKU_POSTGRESQL_COLOR_URL,
ssl: true
}
});
We've also tried this pattern as well:
var pg = require('knex')({
client: 'pg',
connection: HEROKU_POSTGRESQL_COLOR_URL
});
We haven't yet pulled down a copy of our localdb, so every test we run is basically a git commit. We're basically testing an insert query on a GET request to our root (index.html) page. So on any get request to the main page, it should insert something into our waterrates table. If I switch it from insert to select, it returns an object but you can't actually see any of the data in the object.
The inserts we're attempting to use are:
knex.select('*').from('waterrates').then(function(rows){
return rows;
});
knex('waterrates').insert({name: 'pleeeaseee work'}, {rate: 100}).then(function(rows){
console.log(rows);
})
knex.select().
We're actually uncertain where the error could be as attempting to connect doesn't yield any errors. It's probably something silly, but we have no idea where/how to troubleshoot this. Any help would be greatly appreciated!
Thanks,
B
I had an old version of PG installed which was causing the issue. We changed our package.json file to use the latest PG. Heroku updated it and it worked!
As a side note, if anyone looks at this in the future, heroku requires an SSL connection. Keep that in mind when you're working. The connection string that I provided above should work for you all.
B
For anyone who is dealing with this problem.
Please set "SSL" to false if you don't use paid dynos.
Heroku only assigns "SSL" to users who use paid dynos.
const db = knex({
client: 'pg',
connection: {
connectionString : process.env.DATABASE_URL,
ssl: false
}
});

Categories

Resources