sequelize dialectoptions , UTC and dates, for mysql - mysql

I am still learning how to use sequelize.
I am using sequelize 5 along with node 10 and mysql2 .
I am setting my connection like so
const sequelize = new Sequelize({
database: dbs,
username: usr,
host: hst,
password: pwd,
port: prt,
dialect: 'mysql',
dialectOptions: {
useUTC: true,
dateFirst: 1
},
define:{
timestamps:false,
paranoid:false,
freezeTableName: true
}
});
and I am getting the following warnings
Ignoring invalid configuration option passed to Connection: useUTC.
This is currently a warning, but in future versions of MySQL2, an
error will be thrown if you pass an invalid configuration option to a
Connection
Ignoring invalid configuration option passed to Connection: dateFirst.
This is currently a warning, but in future versions of MySQL2, an
error will be thrown if you pass an invalid configuration option to a
Connection
If I remove the useUTC: true and dateFirst: 1 from the dialectOptions, the errors obviously go away.
What am I missing and how can I set those options for mysql

Related

Error in sql connector configuration when connecting using Ballerina MYSQL Client

I'm trying to comment using Ballerina Mysql client.(Ballerina version - 0.990.2 ,MySQL JDBC driver-5.1.6) But I'm getting error as
error: error in sql connector configuration:Failed to initialize pool: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.:Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property. {}
mysql:Client testDB = new({
host: "localhost",
port: 3306,
name: "users",
username: "root",
password: "password",
poolOptions: { maximumPoolSize: 5 },
dbOptions: { useSSL: false }
});
I found the solution for the error. This is due to the mismatch in the mysql version and MySQL connector version. I downloaded the suitable version from http://central.maven.org/maven2/mysql/mysql-connector-java/

Sequelize ORM: How to connect to MYSQL on localhost, using the 'host' property?

