Sequelize + Decorators = ❤
A proof of concept for using Sequelize with decorators.
Usage with TypeScript
Installation
npm install --save sequelize sequelize-decorators
Add to your tsconfig.json
:
"experimentalDecorators": true,"emitDecoratorMetadata": true
The second setting lets sequelize-decorators infer the type of attributes from the type declaration.
Example:
const sequelize = processenvDB @ @ public username: string; @ public firstName: string; @ // Type is inferred as DataTypes.STRING public lastName: string; get : string return thisfirstName + ' ' + thislastName; { const names = fullName; thislastName = names; thisfirstName = names; }
The @Options
decorator is required and must include the sequelize
option (the connection to use).
Type inference
TypeScript type | Sequelize data type |
---|---|
string |
STRING |
number |
INTEGER |
Date |
DATE |
Buffer |
BLOB |
Usage with Babel
Installation
npm install --save sequelize sequelize-decorators
npm install --save-dev babel-plugin-transform-decorators-legacy
Add to your .babelrc
:
"plugins":
Example:
const sequelize = processenvDB @@ get : string return thisfirstName + ' ' + thislastName; { const names = fullName; thislastName = names; thisfirstName = names; }
The @Options
decorator is required and must include the sequelize
option (the connection to use).