Skip to content

casFetchData

Deva Kumar edited this page Jan 20, 2020 · 1 revision

casFetchData ⇒ promise

Fetch rows from cas Tables

Returns: promise -

returns data and data for scrolling.

Param Type Description
store object

restaf store

session object

cas session

payload object

info to read data

Example

async function test_casFetchData () {
   let {session} = await casSetup(store);
   let payload = {
    from  : 1,
    count : 20,
    format: true,
    table : {caslib: 'Public', name: 'cars'}
   };

  let result = await restaflib.casFetchData(store, session, payload);
  console.log(result.data.schema);
  console.log('The next start is at:' + result.pagination.next.from);
  console.log(result.data.rows[0].toString());

  while (result.pagination.next.from !== -1) {
    console.log('The start is at: ' + result.pagination.next.from);
    result = await restaflib.casFetchData(store, session, result.pagination.next);
    console.log('The next start is at:' + result.pagination.next.from);
    console.log(result.data.rows[0].toString());
  };
  console.log('--------------------------------------- scroll backwards');

  while (result.pagination.prev.from !== -1) {
    console.log('The start is at: ' + result.pagination.prev.from);
    result = await restaflib.casFetchData(store, session, result.pagination.prev);
    console.log('The previous start is at: ' +  result.pagination.prev.from);
    console.log(result.data.rows[0].toString());
  };

  await store.apiCall(session.links('delete'));
}
Clone this wiki locally