Tutorial

casFetchData

casFetchData


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'));
}