document.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module.exports = (sequelize, DataTypes) => {
  2. var Document = sequelize.define("document", {
  3. id: { type: DataTypes.STRING, primaryKey: true },
  4. path: { type: DataTypes.STRING },
  5. title: { type: DataTypes.STRING },
  6. author: { type: DataTypes.STRING },
  7. pageCount: { type: DataTypes.INTEGER },
  8. identifier: { type: DataTypes.STRING },
  9. fileSize: { type: DataTypes.INTEGER }
  10. }, {
  11. timestamps: true,
  12. sequelize });
  13. Document.getLastInserted = function(count) {
  14. return Document.findAll({
  15. order: [[ 'createdAt', 'DESC' ]],
  16. limit: count
  17. });
  18. }
  19. var DocumentCover = sequelize.define("document_covers", {
  20. id: {
  21. type: DataTypes.STRING,
  22. primaryKey: true,
  23. },
  24. cover: { type: DataTypes.BLOB('long') }
  25. }, {
  26. timestamps: false,
  27. sequelize });
  28. DocumentCover.belongsTo(Document, { foreignKey: 'id' });
  29. return {
  30. Document: Document,
  31. DocumentCover: DocumentCover
  32. };
  33. };