(function(a){function c(a,b){this.content=a,this.model=b,this.getClass=this.model.getClass}function d(){this._client=null,this.dirty=!1,this.params={};try{this.params.offset=global.context().request.params.offset||0}catch(a){this.params.offset=0}this.params.offset<0&&(this.params.offset=0),this._data=[]}var b=global.nwt.load().library("NWTHelperInstance",!1);global.nwt.extend(c,b),c.prototype.render=function(){return this.beforeContent=this.beforeContent||"",this.afterContent=this.afterContent||"",this.beforeContent+this.content+this.afterContent},d.prototype.toString=function(){return""},d.prototype.all=function(a){return this.setParams(a),this.dirty=!0,this},d.prototype.one=function(a){return a.limit=1,this.setParams(a),this.all(a)},d.prototype.get=function(a){var b={where:{id:a}};return this.one(b)},d.prototype.setParams=function(a){this.dirty=!0;for(var b in a)this.params[b]=a[b]},d.prototype._getClient=function(){if(!this._client){var a=require(global.context().siteRoot+"/config.js").db,b=require(__dirname+"/../drivers/NWT"+a.driver+".js").client;this._client=new b(a,this)}return this._client},d.prototype._update=function(){this._data=this._getClient().find(this.params)},d.prototype.save=function(a){this.dirty=!0,this._getClient().save(a)},d.prototype.iterator=function(a,b){this._update();for(var c=0,d;d=this._data[c];c++)a.apply(b,[d])},d.prototype.each=function(a){this._update();var b=[];for(var d=0,e;e=this._data[d];d++)b.push(a(e));return new c(b.join(""),this)},a.NWTModel=d})(this)
