Module

Database.IndexedDB.IDBObjectStore

Package
purescript-indexeddb
Repository
truqu/purescript-indexedDB

An object store is the primary storage mechanism for storing data in a database.

#IndexName Source

type IndexName = String

Type alias for IndexName

#IndexParameters Source

type IndexParameters = { multiEntry :: Boolean, unique :: Boolean }

Flags to set on the index.

An index has a unique flag. When this flag is set, the index enforces that no two records in the index has the same key. If a record in the index’s referenced object store is attempted to be inserted or modified such that evaluating the index’s key path on the records new value yields a result which already exists in the index, then the attempted modification to the object store fails.

An index has a multiEntry flag. This flag affects how the index behaves when the result of evaluating the index’s key path yields an array key. If the multiEntry flag is unset, then a single record whose key is an array key is added to the index. If the multiEntry flag is true, then the one record is added to the index for each of the subkeys.

#add Source

add :: forall e key val store. IDBKey key => IDBObjectStore store => store -> val -> Maybe key -> Aff (idb :: IDB | e) Key

Adds or updates a record in store with the given value and key.

If the store uses in-line keys and key is specified a "DataError" DOMException will be thrown.

If add() is used, and if a record with the key already exists the request will fail, with a "ConstraintError" DOMException.

#clear Source

clear :: forall e store. IDBObjectStore store => store -> Aff (idb :: IDB | e) Unit

Deletes all records in store.

#createIndex Source

createIndex :: forall e store. IDBObjectStore store => store -> IndexName -> KeyPath -> IndexParameters -> Aff (idb :: IDB | e) Index

Creates a new index in store with the given name, keyPath and options and returns a new IDBIndex. If the keyPath and options define constraints that cannot be satisfied with the data already in store the upgrade transaction will abort with a "ConstraintError" DOMException.

Throws an "InvalidStateError" DOMException if not called within an upgrade transaction.

#delete Source

delete :: forall e store. IDBObjectStore store => store -> KeyRange -> Aff (idb :: IDB | e) Unit

Deletes records in store with the given key or in the given key range in query.

#deleteIndex Source

deleteIndex :: forall e store. IDBObjectStore store => store -> IndexName -> Aff (idb :: IDB | e) Unit

Deletes the index in store with the given name.

Throws an "InvalidStateError" DOMException if not called within an upgrade transaction.

#index Source

index :: forall e store. IDBObjectStore store => store -> IndexName -> Aff (idb :: IDB | e) Index

Returns an IDBIndex for the index named name in store.

#put Source

put :: forall e val key store. IDBKey key => IDBObjectStore store => store -> val -> Maybe key -> Aff (idb :: IDB | e) Key

Adds or updates a record in store with the given value and key.

If the store uses in-line keys and key is specified a "DataError" DOMException will be thrown.

If put() is used, any existing record with the key will be replaced.

#autoIncrement Source

autoIncrement :: ObjectStore -> Boolean

Returns true if the store has a key generator, and false otherwise.

#indexNames Source

indexNames :: ObjectStore -> Array String

Returns a list of the names of indexes in the store.

#keyPath Source

keyPath :: ObjectStore -> Array String

Returns the key path of the store, or empty array if none

#name Source

name :: ObjectStore -> String

Returns the name of the store.

#transaction Source

transaction :: ObjectStore -> Transaction

Returns the associated transaction.

Re-exports from Database.IndexedDB.IDBIndex

#openKeyCursor Source

openKeyCursor :: forall e e' index. IDBIndex index => index -> Maybe KeyRange -> CursorDirection -> Callbacks KeyCursor e' -> Aff (idb :: IDB | e) Unit

Opens a KeyCursor over the records matching query, ordered by direction. If query is Nothing, all records in index are matched.

#openCursor Source

openCursor :: forall e e' index. IDBIndex index => index -> Maybe KeyRange -> CursorDirection -> Callbacks ValueCursor e' -> Aff (idb :: IDB | e) Unit

Opens a ValueCursor over the records matching query, ordered by direction. If query is Nothing, all records in index are matched.

#getKey Source

getKey :: forall e index. IDBIndex index => index -> KeyRange -> Aff (idb :: IDB | e) (Maybe Key)

Retrieves the key of the first record matching the given key or key range in query.

#getAllKeys Source

getAllKeys :: forall e index. IDBIndex index => index -> Maybe KeyRange -> Maybe Int -> Aff (idb :: IDB | e) (Array Key)

Retrieves the keys of records matching the given key range in query (up to the number given if given).

#get Source

get :: forall a e index. IDBIndex index => index -> KeyRange -> Aff (idb :: IDB | e) (Maybe a)

Retrieves the value of the first record matching the given key range in query.

NOTE The coercion from a to any type is unsafe and might throw a runtime error if incorrect.

#count Source

count :: forall e index. IDBIndex index => index -> Maybe KeyRange -> Aff (idb :: IDB | e) Int

Retrieves the number of records matching the key range in query.