Guest User

Untitled

a guest
Jul 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import * as fs from 'fs';
  2. import * as path from 'path';
  3. import Sequelize from 'sequelize';
  4.  
  5. const baseFolder = __dir;
  6. const indexFile = 'index.js';
  7.  
  8. const Op = Sequelize.Op;
  9. const operatorsAliases = {
  10. $eq: Op.eq,
  11. $ne: Op.ne,
  12. $gte: Op.gte,
  13. $gt: Op.gt,
  14. $lte: Op.lte,
  15. $lt: Op.lt,
  16. $not: Op.not,
  17. $in: Op.in,
  18. $notIn: Op.notIn,
  19. $is: Op.is,
  20. $like: Op.like,
  21. $notLike: Op.notLike,
  22. $iLike: Op.iLike,
  23. $notILike: Op.notILike,
  24. $regexp: Op.regexp,
  25. $notRegexp: Op.notRegexp,
  26. $iRegexp: Op.iRegexp,
  27. $notIRegexp: Op.notIRegexp,
  28. $between: Op.between,
  29. $notBetween: Op.notBetween,
  30. $overlap: Op.overlap,
  31. $contains: Op.contains,
  32. $contained: Op.contained,
  33. $adjacent: Op.adjacent,
  34. $strictLeft: Op.strictLeft,
  35. $strictRight: Op.strictRight,
  36. $noExtendRight: Op.noExtendRight,
  37. $noExtendLeft: Op.noExtendLeft,
  38. $and: Op.and,
  39. $or: Op.or,
  40. $any: Op.any,
  41. $all: Op.all,
  42. $values: Op.values,
  43. $col: Op.col
  44. };
  45.  
  46. fs
  47. .readdirSync(baseFolder)
  48. .filter(file => (file.indexOf('.') !== 0) && (file !== indexFile) && (file.slice(-3) === '.js'))
  49. .forEach(file => {
  50. sequelize['import'](path.join(baseFolder, file));
  51. });
  52.  
  53. Object.values(sequelize.models).forEach( Model => {
  54. Model.sync();
  55.  
  56. if(Model.associate) {
  57. Model.associate();
  58. }
  59. });
  60.  
  61. export default sequelize;
Add Comment
Please, Sign In to add comment