How to use store

A store is a storage structure that is capable of backing up required program data as per user needs. There are mainly two types of stores. The Project Level stores store data throughout all scripts of the project and could facilitate script-to-script communication. The Run Level stores are lesser stores that can only store data for a particular script run and is thus very limited in scope because of this. It can be mostly used for debugging purposes and lacks a query mechanism to get current data into a script.

Example Script:

let {newPage, end, except, extract, extractAndSave, store, runStore, waitFor} = __sandbox;
let {params, } = OPTIONS;
(async () => { try {
	// -- START --
	
	//project store

	//save single item to store
	await store.saveOne('store', {id: 1, data: 'data'})
	//save several records to store
	await store.saveMany('store-2', [{id: 1, data: 'data'}, {id: 2, data: 'data'}])
	//get all item ids in a store
	console.log(await store.getAll('store-2', {only: ['id']}))
	//get one item from a store
	console.log(await store.getOne('store', 1))

	//run store

	//save single item to store
	await runStore.saveOne('store', {id: 1, data: 'data'})
	//save several records to store
	await runStore.saveMany('store-2', [{id: 1, data: 'data'}, {id: 2, data: 'data'}])

	// -- END --
	end()
} catch(e) { except(e) } })();

Scrapex.ai Store Script

Downloadable Store Project

Code Breakdown

The given snippet:

  • Stores One record to the project-level store: store
  • Stores Many records to the project-level store: store-2
  • Gets all records’ ids from project-level store: store-2
  • Get the record with id: 1 from project-level store: store
  • Save one record to the run-level store: store
  • Savone Many records to the run-level store: store-2