Skip to content

Software Development at Program Tom LTD

Place for coding, programming, development and software in general.

Menu
  • Blog
  • PDF Booklets
  • Dev Utils & Content
  • Java Spring Boot Or Web Apps
  • English
    • български
    • English
    • Español
    • Português
    • हिन्दी
    • Русский
    • Deutsch
    • Français
    • Italiano
    • العربية
  • About Us
Menu
IndexedDB Database

How To Use Indexed DB – a Database in the Web Browser

Posted on December 27, 2020October 9, 2023 by Toma Velev

Can I Use IndexedDB – the Database of the Web Browsers?

IndexedDB Database is the accepted (standardized) way of storing semi-structured & organized information in the Web Browsers. It is supported by most of them in their latest version: https://caniuse.com/indexeddb. In programming terms – you could check the support programmatically this way:

window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
if (!window.indexedDB) {
    console.log("Your browser doesn't support a stable version of IndexedDB. Such and such feature will not be available.");
}

Should I Use IndexedDB – the Database of the Web Browsers?

  • Do you have Data Models that are structured?
  • Do you have Business logic that could work offline – without the help of a Back-End?
  • Do you want your browser client to function like app?
  • Do you really need it like that? Who is your user?
  • Are you going to support older, legacy browsers or you gonna look into the future where the users are having up-to-date software?

All in All – This is an architectural decision that is not made so much from the technical detail so much – than – the users and their use case, the client, the environment and platform of execution, and at last place – the developers.

How Do I Use IndexedDB – the Database of the Web Browsers?

The Database has API presented as a versioned file. First it needs to be opened. If requested versions of the file and the request do not match, an update callback is called by the API.

  _dbPromise = indexedDB.open("offlineNotesWebPage", 1);
        var self = _dbPromise;

        var onerror = (e) => {
            console.log(e);
        };
        _dbPromise.onerror = onerror;
        _dbPromise.onsuccess = function (event) {
            //resultCallback.call(self.result, self.result);
        };
        _dbPromise.onupgradeneeded = function (event) {...}

After successful opening of the file, the API offers a connection object that allows opening transactions against the files. On successful initialization of database session, read (and if requested – also write) operations are allowed on Object Stores (Database Tables). There are functions for defining data models and all the standard CRUD operations: https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore. What is the most tricky thing is – that they are all a-synchronically executed from the usual call flow. Whatever result or failure error response gets delivered via callback functions and many software developers will have a hard time Debugging problems.

Utility To Boost your use of IndexedDB Database

License for – Database Application Generator /GeneratorApp/ – Version – All – Executable Build

The Utility for Generating Source Code around Data Model Definition has Indexed DB as implemented Target Platform.

It Generates JavaScript Model Definitions:

function Note() {
    this.id = 0;
    this.content = "";
}

JavaScript Data Access classes:

initDB = function (resultCallbackWithIndexedDBConnection) { ... }

function NoteDao() {}

NoteDao.loadRecord = function (id, callback) { ... }
NoteDao.getPage = function(offset, callback, total) { ... }
NoteDao.save = function (f, callback) { ... }
NoteDao.removeRecord = function (id, callback) { ... }

and separated from the others – Plain HTML + JavaScript view Layer:

