BrowstorJS: un database per Javascript

Mattepuffo's logo
BrowstorJS: un database per Javascript

BrowstorJS: un database per Javascript

BrowstorJS è un database per Javascript che possiamo usare sia nel "browser" che in applicazioni scritte con Angular o affini.

Può essere molto utile anche nel caso di PWA; inoltre è asincrono, ed usa le promise.

Se vogliamo usarlo nelle nostre pagine web, ci basta aggiungere la libreria in questo modo:

<script src="https://cdn.jsdelivr.net/npm/browstorjs/dist/browstorjs.js"></script>

Fatto ciò, ecco un codice di esempio:

window.onload = async function () {
	const db = await BrowstorJS.open();

	await db.set('chiave', 'valore');
	await db.set('chiave2', 'valore2');

	await db.get('chiave').then(item => console.log(item));
	await db.remove('chiave');
	await db.search((key, value) => {
		console.log(key.startsWith('chiave2'));
	});

	await db.getKeys().then(items => {
		console.log(items);
	});
	await db.reset();
}

Enjoy!


Condividi

Commentami!