Module

Web.IDB

Package
purescript-idb
Repository
philippedev101/purescript-idb

PureScript FFI bindings for IndexedDB via the idb library.

All operations run in Aff and work with any IndexedDB-compatible environment (browsers, or Node.js with fake-indexeddb).

Transaction safety

IndexedDB transactions auto-commit when there are no pending requests on the event loop. withWriteTransaction enforces this by accepting an Effect callback (synchronous), preventing accidental awaits that would close the transaction prematurely.

#IDBDatabase Source

data IDBDatabase

An opaque handle to an open IndexedDB database.

#TxStore Source

data TxStore

An opaque handle to an object store within a write transaction. Operations on TxStore are synchronous (Effect) to prevent the transaction from auto-committing between async operations.

#open Source

open :: String -> Int -> Array String -> Aff IDBDatabase

Open (or create) a database. Creates any missing object stores.

#get Source

get :: IDBDatabase -> String -> String -> Aff (Maybe Foreign)

Get a value by key from a store. Returns Nothing if not found.

#getAll Source

getAll :: IDBDatabase -> String -> Aff (Array Foreign)

Get all values from a store.

#getAllKeys Source

getAllKeys :: IDBDatabase -> String -> Aff (Array String)

Get all keys from a store (as strings).

#getAllEntries Source

getAllEntries :: IDBDatabase -> String -> Aff (Array (Tuple String Foreign))

Get all key-value pairs from a store in a single readonly transaction. This is atomic: keys and values are guaranteed to be consistent.

#put Source

put :: IDBDatabase -> String -> String -> Foreign -> Aff Unit

Put a value at a key in a store (upsert).

#delete Source

delete :: IDBDatabase -> String -> String -> Aff Unit

Delete a key from a store.

#clear Source

clear :: IDBDatabase -> String -> Aff Unit

Clear all entries in a store.

#withWriteTransaction Source

withWriteTransaction :: IDBDatabase -> String -> (TxStore -> Effect Unit) -> Aff Unit

Execute a batch of write operations in a single atomic transaction.

The callback receives a TxStore handle and must queue all operations synchronously using txPut, txDelete, and txClear. The transaction commits automatically when all queued operations complete.

The callback is Effect (not Aff) to prevent awaiting between operations, which would cause the transaction to auto-commit.

#txPut Source

txPut :: TxStore -> String -> Foreign -> Effect Unit

Queue a put (upsert) operation within a write transaction.

#txDelete Source

txDelete :: TxStore -> String -> Effect Unit

Queue a delete operation within a write transaction.

#txClear Source

txClear :: TxStore -> Effect Unit

Queue a clear operation within a write transaction.

#putBatch Source

putBatch :: IDBDatabase -> String -> Array (Tuple String Foreign) -> Aff Unit

Put multiple key-value pairs in a single atomic transaction.

#clearAndPutBatch Source

clearAndPutBatch :: IDBDatabase -> String -> Array (Tuple String Foreign) -> Aff Unit

Clear a store then put multiple key-value pairs, all in one atomic transaction.

#deleteBatch Source

deleteBatch :: IDBDatabase -> String -> Array String -> Aff Unit

Delete multiple keys in a single atomic transaction.

Modules
Web.IDB