美文网首页sequelize
Sequelize | 0. 初始化

Sequelize | 0. 初始化

作者: ShadowFieldEric | 来源:发表于2021-01-06 17:15 被阅读0次

    安装

    npm install --save sequelize
    

    初始化使用

    const { Sequelize, Model, DataTypes } = require('sequelize');
    
    const sequelize = new Sequelize('db_stu', 'db_username', 'db_password', {
      host: '127.0.0.1',
      dialect: 'mysql',
      pool: {
        max: 50,
        min: 0,
        idle: 5000
      }
    });
    

    测试连接

    sequelize.authenticate()

    (async () => {
      try {
        await sequelize.authenticate();
        console.log('Connection has been established successfully.');
      } catch (error) {
        console.error('Unable to connect to the database:', error);
      }
    })()
    

    相关文章

      网友评论

        本文标题:Sequelize | 0. 初始化

        本文链接:https://www.haomeiwen.com/subject/akhkoktx.html