Category: indexeddb

  • Khóa học miễn phí IndexedDB – Indexes nhận dự án làm có lương

    IndexedDB – Indexes



    Indexes are a kind of object store used to retrieve data from the reference object stored by a specified property. Even though an index is inside the reference object store and contains the same data, instead of the reference store”s primary key it uses the specified property as its key path.

    Indexes are used to define a unique constraint on your data and they are made when the object stores are created. To create an index, call the createIndex method on an object store instance −

    Syntax

    var myIDBIndex = objectStore.createIndex(indexName, keyPath);
    var myIDBIndex = objectStore.createIndex(indexName, keyPath, objectParameters);
    

    This method creates and returns an index object. The method creates an index that takes the following arguments −

    • Index name − The name of the index.

    • Keypath − We mention the primary key here.

    • Object Parameters − There are two object parameters.

    • Unique − Duplicate values cannot be added.

    • Multi entry − If true, the index will add an entry in the index for each array element when the keyPath resolves to an Array. If false, it will add one single entry containing the Array.

    Example

    The following example shows the implementation of indexes in an object store −

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>Document</title>
    </head>
    <body>
       <script>
          const request = indexedDB.open("botdatabase",1);
          request.onupgradeneeded = function(){
             const db = request.result;
             const store = db.createObjectStore("bots",{ keyPath: "id"});
             store.createIndex("branch_db",["branch"],{unique: false});
          }
          request.onsuccess = function(){
             document.write("database opened successfully");
             const db = request.result;
             const transaction=db.transaction("bots","readwrite");
             const store = transaction.objectStore("bots");
             const branchIndex = store.index("branch_db");
             store.add({id: 1, name: "jason",branch: "IT"});
             store.add({id: 2, name: "praneeth",branch: "CSE"});
             store.add({id: 3, name: "palli",branch: "EEE"});
             store.add({id: 4, name: "abdul",branch: "IT"});
             store.put({id: 4, name: "deevana",branch: "CSE"});
             transaction.oncomplete = function(){
                db.close;
             }
          }
       </script>
    </body>
    </html>
    

    Output

    branchIndex:
    1
    [''CSE'']
    0: "CSE"
    length: 1
    4
    {id: 4, name: ''deevana'', branch: ''CSE''}
    branch: "CSE"
    id: 4
    name: "deevana"
    2
    [''EEE'']
    0: "EEE"
    length: 1
    3
    {id: 3, name: ''palli'', branch: ''EEE''}
    branch: "EEE"
    id: 3
    name: "palli"
    3
    [''IT'']
    0: "IT"
    length: 1
    1
    {id: 1, name: ''jason'', branch: ''IT''}
    branch: "IT"
    id: 1
    name: "jason"
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí IndexedDB – Deleting Data nhận dự án làm có lương

    IndexedDB – Deleting Data



    There are many situations where we need to delete data from the database; be it for storage purposes or just removing unwanted data to free up space. If we want to delete this unnecessary data from a database we can use the .delete() function

    Syntax

    const request = objectStore.delete(data);
    

    We use the delete() function to delete the fields of the database which are not required.

    Example

    Let us look at an example script to delete data −

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>Document</title>
    </head>
    <body>
       <script>
          const request = indexedDB.open("botdatabase",1);
          request.onupgradeneeded = function(){
             const db = request.result;
             const store = db.createObjectStore("bots",{ keyPath: "id"});
          }
          request.onsuccess = function(){
             document.write("database opened successfully");
             const db = request.result;
             const transaction=db.transaction("bots","readwrite");
             const store = transaction.objectStore("bots");
             store.add({id: 1, name: "jason",branch: "IT"});
             store.add({id: 2, name: "praneeth",branch: "CSE"});
             store.add({id: 3, name: "palli",branch: "EEE"});
             store.add({id: 4, name: "abdul",branch: "IT"});
             store.put({id: 4, name: "deevana",branch: "CSE
             const deletename = store.delete(1);
             deletename.onsuccess = function(){
                document.write("id : 1 has been deleted");
             }
             transaction.oncomplete = function(){
                db.close;
             }
          }
       </script>
    </body>
    </html>
    

    Output

    database opened successfully
    id : 1 has been deleted
    

    The database after deletion of id:1 =

    0  2
    {id: 2, name: ''praneeth'', branch: ''CSE''}
    1  3
    {id: 3, name: ''palli'', branch: ''EEE''}
    2  4
    {id: 4, name: ''deevana'', branch: ''CSE''}
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí IndexedDB – Installation nhận dự án làm có lương

    IndexedDB – Installation



    Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.

    • You can download the visual studio code from its official website –

    • Select the version you want based on your PC configuration and OS.

    • Once downloaded you can install it directly on your computer.

    Installing the Visual Studio Code installer on Windows

    First of all download the Visual Studio Code installer for Windows as specified above −

    • Once it is downloaded, run the installer.
    Visual
    • Then, accept the agreement and click on next.
    Agreement
    • Now, click on “create a desktop icon” so that it can be accessed from the desktop, and click on Next.
    Setup
    • Then, click on the install button.
    Install
    • Finally, after installation completes, click on the finish button, and the visual studio code will open.

    Code Setup
    • Now Visual Studio code is successfully installed on your device, start writing code on this code editor.

    Downloading, Installing, and Creating a Node.js project (optional)

    Now after installing the visual studio code we need to install Node.js

    Downloading Node.JS

    • You can download Node.js from its official website which is https://nodejs.org/en/.

    • Select the version of your choice based on your computer”s configuration.

    • The LTS version is preferable as it is a more stable version and it stands for Long Term Support.

    Installing Node.js

    Follow the steps given below to install Node.js in your system −

    Step 1 − Now that the Node.js has opened. You’ll find this window pop up Click on next.

    Nodejs

    Step 2 − You will be redirected to the “End-User License Agreement” window. Accept the agreement and click on Next.

    Nodejs Setup

    Step 3 − In the next window you need to select the “Destination Folder”. Change the existing folder or, use the default folder mentioned and then click Next.

    Destination

    Step 4 − Click Next in the “Custom Setup” and “Tools For Native Modules” windows.

    Step 5 − Now, thw setup is ready click Install, to install the selected modules.

    Ready Nodejs

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí IndexedDB – Creating Data nhận dự án làm có lương

    IndexedDB – Creating Data



    Before creating data we need to know how data is transferred. IndexedDB opens transactions and each of its data operations are carried out inside each of these transactions. Each operation has four steps −

    • Get database object
    • Open transaction on the database
    • Open object store on the transaction
    • Operate on the object store

    Operations in IndexedDB are −

    • create
    • read
    • update
    • delete

    Firstly, to perform any operation in our database, we need to open a transaction. After a transaction is opened, we need to get the object store we require. These object stores are provided only according the requirements mentioned when the transaction is created. Then whatever data that is needed can be added later.

    Functions are used to perform the given operation (if any). For example, we use the add() function to add data into the database or to add a new entry.

    Syntax

    Following is the syntax of creating data into a database −

    ar request = objectStore.add(data);
    

    We can add data to an object store by using the add() or put() function.

    Example

    In the following example, we are inserting data into the object store using the add() method in JavaScript −

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>creating data</title>
    </head>
    <body>
       <script>
          const dbName = "Database";
          var request = indexedDB.open("Database", 2);
          request.onupgradeneeded = event => {
             var db = event.target.result;
             var objectStore = db.createObjectStore("student",{ keyPath :"rollno" } );
          };
          request.onsuccess = event => {
             document.write("Database opened successfully");
             var db = event.target.result;
             var transaction = db.transaction("student", "readwrite");
             var objectStore = transaction.objectStore("student");
             objectStore.add({ rollno: 160218737028, name: "jason", branch: "IT" });
             objectStore.add({ rollno: 160218733028, name: "tarun", branch: "EEE" });
             objectStore.add({ rollno: 160218732028, name: "lokesh", branch: "CSE" });
             objectStore.add({ rollno: 160218737025, name: "abdul", branch: "IT" });
             objectStore.add({ rollno: 160218736055, name: "palli", branch: "MECH" });
          }
          transaction.oncomplete = function () {
             db.close();
          };
       </script>
    </body>
    </html>
    

    Output

    0 160218732028
    {rollno: 160218732028, name: ''lokesh'', branch: ''CSE''}
    1 160218733028
    {rollno: 160218733028, name: ''tarun'', branch: ''EEE''}
    2 160218736055
    {rollno: 160218736055, name: ''palli'', branch: ''CSE''}
    3 160218737025
    {rollno: 160218737025, name: ''abdul'', branch: ''IT''}
    4 160218737028
    {rollno: 160218737028, name: ''jason'', branch: ''IT''}
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí IndexedDB – Connection nhận dự án làm có lương

    IndexedDB – Connection



    A database is an organized collection of structured data stored in a computer system. To perform operations on data we need to connect to a database. In this chapter, we will discuss how to create/connect to a database, open a database, and delete a database.

    Creating a database − You can create a database in IndexedDB using the open() function. Following is the syntax of this function.

    let openRequest = indexedDB.open(name, version);
    

    Where,

    • name is the name of the database you need to create.
    • version is the version of the database that is to be created. The default value of this parameter is 1. If you omit this value, the version is considered as 1.

    The version value you pass to this function should not be less than the current version (of the IndexedDB). This function returns 1 if the database is created successfully and it returns 0 in case of a failure.

    Example

    Following is the example to create a database in IndexedDB

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>Indexed db</title>
    </head>
    <body>
       <script>
          //Creating a database
          const request = indexedDB.open("myDatabase", 1);
          if(indexedDB){
             document.write("Database Created......");
          }
       </script>
    </body>
    </html>
    

    Output

    If you save the above code in a file “test.html” and run it, the following message will be displayed on the browser −

    Database Created......
    

    Verification

    Since IndexedDB is the browser”s built-in database you observe the created database in the browser itself.

    Right-click on the resultant page, click on inspect element and select the Application tab. You can see the IndexedDB database there if you expand it you can see the created database file as shown below −

    Indexeddb Files

    Generating Handlers

    An event is an action performed on an HTML element. Using JavaScript we can handle these events. From now on we use JavaScript handlers (to make this clearer).

    If the request is a success, we use the onsuccess event.

    request.onerror = event => {
       // Do something (ex: document.write("error");
    };
    

    If the request is a failure, we use onerror event.

    request.onsuccess = event => {
       // Do something (ex : document.write("success");
    };
    

    When you create a database or increase the version number of an existing database we use onupgradeneeded event.

    request.onupgradeneeded = event => {
       var db = event.target.result;
    };
    

    Example

    Following example displays the message “database creation success”. If the database creation is successful. In here we are using the onsuccess and onerror handlers to display these messages.

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>Handlers</title>
    </head>
    <body>
       <script>
          const request = indexedDB.open("DATABASE", 1);
          request.onsuccess = function (){
             document.write("Database created successfully...")
          }
          request.onerror = function(){
             document.write("database creation error");
          }
          request.onupgradeneeded = function(event){
             var db = event.target.result;
          }
       </script>
    </body>
    </html>
    

    Output

    If you save the above code in a file “test.html” and run it, the following message will be displayed on the browser −

    Database created successfully...
    

    Connecting to an existing database

    To interact with IndexedDB, we use JavaScript. The code we write in JavaScript doesn”t interact with databases directly. We need to connect with the database using a connection object to manipulate the objects of the database.

    Opening a database directly creates a connection. There can be multiple connections to a database. When a connection is initially created it is in the open state.

    You can connect to an IndexedDB database using the open() function (which we used to create a database).

    Syntax

    Following is the syntax to connect to an existing database.

    let openRequest = indexedDB.open(name, version);
    

    Example

    A JavaScript example that interacts with an existing database using a connection object is given below −

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>OPENING A DATABASE</title>
    </head>
    <body>
       <script>
          const request = indexedDB.open("DATABASE", 1);
          request.onsuccess = function (){
             document.write("<br> Database created successfully")
          }
          const requestone = indexedDB.open("Database1",2);
          requestone.onsuccess = function(){
             document.write("<br> Database created successfully");
          }
          const requesttwo = indexedDB.open("DATABASE",1);
          requesttwo.onsuccess = function(){
             document.write("<br> Database opened successfully");
          }
       </script>
    </body>
    </html>
    

    Output

    The above program prints the following output on the browser −

    Database created successfully
    Database opened successfully
    Database created successfully
    

    If the request is a success, then the event named onsuccess will be called.

    Another way to check databases in the browser

    In addition to the inspect element, there is another way to check the IndexedDB database in the browser.

    In the top right corner, there will be a customize and control button, Click it.

    Select the More tools option in the list and then select Developer tools.

    More Tools

    On the next page select the Application tab where you can see the IndexedDB database.

    Opening Database

    Deleting a database

    If there is an excess of any database which we do not need or it unnecessarily occupies space, we can delete it. To delete a database we can use the deleteDatabase() function.

    Following is the syntax of the deleteDatabase() function −

    let deleteRequest = indexedDB.deleteDatabase(name)
    

    Here, the name parameter is the name of the database that we want to delete.

    Example

    Following example creates a database named TestDatabase and deletes it using the deleteDatabase() function.

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>Indexed db</title>
    </head>
    <body>
       <script>
          const request = indexedDB.open("TestDatabase", 1);
          request.onsuccess = function () {
             document.write("Database Created Successfully");
          };
          var req = indexedDB.deleteDatabase("TestDatabase");
          req.onsuccess = function () {
             document.write("Database Deleted Successfully");
          };
          req.onerror = function () {
             document.write("Couldn''t delete the database");
          };
       </script>
    </body>
    </html>
    

    Deleting a database Directly From the browser

    Once you create a database, you can directly delete it database from the browser. To do so, follow the steps given below −

    Step 1 − Open the page where you can see the IndexedDB database (storage) in the browser, using one of the following ways

    • Inspect option − Right−click → Inspect → Application or,

    • Developer tools − Customize and Control Options → More tools → Developers tools → Application

    Step 2 − If you expand the IndexedDB storage, you can observe the list of databases created as shown below.

    Test

    Step 3 − Click on the database you want to delete. On the right−hand side, you will find the Delete Database button. If you click on it, this database will be deleted.

    Delete Database

    Closing a database

    To close a database we need to use the function IDBDatabase.close()

    Syntax

    IDBDatabase.close();
    

    The close() method of the IDBDatabase interface returns immediately and closes the connection.

    The connection is not closed until all transactions are complete but, new transactions cannot be created for this connection and methods throw exceptions if the closing operation is pending.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí IndexedDB – Reading Data nhận dự án làm có lương

    IndexedDB – Reading Data



    We enter data into the database, and we need to call the data to view the changes and also for various other purposes.

    We must call the get() method on the object store to read this data. The get method takes the primary key of the object you want to retrieve from the store.

    Syntax

    var request = objectstore.get(data);
    

    Here, we are requesting the objectstore to get the data using get() function.

    Example

    Following example is an implementation of requesting the objectstore to get the data −

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>Document</title>
    </head>
    <body>
       <script>
          const request = indexedDB.open("botdatabase",1);
          request.onupgradeneeded = function(){
             const db = request.result;
             const store = db.createObjectStore("bots",{ keyPath: "id"});
          }
          request.onsuccess = function(){
             document.write("database opened successfully");
             const db = request.result;
             const transaction=db.transaction("bots","readwrite");
             const store = transaction.objectStore("bots");
             store.add({id: 1, name: "jason",branch: "IT"});
             store.add({id: 2, name: "praneeth",branch: "CSE"});
             store.add({id: 3, name: "palli",branch: "EEE"});
             store.add({id: 4, name: "abdul",branch: "IT"});
             const idquery = store.get(4);
             idquery.onsuccess = function(){
                document.write("idquery",idquery.result);
             }
             transaction.oncomplete = function(){
                db.close;
             }
          }
       </script>
    </body>
    </html>
    

    Output

    database opened successfully
    idquery {id: 4, name: ''abdul'', branch: ''IT''}
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí IndexedDB – Updating Data nhận dự án làm có lương

    IndexedDB – Updating Data



    After we created the data, the next step is to perform various operations on it; so we need to update the data regularly. We also need to update the data in the case where we entered data incorrectly into the database. Here, we have to specify a read−write transaction because we want to write to the database, not just read from it.

    If we want to modify it or make an entry which is already present in the database we use the put() function.

    Syntax

    var requestUpdate = objectStore.put(data);
    

    We use the put() function on the object store for which the transaction happened and we need to update data.

    Example

    Let us look at the script below to understand how to update or modify the data in objectstore using put() function −

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>Document</title>
    </head>
    <body>
       <script>
          const request = indexedDB.open("botdatabase",1);
          request.onupgradeneeded = function(){
             const db = request.result;
             const store = db.createObjectStore("bots",{ keyPath: "id"});
          }
          request.onsuccess = function(){
             document.write("database opened successfully");
             const db = request.result;
             const transaction=db.transaction("bots","readwrite");
             const store = transaction.objectStore("bots");
             store.add({id: 1, name: "jason",branch: "IT"});
             store.add({id: 2, name: "praneeth",branch: "CSE"});
             store.add({id: 3, name: "palli",branch: "EEE"});
             store.add({id: 4, name: "abdul",branch: "IT"});
             store.put({id: 4, name: "deevana",branch: "CSE"});
             const idquery = store.get(4);
             idquery.onsuccess = function(){
                document.write("idquery",idquery.result);
             }
             transaction.oncomplete = function(){
                db.close;
             }
          }
       </script>
    </body>
    </html>
    

    Output

    database opened successfully
    idquery {id: 4, name: ''deevana'', branch: ''CSE''}
    Previously the data stored in id: 4 was
    Name: abdul Branch : IT
    But as we updated the entry the values are changed.
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí Using getAll() Functions nhận dự án làm có lương

    IndexedDB – Using getAll() Function



    In the previous sections, we only retrieved objects from the store one at a time. Now we can retrieve all the data or subsets of the object stores. The get all method returns all the objects in the object store using the getAll() function

    Syntax

    ObjectStore.getAll(optionalConstraint);
    

    We can directly call getAll() to return all the objects stored in the object store or else we can specify an optional constraint for example red colored cars from a car database

    Example

    In the following example script, we are calling the getAll() method to return all the objects stored in the object store at once −

    <!DOCTYPE html>
    <html lang="en">
    <head>
       <title>Document</title>
    </head>
    <body>
       <script>
          const request = indexedDB.open("botdatabase",1);
          request.onupgradeneeded = function(){
             const db = request.result;
             const store = db.createObjectStore("bots",{ keyPath: "id"});
             store.createIndex("branch_db",["branch"],{unique: false});
          }
          request.onsuccess = function(){
             document.write("database opened successfully");
             const db = request.result;
             const transaction=db.transaction("bots","readwrite");
             const store = transaction.objectStore("bots");
             const branchIndex = store.index("branch_db");
             store.add({id: 1, name: "jason",branch: "IT"});
             store.add({id: 2, name: "praneeth",branch: "CSE"});
             store.add({id: 3, name: "palli",branch: "EEE"});
             store.add({id: 4, name: "abdul",branch: "IT"});
             store.put({id: 4, name: "deevana",branch: "CSE"});
             const query = branchIndex.getAll(["IT"]);
             query.onsuccess = function(){
                document.write("query",query.result);
             }
             transaction.oncomplete = function(){
                db.close;
             }
          }
       </script>
    </body>
    </html>
    

    Output

    database opened successfully
    query (1) [{...}]
    arg1:(1) [{...}]
    0:{id: 1, name: ''jason'', branch: ''IT''}
    length:1
    [[Prototype]]:Array(0)
    [[Prototype]]:Object
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí IndexedDB – Introduction nhận dự án làm có lương

    IndexedDB – Introduction



    A database management system provides a mechanism for the storage and retrieval of data. There are various kinds of databases available mostly used ones among them are −

    • Hierarchical databases
    • Network databases
    • Object-oriented databases
    • Relational databases
    • NoSQL databases

    NoSQL databases

    A NoSQL database (sometimes called Not Only SQL) is a database that provides a mechanism to store and retrieve data other than the tabular relations used in relational databases. These databases are schema-free, support easy replication, have simple API, are eventually consistent, and can handle huge amounts of data (big data).

    There are different types of NoSQL databases also like −

    • Document databases.
    • Key-value stores.

      Column-oriented databases.

      Graph databases.

    What is IndexedDB

    Indexed Database is a type of NoSQL database or Non−relational structured query language. It is a transactional database system, like an SQL−based RDBMS. However, unlike SQL−based RDBMSs, which use fixed-column tables, IndexedDB is a JavaScript−based object-oriented database.

    It is used when we need to store significant amounts of data on the server side and faster than local storage. Since it stores the data in the browser it can be used online and offline too. Using this, you can create a web application (with rich query abilities) that can run whether an internet connection is available or not.

    Key Characteristics of IndexedDB

    Following are the key characters of the IndexedDB database −

    IndexedDB is a NoSQL database that stores key−value pairs. It can store almost any kind of value by keys or multiple key types.

    • As mentioned, IndexedDB follows a transactional database model − Transaction is a wrapper class around the operation or group of operations so that data integrity is maintained. You don”t want data to be altered or missed so if the transaction is failed a callback is rolled out.

    • IndexedDB does not use Structured Query Language − Since IndexedDB uses a NoSQL database it doesn’t use SQL, instead, it uses queries on Indexes to produce data via cursors or the getAll() method to iterate around different sets.

    • IndexedDB uses a lot of requests − Requests are objects that receive the success or failure of DOM events (DOM – HTML DOM events allow JavaScript to register different event handlers on elements in an HTML document). DOM events are success or error which has a target property that indicates the flow of the request.

      Success events can’t be canceled but, error events can be canceled. There are a lot of requests in IndexedDB like on success, onerror and addEventListener(), removeEventListener() on them. For getting to know the status of the request we also have ready state, result, and error code properties.

    • IndexedDB needs to follow the same origin − Origin is the URL of the document in which the script is being written, each origin has some databases under it and each database has its name to be identified by the origin. The security boundary imposed on IndexedDB prevents applications from accessing data with a different origin.

      For example, if we take a URL and take different subdirectories of it, it can retrieve data but if we change location to port 8080 and try to retrieve data from the usual URL and the changed port, we cannot retrieve the data.

    Terminology

    Following are various important terms in indexedDB that you should know before proceeding further −

    • Database − In IndexedDB database is the highest level which contains the object stores that contain the data.

    • Object Stores − Object stores are the data storage entities of IndexedDB. Think of it as tables in RDBMS where we store data based on the type of data we want to store (ex: id, name, roll no, etc).

    • Transaction − For any database operation we do the following process.

      • Get database object
      • Open transaction on the database
      • Open object store on the transaction and then, operate on object store.

      So basically, a transaction is a wrapper function that is connected to every database and it ensures data integrity such that if the transaction is canceled or any error happens it will call back to where the transaction has not yet been begun.

    • Index − Think of object store as a table and we use indexes to retrieve data of a single property from them. Ex: Name, age, etc.

    • Cursor − In a database, if we need to traverse multiple records from object stores we use cursors.

    Support for IndexedDB

    IndexedDB is a database in a browser so, we need to check if it is supported by the current/existing browser. To do so, paste the following code in an text editor save it as test.html and run it your browser.

    const indexedDB =
       window.indexedDB ||
       window.mozIndexedDB ||
       window.webkitIndexedDB ||
       window.msIndexedDB ||
       window.shimIndexedDB;
    
    if (!indexedDB) {
       document.write("IndexedDB could not be found in this browser.");
    }
    const request = indexedDB.open("MyDatabase", 1);
    

    If IndexedDB is supported by your browser this program gets executed successfully, an a database will be created.

    Mydatabase

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí IndexedDB – Home nhận dự án làm có lương

    IndexedDB Tutorial

    IndexedDB Tutorial







    Indexed Database is a type of NoSQL database or Non-relational structured query language. It is a transactional database system like an SQL-based RDBMS. However, unlike SQL-based RDBMSs, which use fixed-column tables, IndexedDB is a JavaScript-based object-oriented database.

    Audience

    This tutorial is designed for Software Professionals who are willing to learn IndexedDB Database in simple and easy steps. It will throw light on IndexedDB concepts and after completing this tutorial you will be at an intermediate level of expertise, from where you can take yourself at higher level of expertise.

    Prerequisites

    Before you start proceeding with this tutorial, we are assuming that you have a brief knowledge understanding of JavaScript.

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc