persistent-mongoDB-1.1.5: 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]Source

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

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

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)Source

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

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 nesSource

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 nesSource

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 nesSource

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

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

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

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

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 vSource

use to see if an embedded list contains an item

using connections

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

createMongoDBPoolSource

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 

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

use default AccessMode

data MongoConf Source

Information required to connect to a mongo database

using raw MongoDB pipes

createMongoDBPipePoolSource

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

Key conversion helpers

network type

type HostName = String

Either a host name e.g., "haskell.org" or a numeric host address string consisting of a dotted decimal IPv4 address or an IPv6 address e.g., "192.168.0.1".

MongoDB driver types

data AccessMode

Type of reads and writes to perform

Constructors

ReadStaleOk

Read-only action, reading stale data from a slave is OK.

UnconfirmedWrites

Read-write action, slave not OK, every write is fire & forget.

ConfirmWrites GetLastError

Read-write action, slave not OK, every write is confirmed with getLastError.

Instances

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

Field with given label and typed value

Database.Persist