Node.js ORM Sequelize All In One
Sequelize
is an easy-to-use and promise-based Node.jsORM
tool for Postgres,MySQL
, MariaDB, SQLite, DB2, Microsoft SQL Server, and Snowflake.
It features solid transaction support, relations, eager and lazy loading, read replication and more.
https://www.npmjs.com/package/sequelize
sqlite3
$ npm i sequelize sqlite3
# or
$ yarn add sequelize sqlite3
import { Sequelize, DataTypes } from 'sequelize';
const sequelize = new Sequelize('sqlite::memory:');
// DEFINE MODELS
const User = sequelize.define('User', {
username: DataTypes.STRING,
birthday: DataTypes.DATE,
});
// PERSIST
const jane = await User.create({
username: 'janedoe',
birthday: new Date(1980, 6, 20),
});
// QUERY
const users = await User.findAll();
https://sequelize.org/docs/v6/getting-started/
sequelize-cli
$ npm i -D sequelize-cli
$ npx sequelize --help
$ sequelize --version
$ sequelize db:migrate
$ sequelize db:seed
$ sequelize init
https://www.npmjs.com/package/sequelize-cli
demos
macOS
$ brew list | grep mysql
$ brew services list | grep mysql
Name Status User File
httpd error 256 xgqfrms-mm ~/Library/LaunchAgents/homebrew.mxcl.httpd.plist
mongodb-community@4.2 none xgqfrms-mm
php none
unbound none