Back to Puter

puter.kv.flush()

src/docs/src/KV/flush.md

26.06.21.1 KB
Original Source

Will remove all key-value pairs from the user's key-value store for the current app.

Syntax

js
puter.kv.flush()

Parameters

None

Return value

A Promise that will resolve to true when the key-value store has been flushed (emptied), or reject with an error on failure.

Examples

html;kv-flush
<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        (async () => {
            // (1) Create a number of key-value pairs
            await puter.kv.set('name', 'Puter Smith');
            await puter.kv.set('age', 21);
            await puter.kv.set('isCool', true);
            puter.print("Key-value pairs created/updated
");

            // (2) Rretrieve all keys
            const keys = await puter.kv.list();
            puter.print(`Keys are: ${keys}
`);

            // (3) Flush the key-value store
            await puter.kv.flush();
            puter.print('Key-value store flushed
');

            // (4) Retrieve all keys again, should be empty
            const keys2 = await puter.kv.list();
            puter.print(`Keys are now: ${keys2}
`);
        })();
    </script>
</body>