ejdb2-binding-0.2.0.0: Binding to EJDB2 C library, an embedded JSON noSQL database

Safe HaskellNone
LanguageHaskell2010

Database.EJDB2

Synopsis

Documentation

init :: IO () Source #

ejdb2 initialization routine.

Must be called before using any of ejdb API function.

data Database Source #

Reference to database. You can create it by open.

readonlyOpenFlags :: OpenFlags Source #

Open storage file in read-only mode.

truncateOpenFlags :: OpenFlags Source #

Truncate storage file on open.

minimalOptions Source #

Arguments

:: String

Database file path

-> [OpenFlags]

Open mode

-> Options

Options to use in open

Create minimal Options for opening a database: just path to file and opening mode.

open :: Options -> IO Database Source #

Open storage file.

Storage can be opened only by one single process at time.

Remember to release database by close when database is no longer required.

close :: Database -> IO () Source #

Closes storage and frees up all resources.

getById Source #

Arguments

:: FromJSON a 
=> Database 
-> String

Collection name

-> Int64

Document identifier. Not zero

-> IO (Maybe a) 

Retrieve document identified by given id from collection.

getCount :: Database -> Query -> IO Int64 Source #

Executes a given query and returns the number of documents.

getList :: FromJSON a => Database -> Query -> IO [(Int64, Maybe a)] Source #

Executes a given query and builds a query result as list of tuple with id and document.

getList' :: FromJSON a => Database -> Query -> IO [Maybe a] Source #

Executes a given query and builds a query result as list of documents with id injected as attribute.

putNew Source #

Arguments

:: ToJSON a 
=> Database 
-> String

Collection name

-> a

Document

-> IO Int64

New document identifier. Not zero

Save new document into collection under new generated identifier.

put Source #

Arguments

:: ToJSON a 
=> Database 
-> String

Collection name

-> a

Document

-> Int64

Document identifier. Not zero

-> IO () 

Save a given document under specified id.

mergeOrPut Source #

Arguments

:: ToJSON a 
=> Database 
-> String

Collection name

-> a

JSON merge patch conformed to rfc7396 specification

-> Int64

Document identifier. Not zero

-> IO () 

Apply JSON merge patch (rfc7396) to the document identified by id or insert new document under specified id.

This is an atomic operation.

patch Source #

Arguments

:: ToJSON a 
=> Database 
-> String

Collection name

-> a

JSON patch conformed to rfc6902 or rfc7396 specification

-> Int64

Document identifier. Not zero

-> IO () 

Apply rfc6902/rfc7396 JSON patch to the document identified by id.

delete Source #

Arguments

:: Database 
-> String

Collection name

-> Int64

Document identifier. Not zero

-> IO () 

Remove document identified by given id from collection coll.

ensureCollection Source #

Arguments

:: Database 
-> String

Collection name

-> IO () 

Create collection with given name if it has not existed before

removeCollection Source #

Arguments

:: Database 
-> String

Collection name

-> IO () 

Remove collection under the given name.

renameCollection Source #

Arguments

:: Database 
-> String

Old collection name

-> String

New collection name

-> IO () 

Rename collection to new name.

getMeta Source #

Arguments

:: FromJSON a 
=> Database 
-> IO (Maybe a)

JSON object describing ejdb storage. See data Meta

Returns JSON document describing database structure. You can use the convenient data Meta

data IndexMode Source #

Index creation mode.

uniqueIndexMode :: IndexMode Source #

Marks index is unique, no duplicated values allowed.

strIndexMode :: IndexMode Source #

Index values have string type.

Type conversion will be performed on atempt to save value with other type.

f64IndexMode :: IndexMode Source #

Index value have floating point type. Internally floating point numbers are converted to string with precision of 6 digits after decimal point.

i64IndexMode :: IndexMode Source #

Index values have signed integer 64 bit wide type.

Type conversion will be performed on atempt to save value with other type.

ensureIndex Source #

Arguments

:: Database 
-> String

Collection name

-> String

rfc6901 JSON pointer to indexed field

-> [IndexMode]

Index mode

-> IO () 

Create index with specified parameters if it has not existed before.

Index path must be fully specified as rfc6901 JSON pointer and must not countain unspecified */** element in middle sections.

ensureIndex database "mycoll" "/address/street" [uniqueIndexMode | strIndexMode]

removeIndex Source #

Arguments

:: Database 
-> String

Collection name

-> String

rfc6901 JSON pointer to indexed field

-> [IndexMode]

Index mode

-> IO () 

Remove index if it has existed before.

onlineBackup Source #

Arguments

:: Database 
-> String

Backup file path

-> IO Word64

Backup completion timestamp

Creates an online database backup image and copies it into the specified target file. During online backup phase read/write database operations are allowed and not blocked for significant amount of time. Backup finish time is placed into result as number of milliseconds since epoch.

Online backup guaranties what all records before timestamp will be stored in backup image. Later, online backup image can be opened as ordinary database file.

In order to avoid deadlocks: close all opened database cursors before calling this method or do call in separate thread.

fold Source #

Arguments

:: FromJSON b 
=> Database 
-> (a -> (Int64, Maybe b) -> a)

The second argument is a tuple with the object id and the object

-> a

Initial result

-> Query 
-> IO a 

Iterate over query result building the result