persistent-mongoDB-1.1.4: Backend for the persistent library using mongoDB.

Safe HaskellNone

Database.Persist.MongoDB

Contents

Description

Use persistent-mongodb the same way you would use other persistent libraries and refer to the general persistent documentation. There are some new MongoDB specific filters under the filters section. These help extend your query into a nested document.

However, at some point you will find the normal Persistent APIs lacking. and want lower level-level MongoDB access. There are functions available to make working with the raw driver easier: they are under the Entity conversion section. You should still use the same connection pool that you are using for Persistent.

Synopsis

Entity conversion

entityToFields :: forall record. PersistEntity record => record -> [Field]

convert a PersistEntity into document fields. unlike toInsertFields, nulls are included.

toInsertFields :: forall record. PersistEntity record => record -> [Field]

convert a PersistEntity into document fields. for inserts only: nulls are ignored so they will be unset in the document. entityToFields includes nulls

docToEntityEither :: forall record. PersistEntity record => Document -> Either Text (Entity record)

docToEntityThrow :: forall m record. (MonadIO m, PersistEntity record) => Document -> m (Entity record)

MongoDB specific Filters

You can find example usage for all of Persistent in our test cases: https:github.comyesodwebpersistentblobmasterpersistent-testEmbedTest.hs#L144

These filters create a query that reaches deeper into a document with nested fields.

(->.) :: forall val nes nes1. PersistEntity nes1 => EntityField val nes1 -> EntityField nes1 nes -> NestedField val nes

Point to a nested field to query. Used for the final level of nesting with nestEq or other operators.

(~>.) :: forall val nes nes1. PersistEntity nes1 => EntityField val nes1 -> NestedField nes1 nes -> NestedField val nes

Point to a nested field to query. This level of nesting is not the final level. Use (->.) to point to the final level is

(?->.) :: forall val nes nes1. PersistEntity nes1 => EntityField val (Maybe nes1) -> EntityField nes1 nes -> NestedField val nes

Same as (->.), but Works against a Maybe type

(?~>.) :: forall val nes nes1. PersistEntity nes1 => EntityField val (Maybe nes1) -> NestedField nes1 nes -> NestedField val nes

Same as (~>.), but Works against a Maybe type

nestEq :: forall v typ. (PersistField typ, PersistEntityBackend v ~ MongoBackend) => NestedField v typ -> typ -> Filter v

The normal Persistent equality test (==.) is not generic enough. Instead use this with the drill-down operaters (->.) or (?->.)

multiEq :: forall v typ. (PersistField typ, PersistEntityBackend v ~ MongoBackend) => EntityField v [typ] -> typ -> Filter v

use to see if an embedded list contains an item

using connections

withMongoDBConn :: (MonadIO m, Applicative m) => Database -> HostName -> PortID -> Maybe MongoAuth -> NominalDiffTime -> (ConnectionPool -> m b) -> m b

withMongoDBPool :: (MonadIO m, Applicative m) => Database -> HostName -> PortID -> Maybe MongoAuth -> Int -> Int -> NominalDiffTime -> (ConnectionPool -> m b) -> m b

createMongoDBPool

Arguments

:: (MonadIO m, Applicative m) 
=> Database 
-> HostName 
-> PortID 
-> Maybe MongoAuth 
-> Int

pool size (number of stripes)

-> Int

stripe size (number of connections per stripe)

-> NominalDiffTime

time a connection is left idle before closing

-> m ConnectionPool 

runMongoDBPool :: (MonadIO m, MonadBaseControl IO m) => AccessMode -> Action m a -> ConnectionPool -> m a

runMongoDBPoolDef :: (MonadIO m, MonadBaseControl IO m) => Action m a -> ConnectionPool -> m a

use default AccessMode

data MongoConf

Information required to connect to a mongo database

Instances

PersistConfig MongoConf 

data MongoBackend

Instances

PathPiece (KeyBackend MongoBackend entity) 

using raw MongoDB pipes

type PipePool = Pool Pipe

createMongoDBPipePool

Arguments

:: (MonadIO m, Applicative m) 
=> HostName 
-> PortID 
-> Int

pool size (number of stripes)

-> Int

stripe size (number of connections per stripe)

-> NominalDiffTime

time a connection is left idle before closing

-> m PipePool 

A pool of plain MongoDB pipes. The database parameter has not yet been applied yet. This is useful for switching between databases (on the same host and port) Unlike the normal pool, no authentication is available

runMongoDBPipePool :: (MonadIO m, MonadBaseControl IO m) => AccessMode -> Database -> Action m a -> PipePool -> m a

run a pool created with createMongoDBPipePool

Key conversion helpers

keyToOid :: PersistEntity val => KeyBackend MongoBackend val -> ObjectId

oidToKey :: PersistEntity val => ObjectId -> KeyBackend MongoBackend val

network type

data PortID

Instances

MongoDB driver types

data Action m a

Instances

MonadTransControl Action 
MonadTrans Action 
(MonadIO m, MonadBaseControl b m) => MonadBaseControl b (Action m) 
Monad m => MonadError Failure (Action m) 
MonadBase b m => MonadBase b (Action m) 
Monad m => Monad (Action m) 
Functor m => Functor (Action m) 
(Monad m, Functor m) => Applicative (Action m) 
(Applicative m, Functor m, MonadIO m, MonadBaseControl IO m) => PersistUnique (Action m) 
(Applicative m, Functor m, MonadIO m, MonadBaseControl IO m) => PersistStore (Action m) 
(Applicative m, Functor m, MonadIO m, MonadBaseControl IO m) => PersistQuery (Action m) 
MonadIO m => MonadIO (Action m) 
(MonadBaseControl IO m, Applicative m, Functor m) => MonadDB (Action m) 
MonadThrow m => MonadThrow (Action m) 

data AccessMode

Constructors

ReadStaleOk 
UnconfirmedWrites 
ConfirmWrites GetLastError 

Instances

(=:) :: Val v => Label -> v -> Field

Database.Persist