Это видео недоступно.
Сожалеем об этом.

IndexedDB Crash Course with Javascript

Поделиться
HTML-код
  • Опубликовано: 14 авг 2024
  • 💻 More Software engineering videos • Software Engineering b...
    I found out recently about indexedDB that exists in the browser! and wanted to make a video tutorial about it. I got say the API is clunky but that did not stop me from making the video. I first explain the eventing that get triggered when you open the database, onupgradeneeded, onsuccess, onerror and when each are triggered. Then we dive into creating objectstore, then transactions both writing and reading. Pretty cool technology. We are using Javascript on the browser and visual studio code. Enjoy the tutorial guys
    The tutorial is long so here are some jump codes for your convenience
    0:00 Introduction to IndexedDB
    02:17 IndexedDB open database events Flow chart
    06:40 Tutorial start
    08:20 indexedDB.open
    10:00 onupgradeneeded, onsuccess, onerror
    20:00 The database object
    24:20 Creating object store
    29:30 Adding new object to the object store
    37:00 Unique key constraint
    38:35 View objects
    40:00 cursors
    git hub repo
    github.com/hna...
    Stay awesome
    Hussein

Комментарии • 104

  • @hnasr
    @hnasr  5 лет назад +17

    0:00 Introduction to IndexedDB
    02:17 IndexedDB open database events Flow chart
    06:40 Tutorial start
    08:20 indexedDB.open
    10:00 onupgradeneeded, onsuccess, onerror
    20:00 The database object
    24:20 Creating object store
    29:30 Adding new object to the object store
    37:00 Unique key constraint
    38:35 View objects
    40:00 cursors

    • @KingKzTuts2000
      @KingKzTuts2000 8 месяцев назад

      hi Hussein, I wanted to ask you how IDB works when you set network as offline. I had my IDB setup and stores data but when I set the network to offline in developer settings, the IDB is blank. When I set it back to online, the data is back. What is this issue, that I'm dealing with, can you please help?

  • @MrAuxiom
    @MrAuxiom 4 года назад +13

    I knew indexedDB was what i needed, that appeared so simple, so i tryed lots of tutos, but failed to implemented it correctly, I did lot of research, and even took hours and days to motivate me to understant how it was build by reading few documentations... finally with some success but as soon as i try to change it a bit or wrap it, i failed without understanding what happening.
    And it was like a delicious icecream behind an bullet proof glass.
    I guess they wanted to do something very easy to use and so i guess it is too-much abstracted for beginner.
    Now i can fucking taste it!
    Ofc it is not complete but you made it so interresting that the 45min felt like 10!
    So thx you very much, and timecode

  • @ChumX100
    @ChumX100 2 года назад +7

    IndexedDB together with web workers are really game-changing technologies for modern web app architecture. I feel they are not gaining as much traction with devs as they should be.

  • @albertalbaba5101
    @albertalbaba5101 4 года назад +3

    If all instructors are as interesting and like you then the vibe will make people understand without stress

  • @peepwebdev575
    @peepwebdev575 2 года назад +2

    I love this high level tutorial. It's like your casually speaking to other devs. "Guy this is just weird... What..." haha awesome

  • @think2086
    @think2086 3 месяца назад

    I know the other comments have said this too, but I just want to thank you and reiterate that this is EXACTLY the style of teaching we are all looking for--and you'd think it would be in great supply. But it's not. So many tutorials have major, major issues with them. But your teaching style, approach, and structure were all perfect and for that reason I subscribed.

  • @kurniadi2199
    @kurniadi2199 3 года назад +1

    No stress.. Nice! You sounded like the last villain in First Season of Loki

  • @HamzaBhatti10001
    @HamzaBhatti10001 4 года назад +2

    Better than Google Codelab!
    Saved so much time...
    Thanks 👍

  • @The-Dev-Ninja
    @The-Dev-Ninja Год назад +1

    I tried the indexeddb (without using docs) thinking that is like a json object to change like localStorage,
    but in the end is super boilerplate code to write before changing or adding a single value.
    thanks for this video, now I can understand without that complexity

  • @petermartinez8700
    @petermartinez8700 5 лет назад +12

    Your a life saver! thanks for the tutorial! seriously!

    • @hnasr
      @hnasr  5 лет назад +2

      Thanks for watching happy to help!

  • @mac5600
    @mac5600 3 года назад +2

    Just wanted to let you know you helped me out a ton with this tutorial. Thank you so much!!!!

    • @hnasr
      @hnasr  3 года назад

      All the best ⭐️ thanks for your comment

  • @raghavddps2
    @raghavddps2 3 года назад +1

    Who on earth dislikes these videos ? Great Work Hussein. You are the Ninja of backend Engineering!!

  • @techpodcastbyAnuj
    @techpodcastbyAnuj 3 года назад +2

    Great content. Loved the simplicity of your explanation

  • @ymanfaith1588
    @ymanfaith1588 3 года назад +1

    That was amazing, I like your way of explainng things. GOOD JOB

  • @thomasgiesing5845
    @thomasgiesing5845 4 года назад +3

    thanks Hussein, a good job and I like your funny speech and now I will try it on my own

    • @hnasr
      @hnasr  4 года назад +1

      Thomas Giesing thanks Tom! Good luck building your own share with us!

  • @costagmc1
    @costagmc1 2 года назад

    best idb video! Thanks nazzar,

  • @mayanksheladiya7541
    @mayanksheladiya7541 2 года назад

    I never been seen such kind of informative and learning video a very very good tutorial 🙌🙌🙌🙌

  • @CodeCatProgramming
    @CodeCatProgramming 3 года назад +1

    Incredible tutorial! Thanks for the help buddy!

    • @hnasr
      @hnasr  3 года назад +1

      No problem 👍 glad it helps!

  • @benf101
    @benf101 2 года назад

    Would it make sense to download an external database for local use in an IndexedDB, and then push updates back to the external database? More specifically, my thought here is to store it externally as encrypted, then download it, decrypt it, and store locally in IndexedDB as unencrypted. When changes are made, it encrypts and pushes the encrypted data to the external database. So basically, the local IndexedDB is like a middleman, storing the decrypted data.

  • @jpisty
    @jpisty 4 года назад +3

    This helped me a lot. Thanks man

  • @murtazamohammadi9370
    @murtazamohammadi9370 2 года назад

    Hossein brother, thanks for sharing these informative tutorial. could you make a video about indexeddb and synchronize with rest api using angular

  • @danielchambers6990
    @danielchambers6990 4 года назад +2

    Hey there my fellow programmer. New to your channel (I subscribed), watched this video thought it was real informative. Make sure when you do the transaction, to overwrite the "oncomplete" function. For example, "objectStore.transaction.oncomplete = (event) => {...}" because this makes sure the objectStore has finished before adding data into it. IDB is pretty...errr.. it is what it is. Looking forward to checking out your other videos. Thanks

    • @hnasr
      @hnasr  4 года назад +1

      Daniel Chambers thanks Daniel for the great tip! That explains why i would get random errors at times.
      I wish we just had a promise based indexedDB api to avoid all those problems
      Cheers and welcome to the channel sir.

    • @tmack729
      @tmack729 4 года назад

      @@hnasr github.com/jakearchibald/idb

    • @tmack729
      @tmack729 4 года назад

      I just realised that you mentioned in the video that you know about third party stuff, and you wish for a built-in promise-based indexedDB. Me too!

  • @sabuein
    @sabuein 2 года назад

    Thank you, brother, and Eid Saieed.

  • @sylvaingendron5442
    @sylvaingendron5442 5 лет назад +3

    Good job on this tutorial. Thank you

    • @hnasr
      @hnasr  5 лет назад

      Sylvain Gendron thanks for watching!

  • @lardosian
    @lardosian 3 года назад

    AWS uses it for their DataStore service which is part of the Amplify framework which I'm using at the moment. It's an offline first approach.

  • @vinaybammidi7123
    @vinaybammidi7123 2 года назад

    Awesome explanation

  • @alkhwarizmi5426
    @alkhwarizmi5426 2 года назад

    This guy is hilarious. Great content anyway.

  • @gauravmithas2362
    @gauravmithas2362 2 года назад

    great video @Hussein

  • @raghuvallikkat3384
    @raghuvallikkat3384 4 года назад +1

    I have used indexeddb from Angular type script. The indexed db npm packages exposes a little more better APIs for indexedDB access. Still, as you said, it is limitted. just FYI

    • @hnasr
      @hnasr  4 года назад

      Thanks for sharing Raghu

  • @lizavetameta
    @lizavetameta Год назад

    IndexedDB.js:48 Uncaught TypeError: Cannot read properties of null (reading 'transaction')
    at HTMLButtonElement.addNote
    Can someone deal with this problem?

  • @shubert9427
    @shubert9427 5 лет назад +1

    Thank you!
    This is a very helpful primer that gets right to it.

    • @hnasr
      @hnasr  5 лет назад

      Seth Hubert thanks for watching! Trying to make video shorter but its Hard to explain such big concept with short videos..

  • @damdam4969
    @damdam4969 2 года назад

    thats great. Thank you!

  • @zoliky
    @zoliky 4 года назад +1

    Hello, Hussein, thanks for the video. This question may sound silly but does "indexedb" store the data in a file, just like SQlite? Or is it available only in the browser without any way to export it to a file?

    • @hnasr
      @hnasr  4 года назад +1

      Hey Leslie, no I think its a valid question. And yes it does store it on disk since IndexedDB is database using LSM tree structure.. and if i close and reopen the browser my data is still there .. the question whether you have access to these underlying disk files not sure really. Even if you do I would think they are unreadable anyway..

    • @zoliky
      @zoliky 4 года назад

      @@hnasr Thanks for the answer. So, in case I want to move my web application that has a populated database to another computer, it is not possible to load it on the other computer. Right?

    • @hnasr
      @hnasr  4 года назад +1

      Leslie King Correct.
      I wouldn’t relay on browser based databases for mission critical data. It is usually used for caching and simple applications when an application is particularly offline. That is where you would probably need a reliable server side database and use IndexedDB as a backup.
      Interesting use case though..

    • @zoliky
      @zoliky 4 года назад +2

      @@hnasr Thanks, Hussein. I appreciate your time. I have one more question and I promise this is going to be the last one. If I use a server side language such as Golang I can connect to an SQL database, however I'm not sure what is the best way to send the data towards JavaScript nowadays? Do developers configure the server to send JSON data and then JavaScript fetch that JSON with the Fetch API? I think that's what they call REST API. Am I Right?

    • @hnasr
      @hnasr  4 года назад +2

      Leslie King correct! I recommend you watch my REST API video explaining all these things. REST API advantages and disadvantages with examples ruclips.net/video/M3XQ6yEC51Q/видео.html
      Meanwhile yes, a server side language (golang php, or even Javascript is also now a server side language with nodejs) can connect to RDBMS database query some data change the data into another representation (thats the RE in REST) usually JSON and send the JSON to the client.
      The Javascript client makes a call to the server using the Fetch api to pull it..
      And please ask questions! These are very beneficial to the community.. my professor always says if you have a question most likely 10 other students have the same question.
      Cheers

  • @nitingupta1417
    @nitingupta1417 3 года назад

    great tutorial !... I was a absolute beginner : )

  • @amazonreviews2524
    @amazonreviews2524 3 года назад

    Excellent explanation!

  • @CodeCatProgramming
    @CodeCatProgramming 4 года назад

    Awesome stuff dude!

  • @chillncode8313
    @chillncode8313 3 года назад

    Nice tutorial , Thanks for your amazing content

  • @usama7132
    @usama7132 2 года назад

    Uncaught TypeError: Failed to execute 'open' on 'IDBFactory': Value is not of type 'unsigned long long'.
    at HTMLButtonElement.createDB

  • @umpiredeveloper6241
    @umpiredeveloper6241 4 года назад

    great video to start IndexDB. Thanks. And yes we can see zoom in text in your video😂

  • @theledge3748
    @theledge3748 4 года назад

    Hi Hussein, great Tutorial like your delivery style. TL;DR i'm trying to return an array from viewNotes.....This may have something to do with what's been mentioned in other comments or me not understanding some JS events fundamentals (probably the latter). But in viewnotes() i was pushing to an array using the cursor, then i wanted to return that array from viewNotes directly under the } where if(cursor) ends to where i have called viewNotes from (i'm using it to update a html form list). Weird thing is it will return the array back if i test using console.log after, but anything else, even using 'alert' it says undefined! Do i have to do all logic in the cursor loop? If that makes any sense, any help be cool, ta.

  • @tennoqinus7455
    @tennoqinus7455 5 лет назад +1

    I read that indexedDB does not need a server to work, but from all the cases I`ve seen, it still requires a server environment like localhost. Can anyone help clarify this

    • @hnasr
      @hnasr  5 лет назад +4

      TennoWeeb indexedDB is a browser based database so it works on the client. To run indexedDB you need to run javascript and to run javascript you need to put it as part of an HTML page. And to render an HTML page you need to host it on a staticwebserver that serves it. In this video we made a webserver hosted on the same machine. Thats how the all websites in the internet work. You can alternatively double click the html file and run it but you get into weird situations...

  • @bilder7123
    @bilder7123 3 года назад

    Very detial, Thank you very !

  • @mykhailostepanishchev6472
    @mykhailostepanishchev6472 3 года назад

    Interesting and cool video,thank you.

  • @androidetube
    @androidetube 2 года назад

    How was he able to trigger the debugger when he pressed the button at 47:20?

  • @meetmeer
    @meetmeer 3 года назад

    Thank you so much!

  • @lynnoneill7209
    @lynnoneill7209 4 года назад

    Fantastic tutorial! Thank you!

    • @hnasr
      @hnasr  4 года назад

      Thanks Lynn! 😊

  • @mrgogate
    @mrgogate 4 года назад

    This is awesome! Thank you!

  • @RawCoding
    @RawCoding 5 лет назад +3

    Good tutorial, love your energy, although I still think you needed to prepare a little bit more before doing filming the tutorial.

    • @hnasr
      @hnasr  5 лет назад +6

      Raw Coding thank you so much for watching. Ill try to do a better job at preparation, i know this cuts down video length and ill know what about to record instead of just randomly pick a topic in the mid of the video. Having bullets points of what i want to cover could help i think. Will try to balance winging vs preparation Thanks again! .

  • @ianaustria8868
    @ianaustria8868 2 года назад

    Awesome tutorial. Btw, can you share the flowchart in the video?

  • @xerxius5446
    @xerxius5446 4 года назад

    Awesome Tutorial !!

    • @hnasr
      @hnasr  4 года назад

      Thank you!

  • @albertalbaba5101
    @albertalbaba5101 4 года назад

    I believe I wrote the code properly... But the event callback fuctions on the DB object onsuccess, onupgra.... Didn't work when the version was >

  • @techwithshudarsan559
    @techwithshudarsan559 3 года назад

    is it the alternative to location storage?

  • @georgetomeh8898
    @georgetomeh8898 2 года назад

    Great. Thanks

  • @muhammedcansoy1434
    @muhammedcansoy1434 2 года назад

    Excellent

  • @Isra-p1
    @Isra-p1 4 года назад

    awesome and fun! thanks

  • @berkoca
    @berkoca 4 года назад

    Great tutorial Hussein! Can we add objects (Array) at once instead of object to IndexedDB?

    • @hnasr
      @hnasr  4 года назад

      Thanks Berk! I am sure you can it should accept it.

    • @berkoca
      @berkoca 4 года назад

      @@hnasr I'm trying to send Array but it's giving me this on the console: Uncaught DOMException: Failed to execute 'add' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value.

    • @berkoca
      @berkoca 4 года назад

      nvm i'll just send one by one :)

  • @pradipspeaks9395
    @pradipspeaks9395 3 года назад

    What is the scalability of indexedDB?

  • @iwswordpress
    @iwswordpress 4 года назад

    Really useful. Thanks.

    • @hnasr
      @hnasr  4 года назад

      Thanks!! Glad you find it useful 😉

  • @The-Dev-Ninja
    @The-Dev-Ninja Год назад

    localforage js library, make indexedb like using a localstorage

  • @petekhamitbeyli3481
    @petekhamitbeyli3481 4 года назад

    can ı write a hospital MySQL database with javascript?

  • @inderbirsingh3592
    @inderbirsingh3592 5 лет назад

    Really really good video!
    Wanted to ask as I keep getting the error "Cannot read property 'transaction' of null" and I'm not sure why. Sometimes it works, sometimes it doesn't.

    • @hnasr
      @hnasr  5 лет назад +2

      Inderbir Singh thanks for your comment! Yes this usually mean that you are using the db object before it is completely initiated. Make sure when you open a database the onsuccess event is fully executed before you start using it take a look at 40:00 to see how i used addNote. You can also share your code happy to help :) hopefully its a simple repro.. send me an email hus.mhd@gmail.com

  • @anshitsharma2917
    @anshitsharma2917 5 месяцев назад

    nice video

  • @datamis2580
    @datamis2580 8 месяцев назад

    perfect

  • @caribbeanman3379
    @caribbeanman3379 4 года назад

    42:15 Isn't there a getAll() method to retrieve all the items in a store?

  • @omarfathy545
    @omarfathy545 5 лет назад

    Good Job Bro.

    • @hnasr
      @hnasr  5 лет назад

      Omar Fathy thanks Omar!

  • @darulikhsan4151
    @darulikhsan4151 4 года назад

    very good

  • @satindersingh9671
    @satindersingh9671 3 года назад

    cool

  • @hooligansofts7430
    @hooligansofts7430 3 года назад

    Press 4 on your keyboard
    Now press 6

  • @user-vd3pw2tb8l
    @user-vd3pw2tb8l 5 лет назад

    so cool

    • @hnasr
      @hnasr  5 лет назад

      李思南 it is right ! I love databases

  • @karandave7494
    @karandave7494 3 года назад

    Hello

  • @Pharaoh-99
    @Pharaoh-99 4 года назад

    i wish youtube had a 100x speed option

  • @sushberiwal
    @sushberiwal 3 года назад

    were you drunk the whole time while shooting this video ?

  • @ahmadmoradi2018
    @ahmadmoradi2018 3 года назад

    Just say what you want. DO NOT MAKE NOISE PLEASE

  • @aspirinemaga
    @aspirinemaga 5 лет назад +1

    thanks for video, but to be honest, it was really difficult to stay calm and listen to your fancy joky-speech

    • @hnasr
      @hnasr  5 лет назад +1

      aspirinemaga thanks for watching, I like to lighten the mode for such dry topic, sorry it was distracting for you. Will do better next time! Thanks for your comment