KeyValueStore
Hierarchy
- KeyValueStore- KeyValueStore
 
Index
Properties
externalreadonlyconfig
externalreadonlyid
externaloptionalreadonlyname
Methods
externaldrop
- Removes the key-value store either from the Apify cloud storage or from the local directory, depending on the mode of operation. - Returns Promise<void>
externalforEachKey
- Iterates over key-value store keys, yielding each in turn to an - iterateefunction. Each invocation of- iterateeis called with three arguments:- (key, index, info), where- keyis the record key,- indexis a zero-based index of the key in the current iteration (regardless of- options.exclusiveStartKey) and- infois an object that contains a single property- sizeindicating size of the record in bytes.- If the - iterateefunction returns a Promise then it is awaited before the next call. If it throws an error, the iteration is aborted and the- forEachKeyfunction throws the error.- Example usage - const keyValueStore = await KeyValueStore.open();
 await keyValueStore.forEachKey(async (key, index, info) => {
 console.log(`Key at ${index}: ${key} has size ${info.size}`);
 });- Parameters- externaliteratee: KeyConsumer- A function that is called for every key in the key-value store. 
- externaloptionaloptions: KeyValueStoreIteratorOptions- All - forEachKey()parameters.
 - Returns Promise<void>
externalgetAutoSavedValue
- Type parameters- T: Dictionary<any> = Dictionary<any>
 - Parameters- externalkey: string
- externaloptionaldefaultValue: T
 - Returns Promise<T>
getPublicUrl
- Returns a URL for the given key that may be used to publicly access the value in the remote key-value store. - Parameters- key: string
 - Returns string
externalgetValue
- Gets a value from the key-value store. - The function returns a - Promisethat resolves to the record value, whose JavaScript type depends on the MIME content type of the record. Records with the- application/jsoncontent type are automatically parsed and returned as a JavaScript object. Similarly, records with- text/plaincontent types are returned as a string. For all other content types, the value is returned as a raw- Bufferinstance.- If the record does not exist, the function resolves to - null.- To save or delete a value in the key-value store, use the KeyValueStore.setValue function. - Example usage: - const store = await KeyValueStore.open();
 const buffer = await store.getValue('screenshot1.png');- Type parameters- T = unknown
 - Parameters- externalkey: string- Unique key of the record. It can be at most 256 characters long and only consist of the following characters: - a-- z,- A-- Z,- 0-- 9and- !-_.'()
 - Returns Promise<null | T>- Returns a promise that resolves to an object, string or - Buffer, depending on the MIME content type of the record.
externalsetValue
- Saves or deletes a record in the key-value store. The function returns a promise that resolves once the record has been saved or deleted. - Example usage: - const store = await KeyValueStore.open();
 await store.setValue('OUTPUT', { foo: 'bar' });- Beware that the key can be at most 256 characters long and only contain the following characters: - a-zA-Z0-9!-_.'()- By default, - valueis converted to JSON and stored with the- application/json; charset=utf-8MIME content type. To store the value with another content type, pass it in the options as follows:- const store = await KeyValueStore.open('my-text-store');
 await store.setValue('RESULTS', 'my text data', { contentType: 'text/plain' });- If you set custom content type, - valuemust be either a string or- Buffer, otherwise an error will be thrown.- If - valueis- null, the record is deleted instead. Note that the- setValue()function succeeds regardless whether the record existed or not.- To retrieve a value from the key-value store, use the KeyValueStore.getValue function. - IMPORTANT: Always make sure to use the - awaitkeyword when calling- setValue(), otherwise the crawler process might finish before the value is stored!- Type parameters- T
 - Parameters- externalkey: string- Unique key of the record. It can be at most 256 characters long and only consist of the following characters: - a-- z,- A-- Z,- 0-- 9and- !-_.'()
- externalvalue: null | T- Record data, which can be one of the following values: - If null, the record in the key-value store is deleted.
- If no options.contentTypeis specified,valuecan be any JavaScript object and it will be stringified to JSON.
- If options.contentTypeis set,valueis taken as is and it must be aStringorBuffer. For any other value an error will be thrown.
 
- If 
- externaloptionaloptions: RecordOptions- Record options. 
 - Returns Promise<void>
staticexternalgetAutoSavedValue
- Type parameters- T: Dictionary<any> = Dictionary<any>
 - Parameters- externalkey: string
- externaloptionaldefaultValue: T
 - Returns Promise<T>
staticopen
- Parameters- optionalstoreIdOrName: null | string
- options: StorageManagerOptions = {}
 - Returns Promise<KeyValueStore>