44
55[ ![ npm version] ( https://badgen.net/npm/v/@sequelize/core )] ( https://www.npmjs.com/package/@sequelize/core )
66[ ![ npm downloads] ( https://badgen.net/npm/dm/@sequelize/core )] ( https://www.npmjs.com/package/@sequelize/core )
7- [ ![ contributors] ( https://img.shields.io/github/contributors/sequelize/sequelize )] ( https://github.com/sequelize/sequelize/graphs/contributors )
8- [ ![ Open Collective] ( https://img.shields.io/opencollective/backers/sequelize )] ( https://opencollective.com/sequelize#section-contributors )
97[ ![ sponsor] ( https://img.shields.io/opencollective/all/sequelize?label=sponsors )] ( https://opencollective.com/sequelize )
8+ [ ![ Last commit] ( https://badgen.net/github/last-commit/sequelize/sequelize/main )] ( https://github.com/sequelize/sequelize )
109[ ![ Merged PRs] ( https://badgen.net/github/merged-prs/sequelize/sequelize )] ( https://github.com/sequelize/sequelize )
11- [ ![ semantic-release] ( https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg )] ( https://github.com/semantic-release/semantic-release )
12- [ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
10+ [ ![ GitHub stars] ( https://badgen.net/github/stars/sequelize/sequelize )] ( https://github.com/sequelize/sequelize )
11+ [ ![ node] ( https://badgen.net/npm/node/@sequelize/core )] ( https://www.npmjs.com/package/@sequelize/core )
12+ [ ![ License] ( https://badgen.net/github/license/sequelize/sequelize )] ( https://github.com/sequelize/sequelize/blob/main/LICENSE )
1313
1414> 此项目同步自 [ sequelize] ( https://github.com/sequelize ) / [ sequelize] ( https://github.com/sequelize/sequelize ) 项目.
1515>
16- > 更新日志请参阅: [ CHANGELOG] ( CHANGELOG.md )
17- >
18- > 由于v7之后文档结构调整, 计划重新翻译新版并调整文档结构.
16+ > 由于v7现阶段处于alpha阶段, 变更较为频繁, 生产环境建议使用v6
1917
20- Sequelize 是一个易用且基于 promise 的 [ Node.js] ( https://nodejs.org/en/about/ ) [ ORM 工具] ( https://en.wikipedia.org/wiki/Object-relational_mapping ) 适用于 [ Postgres] ( https://en.wikipedia.org/wiki/PostgreSQL ) , [ MySQL] ( https://en.wikipedia.org/wiki/MySQL ) , [ MariaDB] ( https://en.wikipedia.org/wiki/MariaDB ) , [ SQLite] ( https://en.wikipedia.org/wiki/SQLite ) , [ DB2 ] ( https://en.wikipedia.org/wiki/IBM_Db2_Family ) , [ Microsoft SQL Server] ( https://en.wikipedia.org/wiki/Microsoft_SQL_Server ) , [ Snowflake ] ( https://www.snowflake.com/ ) , [ Oracle DB ] ( https://www.oracle. com/database/ ) 和 [ Db2 for IBM i ] ( https://www.ibm .com/support/pages/db2-ibm-i ) . 它具有强大的事务支持, 关联关系, 预读和延迟加载,读取复制等功能.
18+ Sequelize 是一个易用且基于 promise 的 [ Node.js] ( https://nodejs.org/en/about/ ) [ ORM 工具] ( https://en.wikipedia.org/wiki/Object-relational_mapping ) 适用于 [ Postgres] ( https://en.wikipedia.org/wiki/PostgreSQL ) , [ MySQL] ( https://en.wikipedia.org/wiki/MySQL ) , [ MariaDB] ( https://en.wikipedia.org/wiki/MariaDB ) , [ SQLite] ( https://en.wikipedia.org/wiki/SQLite ) , [ Microsoft SQL Server] ( https://en.wikipedia.org/wiki/Microsoft_SQL_Server ) , [ Amazon Redshift ] ( https://docs.aws.amazon. com/redshift/index.html ) 和 [ Snowflake’s Data Cloud ] ( https://docs.snowflake .com/en/user-guide/intro-key-concepts.html ) . 它具有强大的事务支持, 关联关系, 预读和延迟加载,读取复制等功能.
2119
22- Sequelize 遵从 [ 语义版本控制] ( http://semver.org ) 和 [ 官方 Node.js LTS 版本] ( https://nodejs.org/en/about/releases/ ) . Sequelize v7 版本正式支持 Node.js ` ^14.17,0 ` , ` ^16.0.0 ` . 其他版本或可正常工作 .
20+ Sequelize 遵从 [ 语义版本控制] ( http://semver.org ) 和 [ 官方 Node.js LTS 版本] ( https://nodejs.org/en/about/releases/ ) . Sequelize v7 版本正式支持 Node.js ` >=18.0.0 ` .
2321
2422你目前正在查看 Sequelize 的** 教程和指南** .你可能还对[ API 参考] ( https://sequelize.org/api/v7/ ) (英文)感兴趣.
2523
@@ -29,9 +27,9 @@ Sequelize 遵从 [语义版本控制](http://semver.org) 和 [官方 Node.js LTS
2927
3028## 文档版本
3129
32- - [ v7 中文文档] ( https://github.com/demopark/sequelize-docs-Zh-CN/tree/master ) (开发版本 )
30+ - [ v7 中文文档] ( https://github.com/demopark/sequelize-docs-Zh-CN/tree/master ) (更新中 )
3331
34- - [ v6 中文文档] ( https://github.com/demopark/sequelize-docs-Zh-CN/tree/v6 ) (保持更新 )
32+ - [ v6 中文文档] ( https://github.com/demopark/sequelize-docs-Zh-CN/tree/v6 ) (视变更情况更新 )
3533
3634- [ v5 中文文档] ( https://github.com/demopark/sequelize-docs-Zh-CN/tree/v5 ) (停止更新)
3735
@@ -90,85 +88,72 @@ Sequelize 遵从 [语义版本控制](http://semver.org) 和 [官方 Node.js LTS
9088- [ TypeScript] ( other-topics/typescript.md )
9189- [ Resources - 资源] ( other-topics/resources.md )
9290
93- ## 安装
94-
95- ``` sh
96- # 使用 npm
97- npm install sequelize # 这将安装最新版本的 Sequelize
98- # 使用 yarn
99- yarn add sequelize
100- ```
101-
102- ``` sh
103- # 用于支持数据库方言的库:
104- # 使用 npm
105- npm i pg pg-hstore # PostgreSQL
106- npm i mysql2 # MySQL
107- npm i mariadb # MariaDB
108- npm i sqlite3 # SQLite
109- npm i tedious # Microsoft SQL Server
110- npm i ibm_db # DB2
111- npm i odbc # IBM i
112-
113- # 使用 yarn
114- yarn add pg pg-hstore # PostgreSQL
115- yarn add mysql2 # MySQL
116- yarn add mariadb # MariaDB
117- yarn add sqlite3 # SQLite
118- yarn add tedious # Microsoft SQL Server
119- yarn add ibm_db # DB2
120- yarn add odbc # IBM i
121- ```
122-
12391## 简单示例
12492
12593#### TypeScript
12694
127- ``` javascript
128- import { Sequelize , Model , DataTypes , InferAttributes , InferCreationAttributes } from ' sequelize' ;
129-
130- const sequelize = new Sequelize (' sqlite::memory:' );
95+ ``` typescript
96+ import {
97+ Sequelize ,
98+ Model ,
99+ DataTypes ,
100+ InferAttributes ,
101+ InferCreationAttributes ,
102+ } from ' @sequelize/core' ;
103+ import { Attribute } from ' @sequelize/core/decorators-legacy' ;
104+ import { SqliteDialect } from ' @sequelize/sqlite3' ;
131105
132106class User extends Model <InferAttributes <User >, InferCreationAttributes <User >> {
107+ @Attribute (DataTypes .STRING )
133108 declare username: string | null ;
109+
110+ @Attribute (DataTypes .DATE )
134111 declare birthday: Date | null ;
135112}
136113
137- User . init ({
138- username : DataTypes . STRING ,
139- birthday : DataTypes . DATE
140- }, { sequelize, modelName : ' user ' } );
141-
142- ( async () => {
143- await sequelize . sync ();
144- const jane = await User .create ({
145- username: ' janedoe' ,
146- birthday: new Date (1980 , 6 , 20 ),
147- });
148- console . log ( jane . toJSON ());
149- })( );
114+ const sequelize = new Sequelize ({
115+ dialect: SqliteDialect ,
116+ models: [ User ],
117+ });
118+
119+ await sequelize . sync ();
120+
121+ const jane = await User .create ({
122+ username: ' janedoe' ,
123+ birthday: new Date (1980 , 6 , 20 ),
124+ });
125+
126+ console . log ( jane . toJSON () );
150127```
151128
152- #### JavaScript (CJS)
153-
154- ``` javascript
155- const { Sequelize , Model , DataTypes } = require (' sequelize' );
156- const sequelize = new Sequelize (' sqlite::memory:' );
157-
158- class User extends Model {}
159- User .init ({
160- username: DataTypes .STRING ,
161- birthday: DataTypes .DATE
162- }, { sequelize, modelName: ' user' });
163-
164- (async () => {
165- await sequelize .sync ();
166- const jane = await User .create ({
167- username: ' janedoe' ,
168- birthday: new Date (1980 , 6 , 20 )
169- });
170- console .log (jane .toJSON ());
171- })();
129+ #### JavaScript
130+
131+ ``` typescript
132+ import { Sequelize , Model , DataTypes } from ' @sequelize/core' ;
133+ import { Attribute } from ' @sequelize/core/decorators-legacy' ;
134+ import { SqliteDialect } from ' @sequelize/sqlite3' ;
135+
136+ class User extends Model {
137+ @Attribute (DataTypes .STRING )
138+ username;
139+
140+ @Attribute (DataTypes .DATE )
141+ birthday;
142+ }
143+
144+ const sequelize = new Sequelize ({
145+ dialect: SqliteDialect ,
146+ models: [User ],
147+ });
148+
149+ await sequelize .sync ();
150+
151+ const jane = await User .create ({
152+ username: ' janedoe' ,
153+ birthday: new Date (1980 , 6 , 20 ),
154+ });
155+
156+ console .log (jane .toJSON ());
172157```
173158
174159请通过 [ Getting started - 入门] ( core-concepts/getting-started.md ) 来学习更多相关内容. 如果你想要学习 Sequelize API 请通过 [ API 参考] ( https://sequelize.org/api/v7/ ) (英文).
0 commit comments