-
Notifications
You must be signed in to change notification settings - Fork 5
/
MEConnection.h
78 lines (62 loc) · 2.39 KB
/
MEConnection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// MEConnection.h
// Mongo Explorer
//
// Created by François Beausoleil on 10-06-06.
// Copyright 2010 Solutions Technologiques Internationales. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "mongo.h"
@class MEDatabase;
/* The key under which you'll find the database's name in the returned NSDictionary
* from -databases.
*/
extern NSString * const MEDBName;
/* The key under which you'll find the database's size in the returned NSDictionary
* from -databases.
*/
extern NSString * const MEDBSize;
/* The key under which MEConnection will find it's host name in -initWithConnectionInfo: */
extern NSString * const MEHost;
/* The key under which MEConnection will find the port to connect to in -initWithConnectionInfo: */
extern NSString * const MEPort;
/* The key under which MEConnection will find it's user name in -initWithConnectionInfo: */
extern NSString * const MEUsername;
/* The key under which MEConnection will find it's password in -initWithConnectionInfo: */
extern NSString * const MEPassword;
/* Represents a connection to a Mongo instance. You may instantiate multiple such objects.
* On release, this object will clean up and disconnect from Mongo, if still connected.
*/
@interface MEConnection : NSObject {
mongo_connection *connection;
}
@property(nonatomic, copy) NSString *host;
@property(nonatomic, assign) NSUInteger port;
@property(nonatomic, copy) NSString *username;
@property(nonatomic, copy) NSString *password;
@property(readonly) BOOL connected;
@property(readonly) NSString *connectionString;
-(id)initWithConnectionInfo:(NSDictionary *)connectionInfo;
/* Opens the connection to Mongo, or does nothing.
*
* If the connection is already open (connected is YES), nothing happens.
* Else, the connection to Mongo will be open, and kept alive.
*
* @return 0 if connected, else a Mongo error code.
*/
-(int)connect;
/* Disconnects from Mongo.
*
* If MEConnection was disconnected, nothing happens. If we were connected,
* the connection will be dropped. Calling any methods will reconnect.
*/
-(void)disconnect;
/* Returns the databases available to this instance.
*
* The return value is an NSSet of MEDatabase objects.
*/
-(NSSet *)databases;
/* Returns the named database, or nil if it doesn't exist. */
-(MEDatabase *)databaseNamed:(NSString *)name;
-(NSUInteger)documentsCountFromCollection:(NSString *)collectionName database:(NSString *)databaseName;
@end