hails-0.1.1: IFC enforcing web platform framework

Safe HaskellUnsafe

Hails.Database.MongoDB.TCB.Query

Contents

Synopsis

Documentation

insert :: Insert l p s doc => CollectionName -> doc -> Action l p s (Value l)Source

Insert document into collection and return its _id value, which is created automatically if not supplied. It is required that the current label flow to the label of the collection and database (and vice versa). Additionally, the document must be well-formed with respect to the collection policy. In other words, all the labeled values must be below the collection clearance and the policy be applied successfully.

insert_ :: Insert l p s doc => CollectionName -> doc -> Action l p s ()Source

Same as insert except it does not return _id

insertP :: Insert l p s doc => p -> CollectionName -> doc -> Action l p s (Value l)Source

Same as insert, but uses privileges when applying the collection policies, and doing label comparisons.

insertP_ :: Insert l p s doc => p -> CollectionName -> doc -> Action l p s ()Source

Same as insertP except it does not return _id

save :: Insert l p s doc => CollectionName -> doc -> Action l p s ()Source

Update a document based on the _id value. The IFC requirements subsume those of insert. Specifically, in addition to being able to apply all the policies and requiring that the current label flow to the label of the collection and database save requires that the current label flow to the label of the existing database record.

saveP :: Insert l p s doc => p -> CollectionName -> doc -> Action l p s ()Source

Like save, but uses privileges when performing label comparisons.

deleteOne :: (LabelState l p s, Serialize l) => Selection l -> Action l p s ()Source

Given a query, delete first object in selection. In addition to being able to read the object, write to the database and collection, it must be that the current label flow to the label of the existing document.

deleteOneP :: (LabelState l p s, Serialize l) => p -> Selection l -> Action l p s ()Source

Same as deleteOne, but uses privileges when performing label comparisons.

Finding objects

find :: (Serialize l, LabelState l p s) => Query l -> Action l p s (Cursor l)Source

Fetch documents satisfying query. A labeled Cursor is returned, which can be used to retrieve the actual Documents. Current label is raised to the join of the collection, database, and ccollection-policy label.

findP :: (Serialize l, LabelState l p s) => p -> Query l -> Action l p s (Cursor l)Source

Same as find, but uses privileges when raising the current label

findOne :: (LabelState l p s, Serialize l) => Query l -> Action l p s (Maybe (LabeledDocument l))Source

Fetch the first document satisfying query, or Nothing if not documents matched the query.

findOneP :: (LabelState l p s, Serialize l) => p -> Query l -> Action l p s (Maybe (LabeledDocument l))Source

Same as findOne, but uses privileges when performing label comparisons.

next :: (LabelState l p s, Serialize l) => Cursor l -> Action l p s (Maybe (LabeledDocument l))Source

Return next document in query result, or Nothing if finished. The current label is raised to join of the current label and Cursor label. The document is labeled according to the underlying 'Collection'\'s policies.

nextP :: (LabelState l p s, Serialize l) => p -> Cursor l -> Action l p s (Maybe (LabeledDocument l))Source

Same as next, but usess privileges raising the current label.

data Query l Source

Use select to create a basic query with defaults, then modify if desired. Example: (select sel col) {limit =: 10}. Note that unlike MongoDB's query functionality, our queries do not allow for projections (since policies may need a field that is not projects). Both the selection and sorting are restricted to searchable fields.

TODO: add snapshot.

Constructors

Query 

Fields

options :: [QueryOption]

Query options, default [].

selection :: Selection l

WHERE clause,default [].

skip :: Word32

Number of documents to skip, default 0.

limit :: Limit

Max number of documents to return. Default, 0, means no limit.

sort :: Order l

Sort result by given order, default [].

batchSize :: BatchSize

The number of document to return in each batch response from the server. 0 means Mongo default.

hint :: Order l

Force mongoDB to use this index (must be only searchable fields). Default [], no hint.

Instances

Select Query 

data Selection l Source

Selects documents in specified collection that match the selector.

Constructors

Selection 

Fields

selector :: Selector l

Selector

coll :: CollectionName

Collection operaing

Instances

Select Selection 

type Selector l = Document lSource

Filter for a query, analogous to the WHERE clause in SQL. [] matches all documents in collection. [x =: a, y =: b] is analogous to WHERE x = a AND y = b in SQL.

Note: all labeld (including policy-labeled) values are removed from the Selector.

select :: (Select selectionOrQuery, Label l) => Selector l -> CollectionName -> selectionOrQuery lSource

Query or Selection that selects documents in collection that match selector. The choice of end type depends on use, for example, in find select sel col is a Query, but in delete it is a Selection.