davidhamann / python-fmrest

Python wrapper around the FileMaker Data API
MIT License
100 stars 27 forks source link

pagination #12

Closed d1337ted closed 4 years ago

d1337ted commented 5 years ago

Maybe its something obvious and I'm missing it (forgive me if that is the case) but do you have any examples of how I would go about looping through or handling additional pages of records. The get records function jumps straight into the data['fieldData'] being returned which is awesome but what if I want to be able to pull info out of the response['dataInfo'] such as the 'totalRecordCount' and 'foundCount' etc.

Thanks again for all you do.

davidhamann commented 5 years ago

The dataInfo wasn't part of the response in earlier versions of the Data API, that's why it's currently being ignored/skipped.

However, it should be pretty straight-forward to add the information as properties to the returned Foundset instance. Will have a look at it at some point.

As an idea for now to get the info: the number of returned records (which is often the same as number of records in the original FM foundset) can be obtained by taking then len of the Foundset instance (something like len(list(my_foundset))). For the total number of records: you would probably need to return that info as part of the response in a field or call a separate script to return the info (the script could be part of the same call, so you wouldn't even make two calls – see the API for get_records, probably with type after) .

For pagination it would be easiest to use get_records with the provided offset and limit parameters. You would reach the end once the number of returned records is lower than the provided limit.

Hope this helps a bit. Will look into adding the info from the dataInfo section as soon as I find the time.

davidhamann commented 5 years ago

@d1337ted I just pushed a new version to the master branch (not yet on PyPI). You can now access the dataInfo part of both the main Foundset instance and the portalDataInfo (for all the portal Foundset instances).

Want to give it a try?

pip install https://github.com/davidhamann/python-fmrest/archive/master.zip

Sample request:

foundset = fms.find(query=[{'name': 'Something'}], limit=1)
print(foundset.info)

Sample return of foundset.info property:

{'database': 'Contacts',
 'foundCount': 2,
 'layout': 'Test layout',
 'returnedCount': 1,
 'table': 'Test',
 'totalRecordCount': 8}

Currently, the keys of the info property are 1:1 those of the FMS response.

davidhamann commented 4 years ago

Functionality is now in release 1.2.1 and available on PyPI.