Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
zoontek committed Mar 7, 2024
1 parent 16b8d1f commit f623812
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ $ npm install --save @swan-io/indexed-db
## Quickstart

```ts
const store = openStore("myDatabaseName", "myStoreName");
const store = openStore({
databaseName: "myDatabaseName",
storeName: "myStoreName",
});

store
.setMany({
Expand All @@ -45,7 +48,9 @@ Open a database, create a store if needed and returns methods to manipulate it.<
Note that you can open multiple databases / stores, with different names.

```ts
const store = await openStore("myDatabaseName", "myStoreName", {
const store = await openStore({
databaseName: "myDatabaseName",
storeName: "myStoreName",
transactionRetries: 2, // retry failed transactions (default: 2)
transactionTimeout: 500, // timeout a transaction when it takes too long (default: 500ms)
});
Expand Down
25 changes: 20 additions & 5 deletions tests/inMemoryStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ afterAll(() => {
});

test("API stays usable thanks to in-memory store", async () => {
const store = await openStore("database", "storeA");
const store = await openStore({
databaseName: "database",
storeName: "storeA",
});

expect(await store.setMany({ A: true })).toBeUndefined();

Expand All @@ -29,11 +32,17 @@ test("API stays usable thanks to in-memory store", async () => {
});

test.skip("In-memory stores are preserved during session", async () => {
const firstOpenedStore = await openStore("database", "storeB");
const firstOpenedStore = await openStore({
databaseName: "database",
storeName: "storeB",
});

await firstOpenedStore.setMany({ A: true });

const secondOpenedStore = await openStore("database", "storeB");
const secondOpenedStore = await openStore({
databaseName: "database",
storeName: "storeB",
});

expect(await secondOpenedStore.getMany(["A", "B"])).toStrictEqual({
A: true,
Expand All @@ -42,11 +51,17 @@ test.skip("In-memory stores are preserved during session", async () => {
});

test.skip("In-memory stores are created by database + store names", async () => {
const firstOpenedStore = await openStore("database", "storeC");
const firstOpenedStore = await openStore({
databaseName: "database",
storeName: "storeC",
});

await firstOpenedStore.setMany({ A: true });

const secondOpenedStore = await openStore("database", "storeD");
const secondOpenedStore = await openStore({
databaseName: "database",
storeName: "storeD",
});

expect(await secondOpenedStore.getMany(["A", "B"])).toStrictEqual({
A: undefined,
Expand Down
5 changes: 4 additions & 1 deletion tests/noFailures.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { afterEach, expect, test } from "vitest";
import { openStore } from "../src";

const store = await openStore("database", "store");
const store = await openStore({
databaseName: "database",
storeName: "store",
});

afterEach(async () => {
await store.clear();
Expand Down

0 comments on commit f623812

Please sign in to comment.