xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Node.js ORM Sequelize All In One

Node.js ORM Sequelize All In One

Sequelize is an easy-to-use and promise-based Node.js ORM 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://sequelize.org/

https://www.npmjs.com/package/sequelize

image

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, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(6)  评论(2编辑  收藏  举报
编辑推荐:
· 聊一聊 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
点击右上角即可分享
微信分享提示