influxdb/admin/javascripts/api.js

1 line
1.3 KiB
JavaScript

!function(){var t;window.InfluxDB=t=function(){function t(t,r,e,s,n){this.host=t,this.port=r,this.username=e,this.password=s,this.database=n}return t.prototype.test=function(){return!0},t.prototype.createDatabase=function(t,r){var e,s;return s=this.url("db"),e={name:t},$.post(s,JSON.stringify(e),r)},t.prototype.deleteDatabase=function(t){var r;return r=this.url("db/"+t),$["delete"](r)},t.prototype.getDatabaseNames=function(){var t;return t=this.url("dbs"),$.get(t)},t.prototype.createUser=function(t,r,e,s){var n,o;return o=this.url("db/"+t+"/users"),n={username:r,password:e},$.post(o,JSON.stringify(n),s)},t.prototype.readPoint=function(t,r,e){var s,n;return n=this.url("db/"+this.database+"/series"),s="SELECT "+t+" FROM "+r+";",n+="&q="+encodeURIComponent(s),$.get(n,null,e)},t.prototype._readPoint=function(t,r){var e;return e=this.seriesUrl(this.database),e+="&q="+encodeURIComponent(t),$.get(e,{},r)},t.prototype.writePoint=function(t,r,e,s){var n,o,i,u,a,p;null==e&&(e={}),o={points:[],name:t,columns:[]},u=[];for(i in r)p=r[i],u.push(p),o.columns.push(i);return o.points.push(u),n=[o],a=this.seriesUrl(this.database),$.post(a,JSON.stringify(n),s)},t.prototype.url=function(t){return"http://"+this.host+":"+this.port+"/"+t+"?u="+this.username+"&p="+this.password},t.prototype.seriesUrl=function(t){return this.url("db/"+t+"/series")},t}()}.call(this);