Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="column"><p>
  <a id="exportLink" href="#">Click here to export the database</a>
</p>
<div id="dropzone">
  Drop dexie export JSON file here
</div>
</div><div class="column">
  <h3>Database Info</h3>
  <table border="1">
    <thead></thead>
    <tbody></tbody>
  </table>
</div>
              
            
!

CSS

              
                div.column {
  float: left;
  margin: 12px;
}
#dropzone {
  width: 600px;
  height: 20px;
  border: 2px dotted #bbb;
  border-radius: 10px;
  padding: 35px;
  color: #bbb;
  text-align: center;
}
table {
  text-align: left;
}
              
            
!

JS

              
                //
// Declare Database and pre-populate it
//
let db = new Dexie('exportSample');
db.version(1).stores({
  foos: 'id'
});
db.on('populate', ()=>{
  return db.foos.bulkAdd([
    {
      id: 1,
      foo: 'foo',
      date: new Date(), // Dates, Blobs, ArrayBuffers, etc are supported
    },{
      id: 2,
      foo: 'bar',
    }
  ]);
});

//
// When document is ready, bind export/import funktions to HTML elements
//
document.addEventListener('DOMContentLoaded', ()=>{
  showContent().catch(err => console.error(''+err));
  const dropZoneDiv = document.getElementById('dropzone');
  const exportLink = document.getElementById('exportLink');

  // Configure exportLink
  exportLink.onclick = async ()=>{
    try {
      const blob = await db.export({prettyJson: true, progressCallback});
      download(blob, "dexie-export.json", "application/json");
    } catch (error) {
 console.error(''+error);
    }
  };

  // Configure dropZoneDiv
  dropZoneDiv.ondragover = event => {
    event.stopPropagation();
    event.preventDefault();
    event.dataTransfer.dropEffect = 'copy';
  };

  // Handle file drop:
  dropZoneDiv.ondrop = async ev => {
    ev.stopPropagation();
    ev.preventDefault();

    // Pick the File from the drop event (a File is also a Blob):
    const file = ev.dataTransfer.files[0];
    try {
      if (!file) throw new Error(`Only files can be dropped here`);
      console.log("Importing " + file.name);
      await db.delete();
      db = await Dexie.import(file, {
        progressCallback
      });
      console.log("Import complete");
      await showContent();
    } catch (error) {
      console.error(''+error);
    }
  }
});

function progressCallback ({totalRows, completedRows}) {
  console.log(`Progress: ${completedRows} of ${totalRows} rows completed`);
}

async function showContent() {
  const tbody = document.getElementsByTagName('tbody')[0];
 
  const tables = await Promise.all(db.tables.map (async table => ({
    name: table.name,
    count: await table.count(),
    primKey: table.schema.primKey.src
  })));
  tbody.innerHTML = `
    <tr>
      <th>Database Name</th>
      <td colspan="2">${db.name}</th>
    </tr>
    ${tables.map(({name, count, primKey}) => `
      <tr>
        <th>Table: "${name}"</th>
        <td>Primary Key: ${primKey}</td>
        <td>Row count: ${count}</td>
      </tr>`)}
  `;
}
              
            
!
999px

Console