Sequelize Docs 中文文檔 v4
寫在前面
Sequelize 是一個基於 promise 的 Node.js ORM, 目前支持 Postgres, MySQL, SQLite 和 Microsoft SQL Server. 它具有強大的事務支持, 關聯關系, 讀取和復制等功能.
- Getting started - 入門
- Model definition - 模型定義
- Model usage - 模型使用
- Querying - 查詢
- Instances - 實例
- Associations - 關聯
- Transactions - 事務
- Scopes - 作用域
- Hooks - 鈎子
- Raw queries - 原始查詢
- Migrations - 遷移
- Upgrade to V4 - 升級到 V4
- Working with legacy tables - 使用遺留表
使用實例
(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'))
})();