sequelize#DataTypes TypeScript Examples

The following examples show how to use sequelize#DataTypes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sequelize.test.ts    From feathers-casl with MIT License 6 votes vote down vote up
afterHooks = [
  (context: HookContext) => {
    const { Model } = context.service;
    const fields = Model.fieldRawAttributesMap;
    let items = getItems(context);
    items = (Array.isArray(items)) ? items : [items];

    items.forEach(item => {
      const keys = Object.keys(item);
      keys.forEach(key => {
        const field = fields[key];
        if (item[key] === null) {
          delete item[key];
          return;
        }
        // @ts-ignore
        if (field.type instanceof DataTypes.BOOLEAN) {
          item[key] = !!item[key];
        }
      });
    });
  }
]
Example #2
Source File: validatorstats.ts    From community-repo with GNU General Public License v3.0 6 votes vote down vote up
ValidatorStats.init({
  accountId: {type: DataTypes.INTEGER, allowNull: false},
  eraId: {type: DataTypes.INTEGER, allowNull: false},
  stake_total: { type: DataTypes.DECIMAL, defaultValue: 0},
  stake_own: { type: DataTypes.DECIMAL, defaultValue: 0},
  points: { type: DataTypes.INTEGER, defaultValue: 0},
  rewards: { type: DataTypes.DECIMAL, defaultValue: 0},
  commission: DataTypes.DECIMAL
}, 
{modelName: 'validator_stats', sequelize: db, indexes: [
  {
    unique: true,
    fields: ['accountId', 'eraId']
  }
 ]
})
Example #3
Source File: Birthday.ts    From CSZ-Bot with MIT License 6 votes vote down vote up
static initialize(sequelize: Sequelize) {
        this.init({
            id: {
                type: DataTypes.STRING(36),
                defaultValue: () => uuidv4(),
                primaryKey: true
            },
            userId: {
                type: DataTypes.STRING(32),
                allowNull: false,
                unique: true
            },
            day: {
                type: DataTypes.INTEGER,
                allowNull: false,
                validate: {
                    min: 1,
                    max: 31
                }
            },
            month: {
                type: DataTypes.INTEGER,
                allowNull: false,
                validate: {
                    min: 1,
                    max: 12
                }
            }
        },
        {
            sequelize,
            modelName: "Birthday"
        });
    }
Example #4
Source File: build.ts    From one-platform with MIT License 6 votes vote down vote up
Build = sequelize.define<BuildInstance>('builds', {
  id: { type: DataTypes.UUID, primaryKey: true },
  projectId: {
    type: DataTypes.UUID,
    references: { model: ModelRef, key: 'id' },
  },
  lifecycle: { type: DataTypes.STRING(40) },
  hash: { type: DataTypes.STRING(40) },
  branch: { type: DataTypes.STRING(40) },
  commitMessage: { type: DataTypes.STRING(80) },
  author: { type: DataTypes.STRING(256) },
  avatarUrl: { type: DataTypes.STRING(256) },
  ancestorHash: { type: DataTypes.STRING(40) },
  externalBuildUrl: { type: DataTypes.STRING(256) },
  runAt: { type: DataTypes.DATE(6) }, // should mostly be equal to createdAt but modifiable by the consumer
  committedAt: { type: DataTypes.DATE(6) },
  ancestorCommittedAt: { type: DataTypes.DATE(6) },
  createdAt: { type: DataTypes.DATE(6) },
  updatedAt: { type: DataTypes.DATE(6) },
})
Example #5
Source File: Stempel.ts    From CSZ-Bot with MIT License 6 votes vote down vote up
static initialize(sequelize: Sequelize) {
        this.init({
            id: {
                type: DataTypes.STRING(36),
                defaultValue: () => uuidv4(),
                primaryKey: true
            },
            invitator: {
                type: DataTypes.STRING(32),
                allowNull: false
            },
            invitedMember: {
                type: DataTypes.STRING(32),
                allowNull: false,
                unique: true
            }
        },
        {
            sequelize,
            modelName: "Stempel"
        });
    }
