1234567891011121314151617181920212223242526272829303132333435 |
- import labkeyInterface
- import json
- import chardet
- class labkeyDB:
- def __init__(self,net):
- self.net=net
- def selectRows(self,project,schemaName, queryName,qfilter):
- debug=False
- url=self.net.GetLabkeyUrl()+'/'+project
- url+='/query-selectRows.api?schemaName='+schemaName+\
- '&query.queryName='+queryName
- 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
|