資料庫
SQL 風格
var mysql = require('mysql')
var con = mysql.createConnection({
host: 'localhost',
user: 'yourusername',
password: 'yourpassword',
database: 'mydb',
})
con.connect(function(err) {
if (err) throw err
console.log('Connected!')
var sql = "INSERT INTO users (firstName, lastName) VALUES ('AILIN', 'LIOU')"
con.query(sql, function(err, result) {
if (err) throw err
console.log('1 record inserted')
})
})
ORM 風格
ORM (Object-relational mapping)
// sequelize
let user = await User.create({ firstName: 'AILIN', lastName: 'LIOU' })
資料庫
- SQLite
- RDBMS:MySQL / MariaDB, PostgreSQL, Microsoft SQL Server
選用哪一個模組
- Sequelize:支援 PostgreSQL, MySQL, MariaDB, SQLite and Microsoft SQL Server 資料庫
- Mongoose:支援 MongoDB