MariaDB connection with Sequelize

前端 未结 2 764
旧时难觅i
旧时难觅i 2021-01-22 19:44

I have been checking for the connectivity of MariaDB, with Sequelize.

const Sequelize = require(\'sequelize\');

// Setting up database (MariaDB) connection
cons         


        
相关标签:
2条回答
  • 2021-01-22 20:10

    https://github.com/MariaDB/mariadb-connector-nodejs

    NPM

        npm install --save mariadb
        npm install --save sequelize@next
    

    Yarn

        yarn add mariadb
        yarn add sequelize@next
    
      const Sequelize = require('sequelize'),
        sequelize = new Sequelize(process.env.db_name, process.env.db_user, process.env.db_pass, {
        dialect: 'mariadb',
        dialectOptions: {
          socketPath: process.env.db_socket,
          timezone: process.env.db_timezone
        },
        pool: {
          min: 0,
          max: 5,
          idle: 10000
        },
        define: {
          charset: 'utf8',
          timestamps: false
        },
        benchmark: false,
        logging: false
      })
    
    0 讨论(0)
  • 2021-01-22 20:15

    MariaDB For MariaDB compatibility you have to install the package mariasql@0.1.20, or higher. The configuration needs to look like this:

    var sequelize = new Sequelize('database', 'username', 'password', {
      dialect: 'mariadb'
    })
    

    Or Try this:

    MariaSQL: https://www.npmjs.com/package/mariasql

    A node.js binding to MariaDB's non-blocking (MySQL-compatible) client library.

    var Client = require('mariasql');
    
    var c = new Client({
      host: '127.0.0.1',
      user: 'foo',
      password: 'bar'
    });
    
    c.query('SHOW DATABASES', function(err, rows) {
      if (err)
        throw err;
      console.dir(rows);
    });
    
    c.end();
    

    MariaSQL is recommended.

    0 讨论(0)
提交回复
热议问题