8000 README browser example uses MiniGrafDb.inMemory(), but @minigraf/browser exports BrowserDb · Issue #5 · project-minigraf/minigraf-wasm · GitHub
[go: up one dir, main page]

Skip to content

README browser example uses MiniGrafDb.inMemory(), but @minigraf/browser exports BrowserDb #5

Closed

Description

@adityamukho

The browser quick start in README.md doesn't match the API that @minigraf/browser 2.0.4 exports.

README shows:

import init, { MiniGrafDb } from '@minigraf/browser'

await init()

const db = MiniGrafDb.inMemory()
db.execute('(transact [[:alice :name "Alice"]])')

const result = JSON.parse(db.execute('(query [:find ?n :where [?e :name ?n]])'))

The package actually exports (from minigraf_wasm.d.ts in 2.0.4):

  • BrowserDb, not MiniGrafDb
  • BrowserDb.open(dbName) (IndexedDB-backed, returns a Promise<BrowserDb>)
  • BrowserDb.openInMemory() (not inMemory())
  • execute() returns a Promise<string>, so it needs await

MiniGrafDb with inMemory() and a synchronous execute() is the Node binding's API (minigraf on npm), so the example looks copied from there.

Suggested example:

import init, { BrowserDb } from '@minigraf/browser'

await init()

const db = await BrowserDb.open('mydb')   // or BrowserDb.openInMemory() for tests
await db.execute('(transact [[:alice :name "Alice"]])')

const result = JSON.parse(await db.execute('(query [:find ?n :where [?e :name ?n]])'))
console.log(result.results[0][0])  // "Alice"

It may also be worth mentioning exportGraph() / importGraph() and checkpoint(), which the README doesn't cover.

Checked against: @minigraf/browser@2.0.4 from npm. I confirmed BrowserDb.openInMemory() and await db.execute(...) work by loading the package with initSync in Node 24. minigraf-playground/lib/wasm-loader.ts also uses BrowserDb.open.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0