Package: b3j0f.requester
DescriptionAbstract data request library powered by the python syntax and reflective concerns.LinksHomepagePyPIDocumentationInstallationpip install b3j0f.requesterFeaturesThis library aims to access to system data from a generic and python API.Reflective concerns permit to not consider only data access with four create/read/update/delete operations but with a more one which is a service execution. Therefore, the main acronym of this library is CRUDEIn a minimal case, there are 6 concepts to know:Driver: in charge of accessing data.Expression and Function: refers to data models and system functions.Transaction: refers to data access transaction.Context: execution context such as a dict where keys are expressions, and values are system data.Let a data models containing a table ‘user’ where fields are ‘name’ and ‘age’.A filter about users of age at least 10 is:Expression.user.age>10A selection of number of users is:Function.count(Expression.user)Now, imagine you have two systems, called respectivelly Administration and Club. You might want to get users who have the same name and are at least twenty years old, in both systems like that:(Expression.Administration.user.name==Expression.Club.user.name)&(Expression.user.age>=20)Therefore, all python operators are overriden by the object Expression in order to let you requests in a pythonic way.ExamplesRefers to a datafromb3j0f.requesterimportExpressionasE,FunctionasF# ways to refers to the field 'user.id'.E.user.idE('user.id')E('user').id# ways to refers to the function 'count' on the data 'user'.F.count(E.user)F('count')(E.user)F('count',params=[E.user])# In a multi system use, a system is seen such as a data:# access to users from a system administration.E.Administration.userE('Administration.user')E('Administration').userCreate data from a systemfromb3j0f.requesterimportDriverclassMyDriver(Driver):"""implement your own driver..."""driver=MyDriver()# ways to create data from the request managerdriver.create(name='C.user',values={'name':'john'})driver.create(name=E.C.user,values={'name':'john'})# create several data at once with method chaining and transactionwithdriver.open()astransaction:"""transaction.create(...).update(...)"""Thewithensurethetransactioniscommitedorrollbackedincaseofanyerror.trans=driver.open()# it is also possible to create a hierarchy of transaction with trans.open()trans.create('C.user',{'name':'john'}).create(E.C.user,{'name':'paul'}).process(Create('C.user',{'name':'david'}),Create(E.C.user,{'name':'thomas'})).commit()# create transaction with autocommit and with an historical context# autocommit and ctx can be changed at runtimetrans=driver.open(autocommit=True,ctx=Context())Read data from a systemfromb3j0f.requesterimportReadasR,JoinasJ# get a read resource with specific offsetcrud=driver.read(offset=5)# add filterscrud&=(E.A.id==E.B.id)&(F.now>E.B.timestamp)# same ascrud.where(query)# and with a "or"crud.orwhere(query);crud|=query# method chaining and max 10 data, sorted by A.id and grouped by A.nameresult=crud.sortby(E.A.id).groupby(E.A.name).join('FULL').select()[:10]fordatainresult:# display A and Bprint(data['A'],data['B'])# or get the result via a callbackcrud(async=True,callback=lambdaresult:None)# read data with a Read objectread=R(limit=10,groupby=E.A.name,join=J.FULL,sort=E.A.name)result=trans.process(read).ctx[read]# get context request which contain all data from systems and a transaction with autocommit# read data from the driver with default parametersAandB=driver['A','B']Update data from a systemfromb3j0f.requesterimportUpdateasU# udpate data from the driverdriver.update(name='user',values={'name':'john'})driver.update(name=E.user,values={'name':'john'})driver.update(name=E.user,values={'name':'john'})driver[E.user]={'name':'john'}driver['user']={'name':'john'}# update data from the transactiontrans.update(name=E.user,values={'name':'john'})trans.update('user',{'name':'john'})trans['user']={'name':'john'}trans[E.user]={'name':'john'}trans.process(U(name='user',values={'name':'john'}))trans.process(U(name=E.user,values={'name':'john'}))Delete data from a systemfromb3j0f.requesterimportDeleteasD# delete a user from a driverdriver.delete(names=['user'],query=query)driver.delete(names=[E.user],query=query)deldriver['user']deldriver[E.user]# delete a user from a transactiontrans.delete(names=[D.user],query=query)trans.delete(names=['user'],query=query)deltrans['user']deltrans[E.user]trans.process(names=[D('user')],query=query)trans.process(names=[D(E.user)],query=query)Perspectiveswait feedbacks during 6 months before passing it to a stable version.Cython implementation.Donation