Table State Operations
The State provider has table operations for storing state.
Set Table Values
Using a table name, you can store key-value pairs for retrieval later.
Method Signature
mapSet(table: string, keyValuePairs: any)
Setting Table Values
const session = vcr.createSession();
const state = new State(session);
const customer = req.body.customer;
await state.mapSet("customers", { [customer.number]: JSON.stringify(customer) });
Increment Table Values
Using a table name and key, you can increment its value.
Method Signature
mapIncrement(table: string, key: string, increment: number)
Incrementing Table Values
const number = req.body.number;
await state.mapIncrement("customers", number, 1);
Get a Table Value
Using a table name and key, you can fetch a value.
Method Signature
mapGetValue<T>(table: string, key: string)
Getting a Table Value
const number = req.body.number;
const customer = await state.mapGetValue("customers", number);
Getting Multiple Table Values
Using a table name and an array of keys, you can fetch multiple values.
Method Signature
mapGetMultiple<T>(table: string, keys: string[])
Getting Multiple Table Values
const number = req.body.number;
const otherNumber = "447000000001";
const customers = await state.mapGetMultiple("customers", [number, otherNumber]);
Scan Table Values
By providing a pattern you can scan a table, starting at a specified cursor.
Method Signature
mapScan(table: string, cursor: string, pattern: string, count: number)
Scanning Table Values
const name = req.body.name;
await state.mapScan("customers", "0", name, 0);
Getting All Table Values
Using a table name, you can fetch all the stored values.
Method Signature
mapGetValues<T>(table: string)
Getting All Table Values
const customers = await state.mapGetValues("customers");
Get a Table
Using a table name, you can fetch the entire table.
Method Signature
mapGetAll<T>(table: string)
Getting a Table
const customerNumberPairs = await state.mapGetAll("customers");
Get a Table's Length
Using a table name, you can fetch the length of the table.
Method Signature
mapLength<T>(table: string)
Getting a Table's Length
const tableLength = await state.mapLength("customers");
Check a Table Key Exists
Using a table name and key, you can check if a key exists on a table.
Method Signature
mapExists(table: string, key: string)
Checking a Table Key Exists
const number = req.body.number;
const isExistingCustomer = await state.mapExists("customers", number);
Delete Table Values
Using a table name and a list of keys, you can delete a values.
Method Signature
mapDelete(table: string, keys: string[])
Deleting Table Values
const number = req.body.number;
await state.mapDelete("customers", [number]);
Delete a Table
Using a table name, you can delete the whole table.
Method Signature
delete(table: string)
Deleting a Table
await state.delete("customers");