ejdb2-binding-0.3.0.1: 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 q -> IO Int64 Source #

Executes a given query and returns the number of documents.

getList :: FromJSON a => Database -> Query q -> 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 q -> 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 q 
-> IO a 

Iterate over query result building the result

data Query a Source #

Query data with binding. Collection must be specified in query.

Constructors

Query 

Fields

type BindM a = StateT BindState IO a Source #

Monad to apply binding to Query

noBind :: BindM () Source #

Create empty bind

setBool Source #

Arguments

:: Bool 
-> String

Placeholder

-> BindM () 

Bind bool to query placeholder

setBoolAtIndex Source #

Arguments

:: Bool 
-> Int

Index

-> BindM () 

Bind bool to query at specified index

setI64 Source #

Arguments

:: Int64 
-> String

Placeholder

-> BindM () 

Bind number to query placeholder

setI64AtIndex Source #

Arguments

:: Int64 
-> Int

Index

-> BindM () 

Bind number to query at specified index

setF64 Source #

Arguments

:: Double 
-> String

Placeholder

-> BindM () 

Bind Double to query placeholder

setF64AtIndex Source #

Arguments

:: Double 
-> Int

Index

-> BindM () 

Bind Double to query at specified index

setString Source #

Arguments

:: String 
-> String

Placeholder

-> BindM () 

Bind string to query placeholder

setStringAtIndex Source #

Arguments

:: String 
-> Int

Index

-> BindM () 

Bind string to query at specified index

setRegex Source #

Arguments

:: String

Regex

-> String

Placeholder

-> BindM () 

Bind regex to query placeholder

setRegexAtIndex Source #

Arguments

:: String

Regex

-> Int

Index

-> BindM () 

Bind regex to query at specified index

setNull Source #

Arguments

:: String

Placeholder

-> BindM () 

Bind null value to query placeholder

setNullAtIndex Source #

Arguments

:: Int

Index

-> BindM () 

Bind null value to query at specified index