0.0.6 • Published 4 years ago

idx-db.js v0.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Api

import { openDb } from "db";

const structure = [
  {
    version: 1,
    migration(db) {
      // could this have a nicer API?
      const store = db.createObjectStore("todos", {
        keyPath: "id",
        autoIncrement: true,
      });

      store.createIndex("title", "title", { unique: false });
    },
  },
  {
    version: 2,
    migration(db) {
      const store = db.createObjectStore("todos", {
        keyPath: "id",
        autoIncrement: true,
      });

      store.createIndex("done", "done", { unique: false });
    },
  },
];

const db = await openDb("db-name", structure);
const { todos } = db.stores;

await todos.add(todo); // Todo
await todos.delete(id); // DeletedTodo
await todos.update(todo); // Todo
await todos.find(id); // Todo
await todos.all(); // [Todo]
await todos.where("title").equals("hello", { ignoreCase: true }); // [Todo]
await todos.where("title").contains("hello"); // [Todo]
await todos.where("title").not.equals("hello"); // [Todo
await todos.where("done").equals(false); // [Todo]
0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago