Another way is (or will be) kv storage. It's the first built in module for the web.
below code copied from article:
import{storage}from'std:kv-storage';constmain=async()=>{constoldPreferences=awaitstorage.get('preferences');document.querySelector('form').addEventListener('submit',async()=>{constnewPreferences=Object.assign({},oldPreferences,{// Updated preferences go here...});awaitstorage.set('preferences',newPreferences);});};
It uses indexedDb under the hood, but provides a convenient API similar to localStorage. With the main difference that it is asynchronous and therefore doesn't block the main thread.
VP of DevRel RapidAPI ❯ Award-winning Web Developer NodeCLI.com ❯ Google Dev Expert Web tech ❯ 2x GitHub Stars Award ❯ WordPress Core Dev ❯ TEDx Speaker ❯ "awesome example for devs" — Satya Nadella
Location
San Francisco Bay Area
Education
EE-CS Engineer turned Software Developer
Work
VP of DevRel (DX Eng., Content & Community) RapidAPI ❯ Google Dev Expert ❯ GitHub Star ❯ NodeCLI.com
So I pretty much exclusively use SQLite, just wondering when you would use a different option? Is it all personal preference, depends on the scope of the project, ease of use...? How do you decide what you're going to use when you start a (say small) project?
If you plan on having more than one process needing to make database calls or if you're expecting periods of very high traffic*.
SQLite works great as the database engine for most low to medium traffic websites (which is to say, most websites). The amount of web traffic that SQLite can handle depends on how heavily the website uses its database. Generally speaking, any site that gets fewer than 100K hits/day should work fine with SQLite. The 100K hits/day figure is a conservative estimate, not a hard upper bound. SQLite has been demonstrated to work with 10 times that amount of traffic.
I'm a Systems Reliability and DevOps engineer for Netdata Inc. When not working, I enjoy studying linguistics and history, playing video games, and cooking all kinds of international cuisine.
So I pretty much exclusively use SQLite, just wondering when you would use a different option? Is it all personal preference, depends on the scope of the project, ease of use...? How do you decide what you're going to use when you start a (say small) project?
Unless I actually need some functionality that's provided by having an SQL interface, I try to avoid it. I have no issue 'speaking' basic SQL, it's just that in most cases, you don't actually need it, so ti largely just adds overhead (SQL is complicated from an implementation perspective). See for example all of the major FOSS web browsers historically using SQLite for their cache, when all they really need is flat files with directory hashing and a simple 1:1 index.
Other disadvantages to SQLite specifically include it not being truly concurrent-access safe, and reimplementing much of the work the underlying filesystem is already doing.
Personally, if it's just simple data serialization, I'm a fan of YAML. It's reasonably lightweight, easily extensible, widely supported, and most importantly, can be debugged even by non-programmers. It does, of course, have it's own issues, but most of them are non-issues for my typical usage.
How’s it going, I'm a Adam, a Full-Stack Engineer, actively searching for work. I'm all about JavaScript. And Frontend but don't let that fool you - I've also got some serious Backend skills.
Location
City of Bath, UK 🇬🇧
Education
11 plus years* active enterprise development experience and a Fine art degree 🎨
Indexedb with pouch in browser is quite interesting as a level up from session or local storage, or there is even sqlite WebAssembly! So stored much Database.
Another way is (or will be) kv storage. It's the first built in module for the web.
below code copied from article:
It uses indexedDb under the hood, but provides a convenient API similar to localStorage. With the main difference that it is asynchronous and therefore doesn't block the main thread.
Big fan of
lowdbwith file sync adapterSo I pretty much exclusively use SQLite, just wondering when you would use a different option? Is it all personal preference, depends on the scope of the project, ease of use...? How do you decide what you're going to use when you start a (say small) project?
If you plan on having more than one process needing to make database calls or if you're expecting periods of very high traffic*.
More info here.
Unless I actually need some functionality that's provided by having an SQL interface, I try to avoid it. I have no issue 'speaking' basic SQL, it's just that in most cases, you don't actually need it, so ti largely just adds overhead (SQL is complicated from an implementation perspective). See for example all of the major FOSS web browsers historically using SQLite for their cache, when all they really need is flat files with directory hashing and a simple 1:1 index.
Other disadvantages to SQLite specifically include it not being truly concurrent-access safe, and reimplementing much of the work the underlying filesystem is already doing.
Personally, if it's just simple data serialization, I'm a fan of YAML. It's reasonably lightweight, easily extensible, widely supported, and most importantly, can be debugged even by non-programmers. It does, of course, have it's own issues, but most of them are non-issues for my typical usage.
Indexedb with pouch in browser is quite interesting as a level up from session or local storage, or there is even sqlite WebAssembly! So stored much Database.
I've also used dexie in order to interact with IndexedDB in the browser, highly recommend it.
If you don't need more then key-value storage, idb-keyval is light and has a very similar API to localStorage.
LocalStorage should be avoided unless very specific use case (see this comment).
I'm not really sure of your point here, I'm recommending the use of IndexedDB not local storage.
The LocalStorage comment is for the author of the article.
I recommend something called json-server for prototyping, it's fantastic.
This is awesome. Thanks for the resource!
What about
IndexedDBin the browsers for client-side storage?developer.mozilla.org/en-US/docs/W...
But it have bad supporting in browsers like IE
Thank you so much for this. It's nice to know I can prototype stuff without having to figure out a database.
Lovely!
I recently deployed a system for a client with SQLite, and it thruly is a great DB system even in production environment. 100% recommended.
also indexedDB developer.mozilla.org/en-US/docs/W...
This article is right to the point.thx
Thanks Kyle!
Found small typo:
"fs.readFile('user.json'..." shuold be: "users.json".
Thanx for the great article!
Fixed! Thanks for the good spot 👍