Example #6
Source File: sequelize.test.ts    From feathers-casl with MIT License 6 votes vote down vote up
Model = sequelize.define("tests", {
  userId: {
    type: DataTypes.INTEGER
  },
  hi: {
    type: DataTypes.STRING
  },
  test: {
    type: DataTypes.BOOLEAN
  },
  published: {
    type: DataTypes.BOOLEAN
  },
  supersecret: {
    type: DataTypes.BOOLEAN
  },
  hidden: {
    type: DataTypes.BOOLEAN
  }
}, {
  timestamps: false
})
Example #7
Source File: Penis.ts    From CSZ-Bot with MIT License 6 votes vote down vote up
static initialize(sequelize: Sequelize) {
        this.init({
            id: {
                type: DataTypes.STRING(36),
                defaultValue: () => uuidv4(),
                primaryKey: true
            },
            userId: {
                type: DataTypes.STRING(32),
                allowNull: false
            },
            measuredAt: {
                type: DataTypes.DATE,
                allowNull: true
            },
            size: {
                type: DataTypes.INTEGER,
                allowNull: false
            },
            diameter: {
                type: DataTypes.INTEGER,
                allowNull: false
            }
        }, {
            sequelize,
            indexes: [
                {
                    using: "BTREE",
                    fields: [
                        {
                            name: "measuredAt",
                            order: "ASC"
                        }
                    ]
                }
            ]
        });
    }
Example #8
Source File: ModelBuilder.ts    From aloxide with Apache License 2.0 6 votes vote down vote up
static mapField(
    typeInterpreter: Interpreter<Field, DataType>,
    fields: Field[],
    key: string,
  ): ModelAttributes {
    return fields.reduce((a, c) => {
      const field: ModelAttributeColumnOptions<Model> = {
        type: typeInterpreter.interpret(c),
      };

      if (c.name === key) {
        field.primaryKey = true;
        switch (field.type) {
          case DataTypes.SMALLINT:
          case DataTypes.INTEGER:
          case DataTypes.BIGINT:
          case DataTypes.NUMBER:
          case DataTypes.DOUBLE:
            field.autoIncrement = true;
            break;
        }
      }

      return Object.assign(a, {
        [c.name]: field,
      });
    }, {});
  }
Example #9
Source File: user.ts    From expresso with MIT License 6 votes vote down vote up
// init model
User.init(
  {
    ...SequelizeAttributes.Users,
    newPassword: {
      type: DataTypes.VIRTUAL,
    },
    confirmNewPassword: {
      type: DataTypes.VIRTUAL,
    },
  },
  {
    // @ts-expect-error
    sequelize: db.sequelize,
    tableName: 'Users',
    paranoid: true,
    defaultScope: {
      attributes: {
        exclude: ['password', 'tokenVerify'],
      },
    },
    scopes: {
      withPassword: {},
    },
  }
)
Example #10
Source File: actions.ts    From server with Apache License 2.0 6 votes vote down vote up
export function init(sequelize: Sequelize):void {
  Action.init({
      identifier: {
        type: new DataTypes.STRING(250),
        allowNull: false,
        unique: 'uniqueIdentifier'
      },
      name: {
        type: DataTypes.JSONB,
        allowNull: false
      },
      code: {
        type: new DataTypes.STRING(65535),
        allowNull: false
      },
      order: {
        type: new DataTypes.INTEGER,
        allowNull: false,
      },
      triggers: {
        type: DataTypes.JSONB,
        allowNull: false
      },
      ...BaseColumns,
      tenantId: { // override base for uniqueIdentifier
        type: new DataTypes.STRING(50),
        allowNull: false,
        unique: 'uniqueIdentifier'
      }
    }, {
      tableName: 'actions',
      paranoid: true,
      timestamps: true,
      sequelize: sequelize
  });    
}
Example #11
Source File: getdb.ts    From elec-sqlite-vue with GNU General Public License v3.0 6 votes vote down vote up
User.init({
    firstName: {
        type: DataTypes.STRING,
        allowNull: false
    },
    lastName: {
        type: DataTypes.STRING,
        allowNull: false
    },

}, {
    tableName: "users",
    sequelize
})
Example #12
Source File: sequelize.spec.ts    From ucast with Apache License 2.0 6 votes vote down vote up
function configureORM() {
  const sequelize = new Sequelize('sqlite::memory:')

  class User extends Model {}
  class Project extends Model {}

  User.init({
    name: { type: DataTypes.STRING },
    email: { type: DataTypes.STRING },
  }, { sequelize, modelName: 'user' })

  Project.init({
    name: { type: DataTypes.STRING },
    active: { type: DataTypes.BOOLEAN }
  }, { sequelize, modelName: 'project' })

  Project.belongsTo(User)
  User.hasMany(Project)

  return { User, Project }
}
Example #13
Source File: index.ts    From sendight-backend with GNU General Public License v3.0 6 votes vote down vote up
readdirSync(__dirname)
  .filter(file => {
    return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js';
  })
  .forEach(file => {
    // eslint-disable-next-line @typescript-eslint/no-var-requires
    const model = require(join(__dirname, file))(sequelize, DataTypes);
    db[model.name] = model;
  });
