+ static getData (pluginName: string, pluginType: PluginType, key: string) {
+ const query = {
+ raw: true,
+ attributes: [ [ json('storage.' + key), 'value' ] as any ], // FIXME: typings
+ where: {
+ name: pluginName,
+ type: pluginType
+ }
+ }
+
+ return PluginModel.findOne(query)
+ .then((c: any) => {
+ if (!c) return undefined
+ const value = c.value
+
+ try {
+ return JSON.parse(value)
+ } catch {
+ return value
+ }
+ })
+ }
+
+ static storeData (pluginName: string, pluginType: PluginType, key: string, data: any) {
+ const query = 'UPDATE "plugin" SET "storage" = jsonb_set(coalesce("storage", \'{}\'), :key, :data::jsonb) ' +
+ 'WHERE "name" = :pluginName AND "type" = :pluginType'
+
+ const jsonPath = '{' + key + '}'
+
+ const options = {
+ replacements: { pluginName, pluginType, key: jsonPath, data: JSON.stringify(data) },
+ type: QueryTypes.UPDATE
+ }
+
+ return PluginModel.sequelize.query(query, options)
+ .then(() => undefined)
+ }
+