
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
sequelize-decorators
Advanced tools
A proof of concept for using Sequelize with decorators.
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.
import {Sequelize, Model, DataTypes} from 'sequelize'
import {Options, Attribute} from 'sequelize-decorators'
const sequelize = new Sequelize(process.env.DB)
@Options({
sequelize,
tableName: 'users'
})
export class User extends Model {
@Attribute({
type: DataTypes.STRING,
primaryKey: true
})
public username: string;
@Attribute(DataTypes.STRING)
public firstName: string;
@Attribute() // Type is inferred as DataTypes.STRING
public lastName: string;
get fullName(): string {
return this.firstName + ' ' + this.lastName;
}
set fullName(fullName: string) {
const names = fullName.split(' ');
this.lastName = names.pop();
this.firstName = names.join(' ');
}
}
The @Options
decorator is required and must include the sequelize
option (the connection to use).
TypeScript type | Sequelize data type |
---|---|
string | STRING |
number | INTEGER |
Date | DATE |
Buffer | BLOB |
npm install --save sequelize sequelize-decorators
npm install --save-dev babel-plugin-transform-decorators-legacy
Add to your .babelrc
:
"plugins": ["transform-decorators-legacy"]
import {Sequelize, Model, DataTypes} from 'sequelize'
import {Options, Attributes} from 'sequelize-decorators'
const sequelize = new Sequelize(process.env.DB)
@Options({
sequelize,
tableName: 'users'
})
@Attributes({
username: {
type: DataTypes.STRING,
primaryKey: true
},
lastName: DataTypes.STRING,
firstName: DataTypes.STRING,
})
export class User extends Model {
get fullName(): string {
return this.firstName + ' ' + this.lastName;
}
set fullName(fullName: string) {
const names = fullName.split(' ');
this.lastName = names.pop();
this.firstName = names.join(' ');
}
}
The @Options
decorator is required and must include the sequelize
option (the connection to use).
FAQs
Sequelize + Decorators = ❤
We found that sequelize-decorators demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.