Example #14
Source File: schema.ts    From akashlytics with GNU General Public License v3.0 6 votes vote down vote up
Block.init(
  {
    height: { type: DataTypes.INTEGER, primaryKey: true, allowNull: false },
    datetime: { type: DataTypes.DATE, allowNull: false },
    dayId: { type: DataTypes.UUID, allowNull: false, references: { model: Day, key: "id" } },

    // Stats
    isProcessed: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false },
    totalTxCount: { type: DataTypes.BIGINT, allowNull: false },
    totalUAktSpent: { type: DataTypes.BIGINT, allowNull: true },
    activeLeaseCount: { type: DataTypes.INTEGER, allowNull: true },
    totalLeaseCount: { type: DataTypes.INTEGER, allowNull: true },
    activeCPU: { type: DataTypes.INTEGER, allowNull: true },
    activeMemory: { type: DataTypes.BIGINT, allowNull: true },
    activeStorage: { type: DataTypes.BIGINT, allowNull: true },
    activeProviderCount: { type: DataTypes.INTEGER, allowNull: true }
  },
  {
    tableName: "block",
    modelName: "block",
    indexes: [
      { unique: false, fields: ["datetime"] },
      { unique: false, fields: ["dayId"] }
    ],
    sequelize
  }
);
Example #15
Source File: account.ts    From community-repo with GNU General Public License v3.0 6 votes vote down vote up
Account.init({
  id: {
    type: DataTypes.INTEGER,
    autoIncrement: true,
    primaryKey: true,
  },
  key: DataTypes.STRING,
  format: DataTypes.STRING,
  about: DataTypes.TEXT,
}, {modelName: 'account', sequelize: db})
Example #16
Source File: schema.ts    From akashlytics with GNU General Public License v3.0 6 votes vote down vote up
Provider.init(
  {
    owner: { type: DataTypes.STRING, primaryKey: true, allowNull: false },
    hostUri: { type: DataTypes.STRING, allowNull: false },
    createdHeight: { type: DataTypes.INTEGER, allowNull: false },
    email: { type: DataTypes.STRING, allowNull: true },
    website: { type: DataTypes.STRING, allowNull: true },

    // Stats
    isOnline: { type: DataTypes.BOOLEAN, allowNull: true },
    lastCheckDate: { type: DataTypes.DATE, allowNull: true },
    error: { type: DataTypes.STRING, allowNull: true },
    deploymentCount: { type: DataTypes.INTEGER, allowNull: true },
    leaseCount: { type: DataTypes.INTEGER, allowNull: true },
    activeCPU: { type: DataTypes.BIGINT, allowNull: true },
    activeMemory: { type: DataTypes.BIGINT, allowNull: true },
    activeStorage: { type: DataTypes.BIGINT, allowNull: true },
    pendingCPU: { type: DataTypes.BIGINT, allowNull: true },
    pendingMemory: { type: DataTypes.BIGINT, allowNull: true },
    pendingStorage: { type: DataTypes.BIGINT, allowNull: true },
    availableCPU: { type: DataTypes.BIGINT, allowNull: true },
    availableMemory: { type: DataTypes.BIGINT, allowNull: true },
    availableStorage: { type: DataTypes.BIGINT, allowNull: true }
  },
  {
    tableName: "provider",
    modelName: "provider",
    indexes: [{ unique: false, fields: ["owner"] }],
    sequelize
  }
);
Example #17
Source File: statistic.ts    From one-platform with MIT License 6 votes vote down vote up
Statistic = sequelize.define<StatisticInstance>('statistics', {
  id: { type: DataTypes.UUID, primaryKey: true },
  projectId: {
    type: DataTypes.UUID,
    references: { model: ModelRef, key: 'id' },
  },
  buildId: {
    type: DataTypes.UUID,
    references: { model: ModelRef, key: 'id' },
  },
  version: { type: DataTypes.DECIMAL(8, 2) },
  url: { type: DataTypes.STRING({ length: 256 }) },
  name: { type: DataTypes.STRING({ length: 100 }) },
  value: { type: DataTypes.DECIMAL(12, 4) },
  createdAt: { type: DataTypes.DATE(6) },
  updatedAt: { type: DataTypes.DATE(6) },
})
Example #18
Source File: relations.ts    From server with Apache License 2.0 5 votes vote down vote up
export function init(sequelize: Sequelize):void {
  Relation.init({
      identifier: {
        type: new DataTypes.STRING(250),
        allowNull: false,
        unique: 'uniqueIdentifier'
      },
      name: {
        type: DataTypes.JSONB,
        allowNull: false,
      },
      sources: {
        type: DataTypes.JSONB,
        allowNull: true,
      },
      targets: {
        type: DataTypes.JSONB,
        allowNull: true,
      },
      child: {
        type: 'BOOLEAN',
        allowNull: false,
      },
      multi: {
        type: 'BOOLEAN',
        allowNull: false,
      },
      order: {
        type: new DataTypes.INTEGER,
        allowNull: false,
      },
      options: {
        type: DataTypes.JSONB,
        allowNull: false,
      },
      ...BaseColumns,
      tenantId: { // override base for uniqueIdentifier
        type: new DataTypes.STRING(50),
        allowNull: false,
        unique: 'uniqueIdentifier'
      }
    }, {
      tableName: 'relations',
      paranoid: true,
      timestamps: true,
      sequelize: sequelize,
      scopes: {
        tenant(value) {
          return {
            where: {
              tenantId: value
            }
          }
        }
      }        
});    
}
Example #19
Source File: SequelizeTypeInterpreter.test.ts    From aloxide with Apache License 2.0 5 votes vote down vote up
describe('SequelizeTypeInterpreter', () => {
  const interpreter = new SequelizeTypeInterpreter();

  it('string without metatdata', () => {
    expect(
      interpreter.interpret({
        type: FieldTypeEnum.string,
        name: 'any-name',
      }),
    ).toEqual(DataTypes.TEXT);
  });

  it('string with specify length', () => {
    expect(
      interpreter.interpret({
        type: FieldTypeEnum.string,
        name: 'any-name',
        meta: {
          length: 54,
        },
      }),
    ).toEqual(DataTypes.STRING(54));
  });

  it('string with specify type', () => {
    expect(
      interpreter.interpret({
        type: FieldTypeEnum.string,
        name: 'any-name',
        meta: {
          type: 'tiny',
        },
      }),
    ).toEqual(
      DataTypes.TEXT({
        length: 'tiny',
      }),
    );
  });

  it('has meta but no metadata was provided', () => {
    expect(
      interpreter.interpret({
        type: FieldTypeEnum.string,
        name: 'any-name',
        meta: {},
      }),
    ).toEqual(DataTypes.TEXT);
  });
});
Example #20
Source File: types.ts    From server with Apache License 2.0 5 votes vote down vote up
export function init(sequelize: Sequelize):void {
    Type.init({
        path: {
          type: 'LTREE',
          allowNull: false,
          unique: true
        },
        identifier: {
          type: new DataTypes.STRING(250),
          allowNull: false,
          unique: 'uniqueIdentifier'
        },
        link: {
          type: DataTypes.INTEGER.UNSIGNED,
          allowNull: false,
        },
        name: {
          type: DataTypes.JSONB,
          allowNull: false,
        },
        icon: {
          type: new DataTypes.STRING(50),
          allowNull: true,
        },
        iconColor: {
          type: new DataTypes.STRING(50),
          allowNull: true,
        },
        file: {
          type: 'BOOLEAN',
          allowNull: false
        },
        mainImage: {
          type: DataTypes.INTEGER.UNSIGNED,
          allowNull: false,
        },
        images: {
          type: DataTypes.JSONB,
          allowNull: false,
        },        
        options: {
          type: DataTypes.JSONB,
          allowNull: false,
        },
        ...BaseColumns,
        tenantId: { // override base for uniqueIdentifier
          type: new DataTypes.STRING(50),
          allowNull: false,
          unique: 'uniqueIdentifier'
        }
      }, {
        tableName: 'types',
        paranoid: true,
        timestamps: true,
        sequelize: sequelize, // this bit is important
        scopes: {
          tenant(value) {
            return {
              where: {
                tenantId: value
              }
            }
          }
        }        
    });    
}
Example #21
Source File: SqlizeQuery.ts    From expresso with MIT License 5 votes vote down vote up
export function getPrimitiveDataType<T>(dataType: T): 'string' | 0 {
  const findDataType = (item: any): any => dataType instanceof item

  if (
    [
      DataTypes.JSON,
      DataTypes.TEXT,
      DataTypes.STRING,
      DataTypes.UUID,
      DataTypes.UUIDV1,
      DataTypes.UUIDV4,
    ].find(findDataType)
  ) {
    return 'string'
  }

  if (
    [
      DataTypes.REAL,
      DataTypes.INTEGER,
      DataTypes.FLOAT,
      DataTypes.BIGINT,
      DataTypes.DECIMAL,
      DataTypes.DOUBLE,
      DataTypes.MEDIUMINT,
      DataTypes.NUMBER,
      DataTypes.SMALLINT,
      DataTypes.TINYINT,
    ].find(findDataType)
  ) {
    return 0
  }

  // DataTypes.STRING
  // DataTypes.CHAR
  // DataTypes.TEXT
  // DataTypes.NUMBER
  // DataTypes.TINYINT
  // DataTypes.SMALLINT
  // DataTypes.MEDIUMINT
  // DataTypes.INTEGER
  // DataTypes.BIGINT
  // DataTypes.FLOAT
  // DataTypes.REAL
  // DataTypes.DOUBLE
  // DataTypes.DECIMAL
  // DataTypes.BOOLEAN
  // DataTypes.TIME
  // DataTypes.DATE
  // DataTypes.DATEONLY
  // DataTypes.HSTORE
  // DataTypes.JSON
  // DataTypes.JSONB
  // DataTypes.NOW
  // DataTypes.BLOB
  // DataTypes.RANGE
  // DataTypes.UUID
  // DataTypes.UUIDV1
  // DataTypes.UUIDV4
  // DataTypes.VIRTUAL
  // DataTypes.ENUM
  // DataTypes.ARRAY
  // DataTypes.GEOMETRY
  // DataTypes.GEOGRAPHY
  // DataTypes.CIDR
  // DataTypes.INET
  // DataTypes.MACADDR
  // DataTypes.CITEXT
  // if([
  //   DataTypes.NUMBER
  // ])

  // default is string
  return 'string'
}
Example #22
Source File: startblock.ts    From community-repo with GNU General Public License v3.0 5 votes vote down vote up
StartBlock.init({
  block: DataTypes.INTEGER,
}, {modelName: 'start_block', sequelize: db})
Example #23
Source File: SequelizeTypeInterpreter.ts    From aloxide with Apache License 2.0 5 votes vote down vote up
interpret(input: Field): DataType {
    let type: DataType;

    switch (input.type) {
      case FieldTypeEnum.uint16_t:
        type = DataTypes.SMALLINT;
        break;
      case FieldTypeEnum.uint32_t:
        type = DataTypes.INTEGER;
        break;
      case FieldTypeEnum.uint64_t:
        type = DataTypes.BIGINT;
        break;
      case FieldTypeEnum.number:
      case FieldTypeEnum.double:
        type = DataTypes.DOUBLE;
        break;
      case FieldTypeEnum.bool:
        type = DataTypes.BOOLEAN;
        break;
      case FieldTypeEnum.account:
        type = DataTypes.STRING;
        break;
      case FieldTypeEnum.string:
        if (input.meta) {
          if (input.meta.length) {
            type = DataTypes.STRING(input.meta.length);
          } else if (input.meta.type) {
            type = DataTypes.TEXT({
              length: input.meta.type as TextLength,
            });
          }
        }

        if (!type) {
          type = DataTypes.TEXT;
        }
        break;
      default:
        throw new Error(`unknow type ${input}`);
    }

    return type;
  }
