import labkeyInterface import json import chardet class labkeyDB: def __init__(self,net): self.net=net def selectRows(self,project,schemaName, queryName,qfilter,viewName='default'): debug=False url=self.net.GetLabkeyUrl()+'/'+project url+='/query-selectRows.api?schemaName='+schemaName+\ '&query.queryName='+queryName if viewName!='default': url+='&query.viewName={}'.format(viewName) for f in qfilter: url+="&query."+f['variable']+"~"+f['oper']+"="+f['value'] if debug: print("Sending {}").format(url) response=self.net.get(url) encoding=chardet.detect(response.data)["encoding"] return json.loads(response.data.decode(encoding)) def modifyRows(self,mode, project,schemaName, queryName, rows): #mode can be insert/update/delete debug=True data={} data['schemaName']=schemaName data['queryName']=queryName data['rows']=rows url=self.net.GetLabkeyUrl()+'/'+project url+='/query-'+mode+'Rows.api?' response=self.net.post(url,json.dumps(data)) return response.data def addList(self,project,schemaName,queryName,fields): listDomainDefinition={} listDomainDefinition['kind']='IntList' fields.append({'name':'Key','rangeURI':'int'}) domainDesign={} domainDesign['name']=queryName domainDesign['description']='' domainDesign['fields']=fields listDomainDefinition['domainDesign']=domainDesign options={} options['keyName']='Key' options['keyType']='Integer' url=self.net.GetLabkeyUrl()+'/'+project url+='/property-createDomain.api' response=self.net.post(url,json.dumps(listDomainDefinition)) return response.data