@kohanajs/mixin-orm
Advanced tools
Comparing version 1.0.18 to 1.0.19
@@ -115,10 +115,15 @@ const {KohanaJS, ORM, ControllerMixin} = require('kohanajs'); | ||
class ORMInput extends ControllerMixin{ | ||
constructor(client, Model) { | ||
constructor(client, Model, $_POST) { | ||
super(client); | ||
this.model = Model; | ||
this.id = this.request.params?.id; | ||
this.$_POST = $_POST; | ||
this.exports = { | ||
ORMInput : () => this.ORMInput, | ||
} | ||
} | ||
async action_update(){ | ||
const postData = new Map(Object.entries(this.mixin.get('$_POST'))); | ||
const postData = new Map(Object.entries(this.$_POST)); | ||
//parse postData; | ||
@@ -132,3 +137,3 @@ //find instance fields | ||
this.addBehaviour('ORMInput', updates); | ||
this.ORMInput = updates; | ||
} | ||
@@ -135,0 +140,0 @@ |
@@ -8,2 +8,6 @@ const {ORM, ControllerMixin} = require('kohanajs'); | ||
this.id = this.request.params?.id ? parseInt(this.request.params.id) : null; | ||
this.exports = { | ||
instances : () => this.instances, | ||
instance : () => this.instance, | ||
} | ||
} | ||
@@ -18,4 +22,3 @@ | ||
const instances = await ORM.readAll( this.model , null,{database: this.database}); | ||
this.addBehaviour('instances', instances); | ||
this.instances = await ORM.readAll( this.model , null,{database: this.database}); | ||
} | ||
@@ -26,4 +29,4 @@ | ||
const instance = await ORM.factory( this.model, this.id, {database: this.database}); | ||
this.addBehaviour('instance', instance); | ||
this.instance = await ORM.factory( this.model, this.id, {database: this.database}); | ||
} | ||
@@ -30,0 +33,0 @@ } |
@@ -6,18 +6,27 @@ //controller to receive data | ||
class ControllerMixinORMWrite extends ControllerMixin{ | ||
constructor(client, Model) { | ||
/** | ||
* @param client | ||
* @param Model | ||
* @param database | ||
* @param {function | object} ORMInput | ||
*/ | ||
constructor(client, Model, database, ORMInput) { | ||
super(client); | ||
this.model = Model; | ||
this.id = this.request.params?.id; | ||
} | ||
this.database = database; | ||
this.ORMInput = ORMInput; | ||
async before(){ | ||
this.database = this.mixin.get('db'); | ||
this.exports = { | ||
instance: () => this.instance, | ||
} | ||
} | ||
async action_update(){ | ||
const input = this.mixin.get('ORMInput'); | ||
const input = typeof this.ORMInput === 'function' ? this.ORMInput() : this.ORMInput; | ||
const ins = await this.newInstance(input); | ||
this.addBehaviour('instance', ins); | ||
await this.newChild(input, ins); | ||
await this.updateInstances(input); | ||
this.instance = ins; | ||
} | ||
@@ -24,0 +33,0 @@ |
@@ -6,14 +6,20 @@ const {View, ControllerMixin} = require('kohanajs'); | ||
super(client); | ||
this.layout = this.getView(layout, {}); | ||
this.addBehaviour('view', this.layout); | ||
this.addBehaviour('getView', this.getView); | ||
this.exports = { | ||
getView : (file, data, viewClass=null) => this.getView(file, data, viewClass), | ||
setTemplate: (file, data={}, viewClass={}) => { | ||
this.template = this.getView(file, data, viewClass); | ||
}, | ||
getTemplate: () => this.template, | ||
} | ||
} | ||
async after(){ | ||
const layout = this.mixin.get('view'); | ||
const layout = this.layout; | ||
if(!layout)return; | ||
//render template and put into layout's main output. | ||
const template = this.mixin.get('template'); | ||
const template = this.template; | ||
if(template){ | ||
@@ -20,0 +26,0 @@ layout.data.main = await template.render(); |
{ | ||
"name": "@kohanajs/mixin-orm", | ||
"version": "1.0.18", | ||
"version": "1.0.19", | ||
"description": "", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"kohanajs": "^1.0.31", | ||
"kohanajs": "^1.0.33", | ||
"uuid": "^8.3.0" | ||
@@ -23,0 +23,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11935
284
Updatedkohanajs@^1.0.33