Example #24
Source File: database.ts    From commonwealth with GNU General Public License v3.0 5 votes vote down vote up
models: Models = {
  Address: AddressFactory(sequelize, DataTypes),
  Chain: ChainFactory(sequelize, DataTypes),
  ChainCategory: ChainCategoryFactory(sequelize, DataTypes),
  ChainCategoryType: ChainCategoryTypeFactory(sequelize, DataTypes),
  ChainEntity: ChainEntityFactory(sequelize, DataTypes),
  ChainEvent: ChainEventFactory(sequelize, DataTypes),
  ChainEventType: ChainEventTypeFactory(sequelize, DataTypes),
  ChainNode: ChainNodeFactory(sequelize, DataTypes),
  ChatChannel: ChatChannelFactory(sequelize, DataTypes),
  ChatMessage: ChatMessageFactory(sequelize, DataTypes),
  Collaboration: CollaborationFactory(sequelize, DataTypes),
  ContractCategory: ContractCategoryFactory(sequelize, DataTypes),
  ContractItem: ContractItemFactory(sequelize, DataTypes),
  DiscussionDraft: DiscussionDraftFactory(sequelize, DataTypes),
  IdentityCache: IdentityCacheFactory(sequelize, DataTypes),
  InviteCode: InviteCodeFactory(sequelize, DataTypes),
  IpfsPins: IpfsPinsFactory(sequelize, DataTypes),
  LinkedThread: LinkedThread(sequelize, DataTypes),
  LoginToken: LoginTokenFactory(sequelize, DataTypes),
  Notification: NotificationFactory(sequelize, DataTypes),
  NotificationCategory: NotificationCategoryFactory(sequelize, DataTypes),
  NotificationsRead: NotificationsReadFactory(sequelize, DataTypes),
  OffchainAttachment: OffchainAttachmentFactory(sequelize, DataTypes),
  OffchainComment: OffchainCommentFactory(sequelize, DataTypes),
  OffchainPoll: OffchainPollFactory(sequelize, DataTypes),
  OffchainProfile: OffchainProfileFactory(sequelize, DataTypes),
  OffchainReaction: OffchainReactionFactory(sequelize, DataTypes),
  OffchainThread: OffchainThreadFactory(sequelize, DataTypes),
  OffchainTopic: OffchainTopicFactory(sequelize, DataTypes),
  OffchainViewCount: OffchainViewCountFactory(sequelize, DataTypes),
  OffchainVote: OffchainVoteFactory(sequelize, DataTypes),
  Profile: ProfileFactory(sequelize, DataTypes),
  Role: RoleFactory(sequelize, DataTypes),
  SocialAccount: SocialAccountFactory(sequelize, DataTypes),
  SsoToken: SsoTokenFactory(sequelize, DataTypes),
  StarredCommunity: StarredCommunityFactory(sequelize, DataTypes),
  Subscription: SubscriptionFactory(sequelize, DataTypes),
  Token: TokenFactory(sequelize, DataTypes),
  TaggedThread: TaggedThreadFactory(sequelize, DataTypes),
  User: UserModelFactory(sequelize, DataTypes),
  WaitlistRegistration: WaitlistRegistrationFactory(sequelize, DataTypes),
  Webhook: WebhookFactory(sequelize, DataTypes),
}
Example #25
Source File: Reminder.ts    From CSZ-Bot with MIT License 5 votes vote down vote up
static initialize(sequelize: Sequelize) {
        this.init({
            id: {
                type: DataTypes.STRING(36),
                defaultValue: () => uuidv4(),
                primaryKey: true
            },
            userId: {
                type: DataTypes.STRING(32),
                allowNull: false
            },
            remindAt: {
                type: DataTypes.DATE,
                allowNull: false
            },
            messageId: {
                type: DataTypes.STRING(32),
                allowNull: false
            },
            channelId: {
                type: DataTypes.STRING(32),
                allowNull: false
            },
            guildId: {
                type: DataTypes.STRING(32),
                allowNull: false
            }
        }, {
            sequelize,
            indexes: [
                {
                    using: "BTREE",
                    fields: [
                        {
                            name: "remindAt",
                            order: "ASC"
                        }
                    ]
                }
            ]
        });
    }
