Skip to content

Commit

Permalink
$mol_db: + teaser
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Dec 12, 2023
1 parent 4e054b5 commit 127b88c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,43 @@

Static typed facade for [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) with simple API.

## Teaser

```typescript
type User = {
name: string
admin: boolean
}

// Static typed schema
type DB = {
User: {
Key: [ string ]
Doc: User
Indexes: {
Name: [ string ]
}
}
}

// Automatic migrations
const db = await $mol_db< DB >( '$my_app',
mig => mig.store_make( 'User' ),
mig => {
const { User } = mig.stores
User.index_make( 'Name', [ 'name' ] )
},
)

// Writing transaction
const { User } = db.change( 'User' ).stores
await User.put({ name: 'Jin', admin: true })

// Reading transaction
const { Name } = db.read( 'User' ).User.indexes
const jins = await Name.select([ 'Jin' ])
```

## IndexedDB Structure

- **Database** contains named Stores
Expand Down

0 comments on commit 127b88c

Please sign in to comment.