sequelize-typescript
Advanced tools
Comparing version 1.0.0-alpha.5 to 1.0.0-alpha.6
{ | ||
"name": "sequelize-typescript", | ||
"version": "1.0.0-alpha.5", | ||
"version": "1.0.0-alpha.6", | ||
"description": "Decorators and some other features for sequelize", | ||
"scripts": { | ||
"build": "tsc", | ||
"build-tests": "tsc --project test", | ||
"test": "npm run build && npm run build-tests && mocha", | ||
"cover": "npm run build && npm run build-tests && nyc mocha", | ||
"copyJsAndDeclarationFiles": "copyfiles -u 1 src/**/*.js src/**/*.d.ts dist", | ||
"build": "tsc && npm run copyJsAndDeclarationFiles", | ||
"test": "mocha", | ||
"cover": "nyc mocha", | ||
"lint": "tslint .", | ||
"prepare": "npm run build" | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -35,4 +35,4 @@ "repository": { | ||
"homepage": "https://github.com/RobinBuschmann/sequelize-typescript#readme", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
@@ -56,9 +56,10 @@ "@types/bluebird": "3.*", | ||
"chai-datetime": "1.4.1", | ||
"codecov": "3.0.0", | ||
"codecov": "3.1.0", | ||
"copyfiles": "2.1.0", | ||
"has-flag": "2.0.0", | ||
"lodash": "4.17.4", | ||
"mocha": "3.2.0", | ||
"lodash": "4.17.11", | ||
"mocha": "5.2.0", | ||
"moment": "2.21.0", | ||
"mysql2": "1.3.5", | ||
"nyc": "11.0.2", | ||
"nyc": "13.1.0", | ||
"prettyjson": "1.2.1", | ||
@@ -70,4 +71,4 @@ "reflect-metadata": "0.1.9", | ||
"source-map-support": "0.4.14", | ||
"sqlite3": "4.0.0", | ||
"ts-node": "3.0.4", | ||
"sqlite3": "4.0.4", | ||
"ts-node": "7.0.1", | ||
"tslint": "4.3.1", | ||
@@ -89,7 +90,10 @@ "typescript": "2.9.1", | ||
"include": [ | ||
"lib/**/*.js" | ||
"src" | ||
], | ||
"exclude": [ | ||
"test/**/*.js" | ||
"test" | ||
], | ||
"extension": [ | ||
".ts" | ||
], | ||
"reporter": [ | ||
@@ -99,3 +103,3 @@ "lcov", | ||
], | ||
"cache": false, | ||
"cache": true, | ||
"all": true, | ||
@@ -102,0 +106,0 @@ "check-coverage": true, |
@@ -23,2 +23,7 @@ [![Build Status](https://travis-ci.org/RobinBuschmann/sequelize-typescript.svg?branch=master)](https://travis-ci.org/RobinBuschmann/sequelize-typescript) | ||
- [Multiple relations of same models](#multiple-relations-of-same-models) | ||
- [Repository mode](#repository-mode) | ||
- [How to enable repository mode?](#how-to-enable-repository-mode) | ||
- [How to use repository mode?](#how-to-use-repository-mode) | ||
- [How to use associations with repository mode?](#how-to-use-associations-with-repository-mode) | ||
- [Limitations of repository mode](#limitations-of-repository-mode) | ||
- [Model validation](#model-validation) | ||
@@ -505,2 +510,51 @@ - [Scopes](#scopes) | ||
## Repository mode | ||
The repository mode makes it possible to separate static operations like `find`, `create`, ... from model definitions. | ||
It also empowers models so that they can be used with multiple sequelize instances. | ||
### How to enable repository mode? | ||
Enable repository mode by setting `repositoryMode` flag: | ||
```typescript | ||
const sequelize = new Sequelize({ | ||
repositoryMode: true, | ||
..., | ||
}); | ||
``` | ||
### How to use repository mode? | ||
Retrieve repository to create instances or perform search operations: | ||
```typescript | ||
const userRepository = sequelize.getRepository(User); | ||
const luke = await userRepository.create({name: 'Luke Skywalker'}); | ||
const luke = await userRepository.findOne({where: {name: 'luke'}}); | ||
``` | ||
### How to use associations with repository mode? | ||
For now one need to use the repositories within the include options in order to retrieve or create related data: | ||
```typescript | ||
const userRepository = sequelize.getRepository(User); | ||
const addressRepository = sequelize.getRepository(Address); | ||
userRepository.find({include: [addressRepository]}); | ||
userRepository.create({name: 'Bear'}, {include: [addressRepository]}); | ||
``` | ||
> ⚠️ This will change in the future: One will be able to refer the model classes instead of the repositories. | ||
### Limitations of repository mode | ||
Nested scopes and includes in general won't work when using `@Scope` annotation together with repository mode like: | ||
```typescript | ||
@Scopes({ | ||
// includes | ||
withAddress: { | ||
include: [() => Address], | ||
}, | ||
// nested scopes | ||
withAddressIncludingLatLng: { | ||
include: [() => Address.scope('withLatLng')], | ||
} | ||
}) | ||
@Table | ||
class User extends Model<User> {} | ||
``` | ||
> ⚠️ This will change in the future: Simple includes will be implemented. | ||
## Model validation | ||
@@ -656,5 +710,7 @@ Validation options can be set through the `@Column` annotation, but if you prefer to use separate decorators for | ||
## Recommendations and limitations | ||
### One Sequelize instance per model | ||
You cannot add one and the same model to multiple Sequelize instances with | ||
differently configured connections. So that one model will only work for one connection. | ||
### One Sequelize instance per model (without repository mode) | ||
Unless you are using the [repository mode](#repository-mode), you won't be able to add one and the same model to multiple | ||
Sequelize instances with differently configured connections. So that one model will only work for one connection. | ||
### One model class per file | ||
@@ -666,2 +722,3 @@ This is not only good practice regarding design, but also matters for the order | ||
which does not throw an error. | ||
### Minification | ||
@@ -668,0 +725,0 @@ If you need to minify your code, you need to set `tableName` and `modelName` |
@@ -14,2 +14,4 @@ { | ||
"ordered-imports": false, | ||
"max-classes-per-file": false, | ||
"space-before-function-paren": false, | ||
"max-line-length": [ | ||
@@ -16,0 +18,0 @@ true, |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
335329
350
7393
749
30
1