I'm trying to connect to my local MYSQL(ran by XAMPP) through Sequelize:
const sequelize = new Sequelize(process.env.MYSQL_DB, 'root', '', {
host: process.env.CLEARDB_DATABASE_URL,
dialect: 'mysql',
logging: false
});
The process.env.CLEARDB_DATABASE_URL variable is set to "localhost", just like the documentation says(i'm using this specific variable because i want to deploy to Heroku later)
I'm getting the following error:
getaddrinfo ENOTFOUND localhost'; localhost';:3306
The process.env.MYSQL_DB variable is just the name of my database.
It all worked when i was using the "short way" to connect:
var sequelize = new Sequelize(process.env.MYSQL_DB , "root", "", {
dialect:'mysql',
logging: false
});
Can someone tell me what might be wrong with my setup?
EDIT: if anybody is interested, the problem was that i put a semicolon after the variable deceleration in my .env file.......

Slaves not used in Symfony 4 with Raw Queries

I'm using Symfony 4 to interface with an existing Master/Slave MySQL setup and am executing queries against the server using raw sql. Raw SQL is the only option at the moment.
I'm using show full processlist; on the DB server to monitor which DB is used, and I am only seeing connections to the master server. It doesn't appear that any of the slaves are ever used.
For reference, I have two dbal connections setup, the default is NOT master/slave, and uses orm mapping. The second is the master/slave which I'm having issues with, and this is the server I'm executing raw sql queries against.
Below is my doctrine.yml:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: "%env(DATABASE_HOST)%"
dbname: "db1"
user: "%env(DATABASE_USER)%"
password: "%env(DATABASE_PASS)%"
charset: UTF8
ds:
driver: pdo_mysql
host: "%env(DS_DATABASE_HOST)%"
dbname: "db2"
user: "%env(DS_DATABASE_USER)%"
password: "%env(DS_DATABASE_PASS)%"
slaves:
slave1:
host: "%env(DS_DATABASE_SLAVE1_HOST)%"
user: "%env(DS_DATABASE_USER)%"
password: "%env(DS_DATABASE_PASS)%"
dbname: "db2"
slave2:
host: "%env(DS_DATABASE_SLAVE2_HOST)%"
user: "%env(DS_DATABASE_USER)%"
password: "%env(DS_DATABASE_PASS)%"
dbname: "db2"
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
Main:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Main'
prefix: 'App\Entity\Main'
alias: Main
ds:
connection: ds
I have configured my entity managers in my services.yml as follows:
# Entity managers
App\Service\Database\MainEntityManager:
arguments:
$wrapped: '#doctrine.orm.default_entity_manager'
App\Service\Database\DSEntityManager:
arguments:
$wrapped: '#doctrine.orm.ds_entity_manager'
The entity manager (in this case DSEntityManager) is injected into the constructor of a class, then the query is executed as such:
$result = $this->em->getConnection()->prepare($sql);
$result->execute($args);
Please let me know if I'm missing any helpful configuration.
Thanks a lot for the help.
Thanks #Cerad for the tip, that got me in the correct direction. Since I was no longer trying to use an entity manager for raw queries that were not mapped to entities, I could work with the connection directly.
I Created a wrapper class which extended MasterSlaveConnection. That worked as long as I was using executeQuery(). Per the docs, that must be used to query the slaves. However, my query required the use of prepare() and query() which both force the master connection.
So inside my new wrapper class I created two new methods, prepareSlave() and querySlave() which do the same as the original; however, they do $this->connect('slave'); instead of $this->connect('master');
Now all my read queries hit slave and everything else hits master.
So here are the following updates I've made to the configuration above to achieve this:
doctrine.yml
ds:
driver: pdo_mysql
host: "%env(DS_DATABASE_HOST)%"
dbname: "db2"
user: "%env(DS_DATABASE_USER)%"
password: "%env(DS_DATABASE_PASS)%"
wrapper_class: "%env(DS_DATABASE_PASS)%"
slaves: App\Service\Database\DSWrapper
slave1: ...
services.yml
# DBAL connections
App\Service\Database\DSWrapper: '#doctrine.dbal.ds_connection'
My new wrapper class
class DSWrapper extends MasterSlaveConnection
{
public function prepareSlave($statement)
{
$this->connect('slave');
try {
$stmt = new Statement($statement, $this);
} catch (\Exception $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
}
$stmt->setFetchMode($this->defaultFetchMode);
return $stmt;
}
public function querySlave()
{
$this->connect('slave');
$args = func_get_args();
$logger = $this->getConfiguration()->getSQLLogger();
if ($logger) {
$logger->startQuery($args[0]);
}
$statement = $this->_conn->query(...$args);
if ($logger) {
$logger->stopQuery();
}
return $statement;
}
}
So now if I need to execute a query which would normally require the use of prepare() and query(), I instead use prepareSlave() and querySlave().

NodeJS: MySQL returns inaccurate decimal values

I've a MySQL database storing decimal values (DECIMAL(32, 12)).
When I select the values using HeidiSQL, the values are shown correctly (e.g. 15922.638440778302). But when I do the same in NodeJS using the MySQL binding (https://github.com/mysqljs/mysql), it shows me 15922.638440778303.
My SQL-Query is pretty simple:
SELECT SUM(`amount`) FROM `balances`;
Any idea what can cause the difference? Maybe do I need to specify the precision during the MySQL initialization in NodeJS? At the moment, I don't specify anything other than the login credentials:
let mysql = require('mysql').createPool({
host: global.dbconfig['dbhost'],
database: global.dbconfig['dbname'],
user: global.dbconfig['dbuser'],
password: global.dbconfig['dbpass']
})
Add below lines to your mysql config.
supportBigNumbers: true
bigNumberStrings: true
Then it becomes:
let mysql = require('mysql').createPool({
host: global.dbconfig['dbhost'],
database: global.dbconfig['dbname'],
user: global.dbconfig['dbuser'],
password: global.dbconfig['dbpass'],
supportBigNumbers: true,
bigNumberStrings: true,
})
More info on connection options: docs

Unable to connect to MAMP MySQL database using Wakanda's remote connection

I'm trying to connect to a MAMP MySQL database from Wakanda 11.
I tried connecting to the localhost database using Connect to Remote Datastore but I keep getting a Connection failed response. I've also tried using port 127.0.0.1:8081 which it connects to but not when attempting to use port:3306 which is where I have the MySQL database configured on the MAMP server. What am I doing wrong?
I've tried the following script...
model.addSQLCatalog("mysqldb", {
hostname: '127.0.0.1',
port: 3306,
user: 'root',
password: 'xxxxxxxx',
database: 'my_database_name',
ssl: false,
dbType: 'mysql'
});
...but this gives me the following error:
TypeError: JSON.stringify cannot serialize cyclic structures.
How can I fix and make it work on port:3306 so I can see my database structures?
If you are using Wakanda Enterprise Edition 11 or higher there is a MySQL Connector Pro.
Here is an example of connecting with this:
model.mergeSQLCatalog(localName, {
hostname: string 'host name',
port: number remote_port_number,
user: string 'userName',
password: string 'password',
database: string 'SQL database name',
jsFile: string 'configuration JavaScript file',
ssl: boolean true or false,
dbType: string 'mysql' } )
If you are on an older version of Wakanda Enterprise Edition but still using version 7 or higher then there is a Wakanda/MySQL connector.
Here is an example of connecting to MySQL with the connector:
var sql = require('waf-sql');
//use port 3306 and do not use SSL
var dbconn = sql.connect('mysql','192.168.0.21', 'john', 'x54?hsf5x!','arts',3306,false);
var rs = dbconn.update("people", {
name: "smith",
age: 42
}, {
id: 1
});
var rs = dbconn.select("*", "people", {
id: 1
});
var row = rs.getNextRow(); // get the first row
dbcon.close(); // close connection
Here is an example of the available parameters:
var params = {
hostname: [your host name or IP address],
user: [the user name of your DB],
password: [the user password],
database: [the DB name],
port: [the port number of the MySQL Server, by default 3306],
ssl: false,
dbType : 'mysql'
};
If I'm correct your issue has been solved? Does it work for both Windows & Mac ?
To resume , to use ProCOnnector you'll need :
The Enterprise Version of Wakanda
For the current v11 version of Wakanda, you need to use in the model.js file the addSQLCatalog() API.
The parameters accepted are described in the doc
Please note in the next version of Wakanda we 'll provide to wizzard to connect to other DBs instead of the addSQLCatalog(). This will help and ease the process.