function reloadPage() {
            NoteDao.getPage(0, (result) => {...});
        var notes = document.getElementById('notes');
----

<h3>Note</h3>
…
<table id=”notes” width=”100%”>… </table>
<div id=”totalNotes”>Total : 0</div>
<button id=”addeditnotebutton”>Add</button>

<form id=”addeditNoteForm”><input id=”noteId” type=”hidden” />
<div><label for=”noteContent”> <input id=”noteContent” name=”noteContent” type=”text” /></label></div>
<input id=”addeditnotesubmit” type=”submit” value=”Save” /> <input id=”addeditnotecancel” type=”submit” value=”Clear” />
</form>

It is replaceable by whatever User Interface Technology you’d like. The example apps bellow are direct example of that.

Demo Apps Build with Indexed DB

https://programtom.com/developapp.online/ – A No-Code Free – Online version of my Database Application Generator. Define Data Models, Model Properties, Sync the Data Model and on second Sync a link to the build was able to be received. There is no interest in this project so currently The Building Task is turned off, but the UI is still present and you could play with it.

Simple Notes App Data Model – Note (id, content):

Offline IndexedDB – In Browser Notes Web Page – Flutter Web – Source Code

A Stuff Organizer Data Model. You’ll be able to type in places and storing locations within places (in infinite sub-levels) and at the bottom – in each place you could add items. It has the idea of organizing your stuff so one they, when you search for something (currently not implemented) the app would be able to tell you where it is located.

Offline IndexedDB – In Browser Stuff Organizer Web Page – Flutter Web – Source Code

Simple To-Do App in the Browser – Todo(id, title, is done)

Offline IndexedDB – In Browser To-Do Web Page – Flutter Web – Source Code

Similar to Stuff Organizer – Folders (with id, title, [sub-folders]), and notes (id, content) inside folders

Offline IndexedDB – In Browser Folders & Notes Web Page – Flutter Web – Source Code

This is the CRUD side of a budgeting app – Wallet (id, name, amount), money flow (amount – + or -), items (where the money comes from or flows to). Statistics are in to be implemented.

Offline IndexedDB – Personal Budget App Web Page – Flutter Web – Source Code

Very Simple App for Storing Employees.

Offline IndexedDB – In Browser Simple Employees Database Management App Web Page – Flutter Web – Source Code

Here are more tutorials from the Internet where you could look up for reference, documentation, tips and tutorials:
https://developers.google.com/web/ilt/pwa/working-with-indexeddb
https://dev.to/saurabhdaware/make-websites-work-offline-offline-storage-making-indexeddb-the-hero-1oee
https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API

  • Prompt-to-Production: How AI is Forcing Us to Build Higher Quality Software
  • Debug Web View Flutter App
  • Skipping AI? You’re a Relic – Time to Evolve or Perish!
  • 2026 Flutter Launch Blueprint: Your 10-Step Checklist to App Store Domination
  • Product Requirements Document – for different software development levels

Categories

  • Apps (25)
  • ChatGPT (27)
  • Choosing a Framework (38)
  • Flutter (281)
  • Graphical User Interface (14)
  • Marketing (119)
  • Software Development (292)
  • Spring (45)
  • StartUp (22)
  • Uncategorized (14)
  • Uncategorized (4)
  • Vaadin (16)

Tags

Algorithms (9) crypto (29) flutterdev (39) General (86) Java (7) QR & Bar Codes (3) Software Dev Choices (33) Spring Boot (1) standards (1) Theme (3) User Authentication & Authorization (9) User Experience (10) Utilities (19) WordPress (11)

Product categories

  • All Technologies (87)
    • Flutter Apps (26)
    • GPT (4)
    • Java (39)
    • Native Android (3)
    • PHP (9)
    • Spring (Boot) / Quarkus (36)
    • Utils (15)
    • Vaadin 24+ (28)
    • Vaadin 8 (1)
  • Apps (18)
    • Employees DB (1)
    • Notes (6)
    • Personal Budget (1)
    • Recipes Book (1)
    • Stuff Organizer (1)
    • To-Do (2)
  • PDF Books (3)
  • Source Code Generators (8)

Recent Posts

  • Prompt-to-Production: How AI is Forcing Us to Build Higher Quality Software
  • Debug Web View Flutter App
  • Skipping AI? You’re a Relic – Time to Evolve or Perish!
  • 2026 Flutter Launch Blueprint: Your 10-Step Checklist to App Store Domination
  • Product Requirements Document – for different software development levels

Post Categories

  • Apps (25)
  • ChatGPT (27)
  • Choosing a Framework (38)
  • Flutter (281)
  • Graphical User Interface (14)
  • Marketing (119)
  • Software Development (292)
  • Spring (45)
  • StartUp (22)
  • Uncategorized (14)
  • Uncategorized (4)
  • Vaadin (16)