写在前面

Sequelize 是一个基于 promise 的 Node.js ORM, 目前支持 Postgres, MySQL, SQLite 和 Microsoft SQL Server. 它具有强大的事务支持, 关联关系, 读取和复制等功能.

使用实例

Basic usage - 基本用法

(async function () {
    const Sequelize = require('sequelize');

    const sequelize = new Sequelize('http_runner', 'root', '123456', {
        host: '127.0.0.1',
        port: 3306,
        dialect: 'mysql',
        timezone: '+08:00'
    })

    sequelize.authenticate().then(() => {
        console.log('连接成功')
    }).catch(err => {
        console.log('连接失败')
    });
    const User = sequelize.define('user', {
        username: Sequelize.STRING,
        birthday: Sequelize.DATE
    });

    await User.create({
        username: 'janedoe',
        birthday: new Date(1980, 6, 20)
    })
    let user = await User.findAll()
    console.log(user.get('firstName'))
})();

相关文章:

  • 2021-05-25
  • 2022-01-31
  • 2022-12-23
  • 2021-04-03
  • 2021-10-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-11
  • 2022-02-13
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
相关资源
相似解决方案