Example #26
Source File: balance.ts    From community-repo with GNU General Public License v3.0 5 votes vote down vote up
Balance.init({
  available: DataTypes.INTEGER,  
  locked: DataTypes.INTEGER,
  frozen: DataTypes.INTEGER,
}, { modelName: 'balance', sequelize: db })
Example #27
Source File: Ban.ts    From CSZ-Bot with MIT License 5 votes vote down vote up
static initialize(sequelize: Sequelize) {
        this.init({
            id: {
                type: DataTypes.STRING(36),
                defaultValue: () => uuidv4(),
                primaryKey: true
            },
            userId: {
                type: DataTypes.STRING(32),
                allowNull: false
            },
            reason: {
                type: DataTypes.STRING(255),
                allowNull: true
            },
            bannedUntil: {
                type: DataTypes.DATE,
                allowNull: true
            },
            isSelfBan: {
                type: DataTypes.BOOLEAN,
                allowNull: false
            }
        }, {
            sequelize,
            indexes: [
                {
                    unique: true,
                    fields: ["userId"]
                },
                {
                    using: "BTREE",
                    fields: [
                        {
                            name: "bannedUntil",
                            order: "ASC"
                        }
                    ]
                }
            ]
        });
    }
Example #28
Source File: event.ts    From community-repo with GNU General Public License v3.0 5 votes vote down vote up
Event.init({
  blockId: DataTypes.INTEGER,
  section: DataTypes.STRING,
  method: DataTypes.STRING,
  data: DataTypes.JSONB
}, { modelName: 'event', sequelize: db })
Example #29
Source File: attributes.ts    From server with Apache License 2.0 4 votes vote down vote up
export function init(sequelize: Sequelize):void {
  AttrGroup.init({
        identifier: {
          type: new DataTypes.STRING(250),
          allowNull: false,
          unique: 'uniqueIdentifier'
        },
        name: {
          type: DataTypes.JSONB,
          allowNull: false,
        },
        order: {
          type: new DataTypes.INTEGER,
          allowNull: false,
        },
        visible: {
          type: 'BOOLEAN',
          allowNull: false,
        },
        options: {
          type: DataTypes.JSONB,
          allowNull: false,
        },
        ...BaseColumns,
        tenantId: { // override base for uniqueIdentifier
          type: new DataTypes.STRING(50),
          allowNull: false,
          unique: 'uniqueIdentifier'
        }
      }, {
        tableName: 'attrGroups',
        paranoid: true,
        timestamps: true,
        sequelize: sequelize,
        scopes: {
          tenant(value) {
            return {
              where: {
                tenantId: value
              }
            }
          }
        }        
    });    
    Attribute.init({
      identifier: {
        type: new DataTypes.STRING(250),
        allowNull: false,
        unique: 'uniqueIdentifier'
      },
      name: {
        type: DataTypes.JSONB,
        allowNull: false,
      },
      order: {
        type: new DataTypes.INTEGER,
        allowNull: false,
      },
      valid: {
        type: DataTypes.JSONB,
        allowNull: true,
      },
      visible: {
        type: DataTypes.JSONB,
        allowNull: true,
      },
      relations: {
        type: DataTypes.JSONB,
        allowNull: true,
      },
      languageDependent: {
        type: 'BOOLEAN',
        allowNull: false,
      },
      type: {
        type: new DataTypes.INTEGER,
        allowNull: false,
      },
      pattern: {
        type: new DataTypes.STRING(250),
        allowNull: true
      },
      errorMessage: {
        type: DataTypes.JSONB,
        allowNull: true
      },
      lov: {
        type: DataTypes.INTEGER.UNSIGNED,
        allowNull: true
      },
      richText: {
        type: 'BOOLEAN',
        allowNull: false,
      },
      multiLine: {
        type: 'BOOLEAN',
        allowNull: false,
      },
      options: {
        type: DataTypes.JSONB,
        allowNull: false,
      },
      ...BaseColumns,
      tenantId: { // override base for uniqueIdentifier
        type: new DataTypes.STRING(50),
        allowNull: false,
        unique: 'uniqueIdentifier'
      }
    }, {
      tableName: 'attributes',
      paranoid: true,
      timestamps: true,
      sequelize: sequelize,
      scopes: {
        tenant(value) {
          return {
            where: {
              tenantId: value
            }
          }
        }
      }
  });
  GroupsAttributes.init({
    /* createdBy: {
      type: new DataTypes.STRING(250),
      allowNull: false
    },
    updatedBy: {
      type: new DataTypes.STRING(250),
      allowNull: false
    } */
  }, {
    tableName: 'group_attribute',
    paranoid: false,
    timestamps: true,
    sequelize: sequelize,
    scopes: {
      tenant(value) {
        return {
          where: {
            tenantId: value
          }
        }
      }
    }        
  });
  AttrGroup.belongsToMany(Attribute, {through: GroupsAttributes});    
  Attribute.belongsToMany(AttrGroup, {through: GroupsAttributes});    
}