2007-10-20 01:35:48 +02:00
|
|
|
// query.h
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../stdafx.h"
|
|
|
|
#include "../grid/message.h"
|
2007-10-28 21:38:06 +01:00
|
|
|
#include "jsobj.h"
|
2007-11-05 01:17:42 +01:00
|
|
|
#include "storage.h"
|
2007-10-20 01:35:48 +02:00
|
|
|
|
2007-10-28 19:42:59 +01:00
|
|
|
/* requests:
|
|
|
|
|
2007-10-30 10:50:14 +01:00
|
|
|
dbDelete
|
|
|
|
int reserved=0;
|
|
|
|
string collection;
|
|
|
|
int flags=0; // 1=DeleteSingle
|
|
|
|
JSObject query;
|
|
|
|
dbUpdate:
|
|
|
|
int reserved;
|
|
|
|
string collection;
|
|
|
|
int flags; // 1=upsert
|
|
|
|
JSObject query;
|
|
|
|
JSObject objectToUpdate;
|
|
|
|
dbQuery:
|
2007-10-28 19:42:59 +01:00
|
|
|
int reserved;
|
|
|
|
string collection;
|
|
|
|
int nToReturn; // how many you want back as the beginning of the cursor data
|
|
|
|
JSObject query;
|
2007-10-30 10:50:14 +01:00
|
|
|
dbGetMore:
|
2007-11-04 22:17:44 +01:00
|
|
|
int reserved;
|
|
|
|
string collection; // redundant, might use for security.
|
2007-10-28 19:42:59 +01:00
|
|
|
int nToReturn;
|
2007-11-04 22:17:44 +01:00
|
|
|
int64 cursorID;
|
2007-10-30 10:50:14 +01:00
|
|
|
|
|
|
|
Note that on Update, there is only one object, which is different
|
|
|
|
from insert where you can pass a list of objects to insert in the db.
|
|
|
|
Note that the update field layout is very similar layout to Query.
|
2007-10-28 19:42:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* db response format
|
|
|
|
|
2007-10-20 01:35:48 +02:00
|
|
|
Query or GetMore:
|
|
|
|
int reserved;
|
2007-10-28 19:42:59 +01:00
|
|
|
int64 cursorID;
|
|
|
|
int startingFrom;
|
2007-10-28 21:38:06 +01:00
|
|
|
int nReturned; // 0=infinity
|
2007-10-20 01:35:48 +02:00
|
|
|
list of marshalled JSObjects;
|
2007-10-28 21:38:06 +01:00
|
|
|
*/
|
2007-10-20 01:35:48 +02:00
|
|
|
|
|
|
|
struct QueryResult : public MsgData {
|
2007-10-28 19:42:59 +01:00
|
|
|
long long cursorId;
|
|
|
|
int startingFrom;
|
2007-10-20 01:35:48 +02:00
|
|
|
int nReturned;
|
2007-10-28 21:38:06 +01:00
|
|
|
const char *data() { return (char *) (((int *)&nReturned)+1); }
|
2007-10-20 01:35:48 +02:00
|
|
|
};
|
|
|
|
|
2007-11-04 22:17:44 +01:00
|
|
|
QueryResult* getMore(const char *ns, int ntoreturn, long long cursorid);
|
2007-10-28 21:38:06 +01:00
|
|
|
QueryResult* runQuery(const char *ns, int ntoreturn, JSObj);
|
2007-10-20 01:35:48 +02:00
|
|
|
|
2007-10-30 10:50:14 +01:00
|
|
|
void updateObjects(const char *ns, JSObj updateobj, JSObj pattern, bool upsert);
|
|
|
|
void deleteObjects(const char *ns, JSObj pattern, bool justOne);
|
2007-11-04 22:17:44 +01:00
|
|
|
|
|
|
|
class Cursor;
|
|
|
|
class ClientCursor {
|
|
|
|
public:
|
|
|
|
ClientCursor() { cursorid=0; pos=0; }
|
2007-11-05 01:17:42 +01:00
|
|
|
~ClientCursor();
|
2007-11-04 22:17:44 +01:00
|
|
|
long long cursorid;
|
|
|
|
string ns;
|
|
|
|
auto_ptr<JSMatcher> matcher;
|
|
|
|
auto_ptr<Cursor> c;
|
|
|
|
int pos;
|
2007-11-05 01:17:42 +01:00
|
|
|
DiskLoc lastLoc;
|
|
|
|
|
|
|
|
void updateLocation();
|
2007-11-04 22:17:44 +01:00
|
|
|
};
|
|
|
|
|