avers-0.0.10: empty

Safe HaskellNone
LanguageHaskell2010

Avers

Contents

Synopsis

The Avers Monad

Types

newtype Path Source

Path

Constructors

Path 

Fields

unPath :: Text
 

class Pk a where Source

Pk - Types which can be converted to a database primary key.

Methods

toPk :: a -> Text Source

newtype ObjId Source

ObjId

Constructors

ObjId 

Fields

unObjId :: Text
 

rootObjId :: ObjId Source

The root object id is used for object created internally or when there is no applicable creator.

zeroRevId :: RevId Source

The RevId which is used for the initial snapshot.

data ObjectId Source

ObjectId

Constructors

BaseObjectId !ObjId

The base object whose snapshots contain the actual content.

ReleaseObjectId !ObjId !RevId

An object describing a particualar release of the base object.

AuthorizationObjectId !ObjId

Object which contains authorization rules.

data Operation Source

The operations that can be applied to JSON values.

Constructors

Set

Set is applied to Objects. It is used for adding, updating and deleting properties from the object.

Fields

opPath :: !Path
 
opValue :: !(Maybe Value)
 
Splice

Splice is used to manipulate Arrays. It can remove and insert multiple elements in a single operation.

Fields

opPath :: !Path
 
opIndex :: !Int
 
opRemove :: !Int
 
opInsert :: ![Value]
 

Object

exists :: ObjId -> Avers Bool Source

True if the object exists.

createObject :: ToJSON a => ObjectType a -> ObjId -> a -> Avers ObjId Source

Create a new object of the given type. An initial snapshot (RevId 0) is created from the supplied content.

createObject' :: ToJSON a => ObjId -> UTCTime -> ObjectType a -> ObjId -> a -> Avers () Source

A more low-level version of createObject, for use when you want to generate your own ObjId or create objects at a specific time.

lookupObject :: ObjId -> Avers Object Source

Lookup an Object by its ObjId. Throws ObjectNotFound if the object doesn't exist.

deleteObject :: ObjId -> Avers () Source

Mark the object as deleted.

pruneObject :: ObjId -> Avers () Source

Prune the object from the database. This is only allowed if the object is marked as deleted. Note that this is a very dangerous operation, it can not be undone.

TODO: Prune related Release and Authoriation objects.

createCheckpoint :: ObjectId -> ObjId -> Avers RevId Source

Create a checkpoint for for the given object. All patches (and of course snapshots) before the checkpoint can be dropped. Use vacuumObject to do that.

vacuumObject :: ObjectId -> Avers () Source

Drop all patches and snapshots before the most recent checkpoint. This effectively drops the object's history, and frees space in the database.

Patch

data PatchError Source

Constructors

UnknownPatchError !Text 

Instances

Snapshot

lookupLatestSnapshot :: ObjectId -> Avers Snapshot Source

Get the snapshot of the newest revision of the given object.

objectContent :: FromJSON a => ObjectId -> Avers a Source

Fetch the content of the object and try to parse it.

This function will fail with a ParseError if the content can not be decoded into the desired type.

Release

data Release Source

Release

Constructors

Release 

createRelease :: ObjId -> RevId -> Avers () Source

Create a new release of the given revision. If the object doesn't exist, it will fail with ObjectNotFound.

Patching

resolvePathIn :: Path -> Value -> Maybe Value Source

Resolve the path in the object.

Session

data Session Source

The session record that is stored in the database.

A session is a unique identifier attached to a particular object. It contains the creation date and when it was last accessed. If you need to store additional data for a session, we recommend to use cookies.

data ObjectType a Source

An ObjectType describes a particular type of object that is managed by Avers.

Constructors

ObjectType 

Fields

otType :: !Text

The value of the type field of the Object.

otId :: Avers ObjId

Action which generates a new id. This is so that object types can have different strategies how to generate ids.

otViews :: [SomeView a]
 

lookupObjectType :: Text -> Avers SomeObjectType Source

Lookup an object type which is registered in the Avers monad.

data Config Source

Configuration of the Avers monad.

Constructors

Config 

Fields

databaseURI :: !URI

URI which describes the connection details to the RethinkDB database. The URI *MUST* include at least the hostname (uriRegName) and database name (uriPath without the leading slash). The port (uriPort) and credentials (uriUserInfo) *MAY* be left empty. in that case the default port will be used.

putBlob :: BlobId -> Text -> ByteString -> IO (Either AversError ())

Function which saves the given blob in the blob store. This can be the local filesystem or an external service such as Amazon S3.

objectTypes :: ![SomeObjectType]

All the object types which Avers knows about.

emitMeasurement :: Measurement -> Double -> IO ()

This is called when the internal instrumentation code creates a measurement.

Blob

newtype BlobId Source

BlobId

Constructors

BlobId 

Fields

unBlobId :: Text
 

data Blob Source

Blob

Constructors

Blob 

Secret

data Secret Source

Secret

A Secret is a password (encrypted with scrypt) that is attached to a SecretId (for example the ObjId of an account).

It is up to you to ensure that SecretIds are unique. If you use ObjIds then they by definition are.

Constructors

Secret 

verifySecret :: SecretId -> Text -> Avers () Source

Verify the value against the secret. If that fails, then this function throws an error.

This function automatically updates the secret in the database if the scrypt params have changed.

applyObjectUpdates Source

Arguments

:: ObjectId

The object which you want to update

-> RevId

The RevId against which the operations were created

-> ObjId

Committer

-> [Operation]

The operations to apply

-> Bool

True if validation should be skipped

-> Avers ([Patch], Int, [Patch]) 

Views

data View obj a Source

Constructors

View 

Fields

viewName :: Text

The table name is derived from the view name. Therefore it should be unique amongst all views.

viewParser :: Datum -> Either AversError a

Function which parses objects stored in this view.

viewObjectTransformer :: obj -> Avers (Maybe a)

Function which transforms an Avers Object into a type stored in the view.

viewIndices :: [SomeIndex]

Secondary indices defined on the view.

data SomeView obj where Source

Constructors

SomeView :: (ToDatum a, FromDatum a, FromJSON obj, ToJSON a) => View obj a -> SomeView obj 

viewTable :: View obj a -> Exp Table Source

Construct the table name for the given view. The table names look something like this: "view_openGames"

updateView :: ToDatum a => View obj a -> ObjId -> Maybe obj -> Avers () Source

Index

data Index a Source

Constructors

Index 

data SomeIndex where Source

Constructors

SomeIndex :: IsDatum a => Index a -> SomeIndex 

Metrics