Skip to content

Getting started

David Fahlander edited this page Jun 13, 2016 · 75 revisions

Dexie.js can be consumed as a module. But let's skip that for now and just show the simplest possible setup. You will just need a text editor and a web browser.

Hello World

  1. Create a HTML page

    <html>
        <head>
            <!-- Include Dexie -->
            <script src="https://npmcdn.com/dexie@latest/dist/dexie.js"></script>
    
            <script>
                //
                // Define your database
                //
                var db = new Dexie("friends-database");
                db.version(1).stores({
                    friends: 'name,shoeSize',
                    // ...add more stores (tables) here...
                });
    
                //
                // Open it
                //
                db.open().catch(function (e) {
                    alert ("Open failed: " + e);
                });
    
                //
                // Put some data into it
                //
                db.friends.put({name: "Nicolas", shoeSize: 8}).then (function(){
                    //
                    // Then when data is stored, read from it
                    //
                    return db.friends.get('Nicolas');
                }).then(function (friend) {
                    //
                    // Display the result
                    //
                    alert ("Nicolas has shoe size " + friend.shoeSize);
                }).catch(function(error) {
                   //
                   // Finally don't forget to catch any error
                   // that could have happened anywhere in the
                   // code blocks above.
                   //
                   alert ("Ooops: " + error);
                });
            </script>
        </head>
    </html>
  2. Open your page in Chrome, Opera, Firefox, IE10+, Edge or Safari. Note: IE/Edge will require the page to be put at a server, not local hard disk.

That's all for how to get started!

Next steps

[Consuming dexie as a module](consuming dexie as a module)

or

or

or

Clone this wiki locally