How to use the sequelize-typescript.Scopes function in sequelize-typescript

To help you get started, we’ve selected a few sequelize-typescript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github midwayjs / midway-examples / demo-sequelize-typescript / src / lib / model / post.ts View on Github external
// using factory style to provide Model because most useful
// sequelize methods are static in Model class. If you use
// @provide style, this class will be initialized when injected.
export const factory = () => PostModel;
providerWrapper([
  {
    id: 'PostModel',
    provider: factory,
  },
]);
// you need to export the type of Model class to ensure
// type-safety outside
export type IPostModel = typeof PostModel;

@Scopes({
  // a self-defined scope means "non-soft-deleted rows"
  avaliable: {
    where: {status: 1},
  },
})
@Table({
  // you can claim your tableName explicitly
  freezeTableName: true,
  tableName: 'my_posts_table',
})
export class PostModel extends Model {

  @Column({
    type: BIGINT(20),
    primaryKey: true,
    autoIncrement: true,
github T-Systems-RUS / Portfolio / server / models / Domain.ts View on Github external
import {Model, AllowNull, DataType, Column, Table, Scopes, CreatedAt, UpdatedAt, HasMany} from 'sequelize-typescript';
import {Customer} from './Customer';
import {Project} from './Project';
import {Tables} from '../sequelize/Tables';

@Scopes({
  withProjects: {
    include: [() => Project ]
  },
  withCustomers: {
    include: [() => Customer ]
  }
})
@Table({
  timestamps: true,
  tableName: Tables.DOMAINS
})
export class Domain extends Model {

  @AllowNull(false)
  @Column
  name: string;
github T-Systems-RUS / Portfolio / server / models / Customer.ts View on Github external
import {
  Model, AllowNull, DataType, Column, Table, Scopes, CreatedAt, UpdatedAt, HasMany, BelongsToMany,
  ForeignKey, BelongsTo
} from 'sequelize-typescript';
import {Project} from './Project';
import {Domain} from './Domain';
import {ProjectCustomer} from './ProjectCustomer';
import {Tables} from '../sequelize/Tables';

@Scopes({
  full: {
    include: [
      () => Project,
      () => Domain
    ]
  },
  withProjects: {
    include: [ () => Project ]
  }
})
@Table({
  timestamps: true,
  tableName: Tables.CUSTOMERS
})
export class Customer extends Model {
github T-Systems-RUS / Portfolio / server / models / Program.ts View on Github external
import {
  Model, AllowNull, DataType, Column, Table, Scopes, CreatedAt, UpdatedAt, HasMany, ForeignKey,
  BelongsTo
} from 'sequelize-typescript';
import {Project} from './Project';
import {Line} from './Line';
import {Tables} from '../sequelize/Tables';

@Scopes({
  withProjects: {
    include: [() => Project ]
  },
  withLine: {
    include: [() => Line]
  }
})
@Table({
  timestamps: true,
  tableName: Tables.PROGRAMS
})
export class Program extends Model {

  @AllowNull(false)
  @Column
  name: string;
github T-Systems-RUS / Portfolio / server / models / Technology.ts View on Github external
import {Model, AllowNull, DataType, Column, Table, Scopes, CreatedAt, UpdatedAt, HasMany, BelongsToMany} from 'sequelize-typescript';
import {Employee} from './Employee';
import {EmployeeTechnology} from './EmployeeTechnology';
import {Project} from './Project';
import {ProjectTechnology} from './ProjectTechnology';
import {Tables} from '../sequelize/Tables';

@Scopes({
    full: {
        include: [
            () => Employee,
            () => Project
        ]
    },
    withEmployees: {
        include: [ () => Employee ]
    },
    withProjects: {
        include: [ () => Project ]
    }
})
@Table({
    timestamps: true,
    tableName: Tables.TECHNOLOGIES
github T-Systems-RUS / Portfolio / server / models / Project.ts View on Github external
ForeignKey, BelongsTo
} from 'sequelize-typescript';
import {Schedule} from './Schedule';
import {Customer} from './Customer';
import {ProjectCustomer} from './ProjectCustomer';
import {Domain} from './Domain';
import {Employee} from './Employee';
import {Role} from './Role';
import {Program} from './Program';
import {Technology} from './Technology';
import {Type} from './Type';
import {ProjectTechnology} from './ProjectTechnology';
import {Tables} from '../sequelize/Tables';
import {Line} from './Line';

@Scopes({
    full: {
        include: [
          { model: () => Schedule, include: [() => Employee, () => Role]},
          { model: () => Program, include: [() => Line] },
          () => Technology,
          () => Domain,
          () => Type,
          () => Customer
        ]
    },
    projectList: {
      include: [
        { model: () => Program, include: [() => Line]},
        () => Schedule,
        () => Technology,
        () => Domain,
github T-Systems-RUS / Portfolio / server / models / Role.ts View on Github external
import {Model, AllowNull, DataType, Column, Table, Scopes, CreatedAt, UpdatedAt, HasMany} from 'sequelize-typescript';
import {Schedule} from './Schedule';
import {Tables} from '../sequelize/Tables';

@Scopes({
    withSchedules: {
        include: [() => Schedule ]
    }
})
@Table({
    timestamps: true,
    tableName: Tables.ROLES
})
export class Role extends Model {

    @AllowNull(false)
    @Column
    name: string;

    @AllowNull(false)
    @Column
github primecms / heroku / src / models / ContentEntry.ts View on Github external
import { Model, Column, Table, Scopes, BelongsTo, PrimaryKey, ForeignKey, DataType } from 'sequelize-typescript';
import { ContentType } from './ContentType';

@Scopes({
  contentType: {
    include: [{
      model: () => ContentType,
      through: { attributes: [] },
    }],
  },
})
@Table
export class ContentEntry extends Model {

  @PrimaryKey
  @Column({
    type: DataType.UUID,
    defaultValue: DataType.UUIDV4
  })
  id;
github T-Systems-RUS / Portfolio / server / models / Schedule.ts View on Github external
import {Model, Column, DataType, Table, Scopes, CreatedAt, UpdatedAt, ForeignKey, BelongsTo} from 'sequelize-typescript';
import {Employee} from './Employee';
import {Project} from './Project';
import {Role} from './Role';
import {Tables} from '../sequelize/Tables';

@Scopes({
    full: {
        include: [
            () => Project,
            () => Employee,
            () => Role
        ]
    }
})
@Table({
    tableName: Tables.SCHEDULES
})
export class Schedule extends Model {

    @Column({
        type: DataType.DECIMAL
    })
github albinojunior / node-crudapi-ts / src / app / modules / user / user.model.ts View on Github external
import { BeforeCreate, Column, DataType, DefaultScope, Is, Model, Scopes, Table } from "sequelize-typescript";
import { defaultScope, scopes } from "./user.scopes";
import { hashSync } from "bcryptjs";

const EMAIL_REGEX = /^[a-z0-9.]+@[a-z0-9]+\.[a-z]+\.([a-z]+)?$|^[a-z0-9.]+@[a-z0-9]+\.[a-z]/i;

@DefaultScope(defaultScope)
@Scopes(scopes)
@Table({
  tableName: "users",
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
  deletedAt: 'deleted_at'
})
export default class User extends Model {

  @Column(DataType.TEXT)
  name: string;

  @Is(EMAIL_REGEX)
  @Column(DataType.TEXT)
  email: string;