Node.js ORM Sequelize All In One
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/
public constructor(database: string, username: string, password: string, options: object)
const { Sequelize } = require('sequelize');
// Option 1: Passing a connection URI
const sequelize = new Sequelize('sqlite::memory:') // Example for sqlite
const sequelize = new Sequelize('postgres://user:pass@example.com:5432/dbname') // Example for postgres
// Option 2: Passing parameters separately (sqlite)
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: 'path/to/database.sqlite'
});
// Option 3: Passing parameters separately (other dialects)
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: /* one of 'mysql' | 'postgres' | 'sqlite' | 'mariadb' | 'mssql' | 'db2' | 'snowflake' | 'oracle' */
});
https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#instance-constructor-constructor
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
refs
https://github.com/sequelize/sequelize
https://github.com/prisma/prisma
https://github.com/typeorm/typeorm
https://www.imooc.com/u/index/notebook
©xgqfrms 2012-2024
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17713563.html
未经授权禁止转载,违者必究!
【推荐】中国电信天翼云云端翼购节,2核2G云服务器一口价38元/年
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 聊一聊 C#前台线程 如何阻塞程序退出
· 几种数据库优化技巧
· 聊一聊坑人的 C# MySql.Data SDK
· 使用 .NET Core 实现一个自定义日志记录器
· [杂谈]如何选择:Session 还是 JWT?
· 字节豆包,来园广告
· 【经验】几种数据库优化技巧
· 我用cursor, 半就开发了一个手机壁纸小程序,真的太强了
· 聊一聊 C#前台线程 如何阻塞程序退出
· 订单超时自动取消,我们是这样做的。。。
2022-09-19 SQL CONCAT All In One
2022-09-19 free piano music All In One
2022-09-19 SQL LIMIT All In One
2021-09-19 Flutter Widgets Refresh Indicator
2021-09-19 React Native Tutorial (2021) All In One
2021-09-19 StackOverflow sites All In One
2020-09-19 iPadOS 14 memoji 无法使用 bug