@flowfuse/flowfuse
Version:
An open source low-code development platform
55 lines (53 loc) • 1.77 kB
JavaScript
/**
* A Project's Library
* @namespace forge.db.models.StorageLibrary
*/
const { DataTypes, Op } = require('sequelize')
module.exports = {
name: 'StorageLibrary',
schema: {
name: { type: DataTypes.TEXT, allowNull: false },
type: { type: DataTypes.TEXT, allowNull: false },
meta: { type: DataTypes.TEXT, allowNull: true },
body: { type: DataTypes.TEXT, allowNull: false, defaultValue: '' }
},
associations: function (M) {
this.belongsTo(M.Project)
},
finders: function (M) {
return {
static: {
byProject: async (project) => {
return this.findAll({
include: {
model: M.Project,
where: { project },
attributes: ['type', 'meta', 'body']
}
})
},
byType: async (project, type) => {
return this.findAll({
where: { ProjectId: project, type }
})
},
byName: async (project, type, name) => {
return this.findOne({
where: { ProjectId: project, type, name }
})
},
byPath: async (project, type, name) => {
return this.findAll({
where: {
ProjectId: project,
type,
name: {
[Op.like]: `${name}%`
}
}
})
}
}
}
}
}