faststep 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +15 -0
  4. data/bench/standard_benchmark +178 -0
  5. data/ext/faststep/bson.c +687 -0
  6. data/ext/faststep/bson.h +225 -0
  7. data/ext/faststep/bson_ruby_conversion.c +44 -0
  8. data/ext/faststep/bson_ruby_conversion.h +10 -0
  9. data/ext/faststep/collection.c +187 -0
  10. data/ext/faststep/collection.h +24 -0
  11. data/ext/faststep/connection.c +85 -0
  12. data/ext/faststep/connection.h +17 -0
  13. data/ext/faststep/cursor.c +61 -0
  14. data/ext/faststep/cursor.h +10 -0
  15. data/ext/faststep/db.c +56 -0
  16. data/ext/faststep/db.h +8 -0
  17. data/ext/faststep/exceptions.c +7 -0
  18. data/ext/faststep/exceptions.h +5 -0
  19. data/ext/faststep/extconf.rb +3 -0
  20. data/ext/faststep/faststep.c +30 -0
  21. data/ext/faststep/faststep.h +4 -0
  22. data/ext/faststep/faststep_defines.h +11 -0
  23. data/ext/faststep/gridfs.c +799 -0
  24. data/ext/faststep/gridfs.h +278 -0
  25. data/ext/faststep/md5.c +381 -0
  26. data/ext/faststep/md5.h +91 -0
  27. data/ext/faststep/mongo.c +801 -0
  28. data/ext/faststep/mongo.h +188 -0
  29. data/ext/faststep/mongo_except.h +143 -0
  30. data/ext/faststep/numbers.c +127 -0
  31. data/ext/faststep/platform_hacks.h +93 -0
  32. data/ext/faststep/support.c +21 -0
  33. data/ext/faststep/support.h +6 -0
  34. data/faststep.gemspec +26 -0
  35. data/lib/faststep/collection.rb +21 -0
  36. data/lib/faststep/connection.rb +13 -0
  37. data/lib/faststep/cursor.rb +7 -0
  38. data/lib/faststep/db.rb +25 -0
  39. data/lib/faststep/version.rb +3 -0
  40. data/lib/faststep.rb +10 -0
  41. data/spec/collection_spec.rb +116 -0
  42. data/spec/connection_spec.rb +34 -0
  43. data/spec/cursor_spec.rb +24 -0
  44. data/spec/db_spec.rb +28 -0
  45. data/spec/spec_helper.rb +13 -0
  46. data/spec/support_spec.rb +14 -0
  47. metadata +181 -0
@@ -0,0 +1,188 @@
1
+ /* mongo.h */
2
+
3
+ /* Copyright 2009, 2010 10gen Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #ifndef _MONGO_H_
19
+ #define _MONGO_H_
20
+
21
+ #include "mongo_except.h"
22
+ #include "bson.h"
23
+
24
+ #ifdef _WIN32
25
+ #include <windows.h>
26
+ #include <winsock.h>
27
+ #define mongo_close_socket(sock) ( closesocket(sock) )
28
+ typedef int socklen_t;
29
+ #else
30
+ #include <arpa/inet.h>
31
+ #include <sys/types.h>
32
+ #include <sys/socket.h>
33
+ #include <netinet/in.h>
34
+ #include <netinet/tcp.h>
35
+ #define mongo_close_socket(sock) ( close(sock) )
36
+ #endif
37
+
38
+ MONGO_EXTERN_C_START
39
+
40
+ typedef struct mongo_connection_options {
41
+ char host[255];
42
+ int port;
43
+ } mongo_connection_options;
44
+
45
+ typedef struct {
46
+ mongo_connection_options* left_opts; /* always current server */
47
+ mongo_connection_options* right_opts; /* unused with single server */
48
+ struct sockaddr_in sa;
49
+ socklen_t addressSize;
50
+ int sock;
51
+ bson_bool_t connected;
52
+ mongo_exception_context exception;
53
+ } mongo_connection;
54
+
55
+ #pragma pack(1)
56
+ typedef struct {
57
+ int len;
58
+ int id;
59
+ int responseTo;
60
+ int op;
61
+ } mongo_header;
62
+
63
+ typedef struct {
64
+ mongo_header head;
65
+ char data;
66
+ } mongo_message;
67
+
68
+ typedef struct {
69
+ int flag; /* non-zero on failure */
70
+ int64_t cursorID;
71
+ int start;
72
+ int num;
73
+ } mongo_reply_fields;
74
+
75
+ typedef struct {
76
+ mongo_header head;
77
+ mongo_reply_fields fields;
78
+ char objs;
79
+ } mongo_reply;
80
+ #pragma pack()
81
+
82
+ typedef struct {
83
+ mongo_reply * mm; /* message is owned by cursor */
84
+ mongo_connection * conn; /* connection is *not* owned by cursor */
85
+ const char* ns; /* owned by cursor */
86
+ bson current;
87
+ } mongo_cursor;
88
+
89
+ enum mongo_operations {
90
+ mongo_op_msg = 1000, /* generic msg command followed by a string */
91
+ mongo_op_update = 2001, /* update object */
92
+ mongo_op_insert = 2002,
93
+ mongo_op_query = 2004,
94
+ mongo_op_get_more = 2005,
95
+ mongo_op_delete = 2006,
96
+ mongo_op_kill_cursors = 2007
97
+ };
98
+
99
+
100
+ /* ----------------------------
101
+ CONNECTION STUFF
102
+ ------------------------------ */
103
+
104
+ typedef enum {
105
+ mongo_conn_success = 0,
106
+ mongo_conn_bad_arg,
107
+ mongo_conn_no_socket,
108
+ mongo_conn_fail,
109
+ mongo_conn_not_master /* leaves conn connected to slave */
110
+ } mongo_conn_return;
111
+
112
+ /**
113
+ * @param options can be null
114
+ */
115
+ mongo_conn_return mongo_connect( mongo_connection * conn , mongo_connection_options * options );
116
+ mongo_conn_return mongo_connect_pair( mongo_connection * conn , mongo_connection_options * left, mongo_connection_options * right );
117
+ mongo_conn_return mongo_reconnect( mongo_connection * conn ); /* you will need to reauthenticate after calling */
118
+ bson_bool_t mongo_disconnect( mongo_connection * conn ); /* use this if you want to be able to reconnect */
119
+ bson_bool_t mongo_destroy( mongo_connection * conn ); /* you must call this even if connection failed */
120
+
121
+
122
+
123
+ /* ----------------------------
124
+ CORE METHODS - insert update remove query getmore
125
+ ------------------------------ */
126
+
127
+ void mongo_insert( mongo_connection * conn , const char * ns , bson * data );
128
+ void mongo_insert_batch( mongo_connection * conn , const char * ns , bson ** data , int num );
129
+
130
+ static const int MONGO_UPDATE_UPSERT = 0x1;
131
+ static const int MONGO_UPDATE_MULTI = 0x2;
132
+ void mongo_update(mongo_connection* conn, const char* ns, const bson* cond, const bson* op, int flags);
133
+
134
+ void mongo_remove(mongo_connection* conn, const char* ns, const bson* cond);
135
+
136
+ mongo_cursor* mongo_find(mongo_connection* conn, const char* ns, bson* query, bson* fields ,int nToReturn ,int nToSkip, int options);
137
+ bson_bool_t mongo_cursor_next(mongo_cursor* cursor);
138
+ void mongo_cursor_destroy(mongo_cursor* cursor);
139
+
140
+ /* out can be NULL if you don't care about results. useful for commands */
141
+ bson_bool_t mongo_find_one(mongo_connection* conn, const char* ns, bson* query, bson* fields, bson* out);
142
+
143
+ int64_t mongo_count(mongo_connection* conn, const char* db, const char* coll, bson* query);
144
+
145
+ /* ----------------------------
146
+ HIGHER LEVEL - indexes - command helpers eval
147
+ ------------------------------ */
148
+
149
+ /* Returns true on success */
150
+ /* WARNING: Unlike other drivers these do not cache results */
151
+
152
+ static const int MONGO_INDEX_UNIQUE = 0x1;
153
+ static const int MONGO_INDEX_DROP_DUPS = 0x2;
154
+ bson_bool_t mongo_create_index(mongo_connection * conn, const char * ns, bson * key, int options, bson * out);
155
+ bson_bool_t mongo_create_simple_index(mongo_connection * conn, const char * ns, const char* field, int options, bson * out);
156
+
157
+ /* ----------------------------
158
+ COMMANDS
159
+ ------------------------------ */
160
+
161
+ bson_bool_t mongo_run_command(mongo_connection * conn, const char * db, bson * command, bson * out);
162
+
163
+ /* for simple commands with a single k-v pair */
164
+ bson_bool_t mongo_simple_int_command(mongo_connection * conn, const char * db, const char* cmd, int arg, bson * out);
165
+ bson_bool_t mongo_simple_str_command(mongo_connection * conn, const char * db, const char* cmd, const char* arg, bson * out);
166
+
167
+ bson_bool_t mongo_cmd_drop_db(mongo_connection * conn, const char * db);
168
+ bson_bool_t mongo_cmd_drop_collection(mongo_connection * conn, const char * db, const char * collection, bson * out);
169
+
170
+ void mongo_cmd_add_user(mongo_connection* conn, const char* db, const char* user, const char* pass);
171
+ bson_bool_t mongo_cmd_authenticate(mongo_connection* conn, const char* db, const char* user, const char* pass);
172
+
173
+ /* return value is master status */
174
+ bson_bool_t mongo_cmd_ismaster(mongo_connection * conn, bson * out);
175
+
176
+ /* true return indicates error */
177
+ bson_bool_t mongo_cmd_get_last_error(mongo_connection * conn, const char * db, bson * out);
178
+ bson_bool_t mongo_cmd_get_prev_error(mongo_connection * conn, const char * db, bson * out);
179
+ void mongo_cmd_reset_error(mongo_connection * conn, const char * db);
180
+
181
+ /* ----------------------------
182
+ UTILS
183
+ ------------------------------ */
184
+
185
+ MONGO_EXTERN_C_END
186
+
187
+
188
+ #endif
@@ -0,0 +1,143 @@
1
+ /* mongo_except.h */
2
+
3
+ /* Copyright 2009 10gen Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /* This file is based loosely on cexcept (http://www.nicemice.net/cexcept/). I
19
+ * have modified it to work better with mongo's API.
20
+ *
21
+ * The MONGO_TRY, MONGO_CATCH, and MONGO_TROW macros assume that a pointer to
22
+ * the current connection is available as 'conn'. If you would like to use a
23
+ * different name, use the _GENERIC version of these macros.
24
+ *
25
+ * WARNING: do not return or otherwise jump (excluding MONGO_TRHOW()) out of a
26
+ * MONGO_TRY block as the nessesary clean-up code will not be called. Jumping
27
+ * out of the MONGO_CATCH block is OK.
28
+ */
29
+
30
+ #ifdef MONGO_CODE_EXAMPLE
31
+ mongo_connection conn[1]; /* makes conn a ptr to the connection */
32
+
33
+ MONGO_TRY{
34
+ mongo_find_one(...);
35
+ MONGO_THROW(conn, MONGO_EXCEPT_NETWORK);
36
+ }MONGO_CATCH{
37
+ switch(conn->exception->type){
38
+ case MONGO_EXCEPT_NETWORK:
39
+ do_something();
40
+ case MONGO_EXCEPT_FIND_ERR:
41
+ do_something();
42
+ default:
43
+ MONGO_RETHROW();
44
+ }
45
+ }
46
+ #endif
47
+
48
+ /* ORIGINAL CEXEPT COPYRIGHT:
49
+ cexcept: README 2.0.1 (2008-Jul-23-Wed)
50
+ http://www.nicemice.net/cexcept/
51
+ Adam M. Costello
52
+ http://www.nicemice.net/amc/
53
+
54
+ The package is both free-as-in-speech and free-as-in-beer:
55
+
56
+ Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta.
57
+ This package may be modified only if its author and version
58
+ information is updated accurately, and may be redistributed
59
+ only if accompanied by this unaltered notice. Subject to those
60
+ restrictions, permission is granted to anyone to do anything with
61
+ this package. The copyright holders make no guarantees regarding
62
+ this package, and are not responsible for any damage resulting from
63
+ its use.
64
+ */
65
+
66
+ #ifndef _MONGO_EXCEPT_H_
67
+ #define _MONGO_EXCEPT_H_
68
+
69
+ #include <setjmp.h>
70
+
71
+ /* always non-zero */
72
+ typedef enum{
73
+ MONGO_EXCEPT_NETWORK=1,
74
+ MONGO_EXCEPT_FIND_ERR
75
+ }mongo_exception_type;
76
+
77
+
78
+ typedef struct {
79
+ jmp_buf base_handler;
80
+ jmp_buf *penv;
81
+ int caught;
82
+ volatile mongo_exception_type type;
83
+ }mongo_exception_context;
84
+
85
+ #define MONGO_TRY MONGO_TRY_GENERIC(conn)
86
+ #define MONGO_CATCH MONGO_CATCH_GENERIC(conn)
87
+ #define MONGO_THROW(e) MONGO_THROW_GENERIC(conn, e)
88
+ #define MONGO_RETHROW() MONGO_RETHROW_GENERIC(conn)
89
+
90
+ /* the rest of this file is implementation details */
91
+
92
+ /* this is done in mongo_connect */
93
+ #define MONGO_INIT_EXCEPTION(exception_ptr) \
94
+ do{ \
95
+ mongo_exception_type t; /* exception_ptr won't be available */\
96
+ (exception_ptr)->penv = &(exception_ptr)->base_handler; \
97
+ if ((t = setjmp((exception_ptr)->base_handler))) { /* yes, '=' is correct */ \
98
+ switch(t){ \
99
+ case MONGO_EXCEPT_NETWORK: bson_fatal_msg(0, "network error"); \
100
+ case MONGO_EXCEPT_FIND_ERR: bson_fatal_msg(0, "error in find"); \
101
+ default: bson_fatal_msg(0, "unknown exception"); \
102
+ } \
103
+ } \
104
+ }while(0)
105
+
106
+ #define MONGO_TRY_GENERIC(connection) \
107
+ { \
108
+ jmp_buf *exception__prev, exception__env; \
109
+ exception__prev = (connection)->exception.penv; \
110
+ (connection)->exception.penv = &exception__env; \
111
+ if (setjmp(exception__env) == 0) { \
112
+ do
113
+
114
+ #define MONGO_CATCH_GENERIC(connection) \
115
+ while ((connection)->exception.caught = 0, \
116
+ (connection)->exception.caught); \
117
+ } \
118
+ else { \
119
+ (connection)->exception.caught = 1; \
120
+ } \
121
+ (connection)->exception.penv = exception__prev; \
122
+ } \
123
+ if (!(connection)->exception.caught ) { } \
124
+ else
125
+
126
+ /* Try ends with do, and Catch begins with while(0) and ends with */
127
+ /* else, to ensure that Try/Catch syntax is similar to if/else */
128
+ /* syntax. */
129
+ /* */
130
+ /* The 0 in while(0) is expressed as x=0,x in order to appease */
131
+ /* compilers that warn about constant expressions inside while(). */
132
+ /* Most compilers should still recognize that the condition is always */
133
+ /* false and avoid generating code for it. */
134
+
135
+ #define MONGO_THROW_GENERIC(connection, type_in) \
136
+ for (;; longjmp(*(connection)->exception.penv, type_in)) \
137
+ (connection)->exception.type = type_in
138
+
139
+ #define MONGO_RETHROW_GENERIC(connection) \
140
+ MONGO_THROW_GENERIC(connection, (connection)->exception.type)
141
+
142
+
143
+ #endif
@@ -0,0 +1,127 @@
1
+ /* Copyright 2009 10gen Inc.
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ /* all the numbers that fit in a 4 byte string */
17
+ const char bson_numstrs[1000][4] = {
18
+ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
19
+ "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
20
+ "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
21
+ "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
22
+ "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
23
+ "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",
24
+ "60", "61", "62", "63", "64", "65", "66", "67", "68", "69",
25
+ "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",
26
+ "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",
27
+ "90", "91", "92", "93", "94", "95", "96", "97", "98", "99",
28
+
29
+ "100", "101", "102", "103", "104", "105", "106", "107", "108", "109",
30
+ "110", "111", "112", "113", "114", "115", "116", "117", "118", "119",
31
+ "120", "121", "122", "123", "124", "125", "126", "127", "128", "129",
32
+ "130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
33
+ "140", "141", "142", "143", "144", "145", "146", "147", "148", "149",
34
+ "150", "151", "152", "153", "154", "155", "156", "157", "158", "159",
35
+ "160", "161", "162", "163", "164", "165", "166", "167", "168", "169",
36
+ "170", "171", "172", "173", "174", "175", "176", "177", "178", "179",
37
+ "180", "181", "182", "183", "184", "185", "186", "187", "188", "189",
38
+ "190", "191", "192", "193", "194", "195", "196", "197", "198", "199",
39
+
40
+ "200", "201", "202", "203", "204", "205", "206", "207", "208", "209",
41
+ "210", "211", "212", "213", "214", "215", "216", "217", "218", "219",
42
+ "220", "221", "222", "223", "224", "225", "226", "227", "228", "229",
43
+ "230", "231", "232", "233", "234", "235", "236", "237", "238", "239",
44
+ "240", "241", "242", "243", "244", "245", "246", "247", "248", "249",
45
+ "250", "251", "252", "253", "254", "255", "256", "257", "258", "259",
46
+ "260", "261", "262", "263", "264", "265", "266", "267", "268", "269",
47
+ "270", "271", "272", "273", "274", "275", "276", "277", "278", "279",
48
+ "280", "281", "282", "283", "284", "285", "286", "287", "288", "289",
49
+ "290", "291", "292", "293", "294", "295", "296", "297", "298", "299",
50
+
51
+ "300", "301", "302", "303", "304", "305", "306", "307", "308", "309",
52
+ "310", "311", "312", "313", "314", "315", "316", "317", "318", "319",
53
+ "320", "321", "322", "323", "324", "325", "326", "327", "328", "329",
54
+ "330", "331", "332", "333", "334", "335", "336", "337", "338", "339",
55
+ "340", "341", "342", "343", "344", "345", "346", "347", "348", "349",
56
+ "350", "351", "352", "353", "354", "355", "356", "357", "358", "359",
57
+ "360", "361", "362", "363", "364", "365", "366", "367", "368", "369",
58
+ "370", "371", "372", "373", "374", "375", "376", "377", "378", "379",
59
+ "380", "381", "382", "383", "384", "385", "386", "387", "388", "389",
60
+ "390", "391", "392", "393", "394", "395", "396", "397", "398", "399",
61
+
62
+ "400", "401", "402", "403", "404", "405", "406", "407", "408", "409",
63
+ "410", "411", "412", "413", "414", "415", "416", "417", "418", "419",
64
+ "420", "421", "422", "423", "424", "425", "426", "427", "428", "429",
65
+ "430", "431", "432", "433", "434", "435", "436", "437", "438", "439",
66
+ "440", "441", "442", "443", "444", "445", "446", "447", "448", "449",
67
+ "450", "451", "452", "453", "454", "455", "456", "457", "458", "459",
68
+ "460", "461", "462", "463", "464", "465", "466", "467", "468", "469",
69
+ "470", "471", "472", "473", "474", "475", "476", "477", "478", "479",
70
+ "480", "481", "482", "483", "484", "485", "486", "487", "488", "489",
71
+ "490", "491", "492", "493", "494", "495", "496", "497", "498", "499",
72
+
73
+ "500", "501", "502", "503", "504", "505", "506", "507", "508", "509",
74
+ "510", "511", "512", "513", "514", "515", "516", "517", "518", "519",
75
+ "520", "521", "522", "523", "524", "525", "526", "527", "528", "529",
76
+ "530", "531", "532", "533", "534", "535", "536", "537", "538", "539",
77
+ "540", "541", "542", "543", "544", "545", "546", "547", "548", "549",
78
+ "550", "551", "552", "553", "554", "555", "556", "557", "558", "559",
79
+ "560", "561", "562", "563", "564", "565", "566", "567", "568", "569",
80
+ "570", "571", "572", "573", "574", "575", "576", "577", "578", "579",
81
+ "580", "581", "582", "583", "584", "585", "586", "587", "588", "589",
82
+ "590", "591", "592", "593", "594", "595", "596", "597", "598", "599",
83
+
84
+ "600", "601", "602", "603", "604", "605", "606", "607", "608", "609",
85
+ "610", "611", "612", "613", "614", "615", "616", "617", "618", "619",
86
+ "620", "621", "622", "623", "624", "625", "626", "627", "628", "629",
87
+ "630", "631", "632", "633", "634", "635", "636", "637", "638", "639",
88
+ "640", "641", "642", "643", "644", "645", "646", "647", "648", "649",
89
+ "650", "651", "652", "653", "654", "655", "656", "657", "658", "659",
90
+ "660", "661", "662", "663", "664", "665", "666", "667", "668", "669",
91
+ "670", "671", "672", "673", "674", "675", "676", "677", "678", "679",
92
+ "680", "681", "682", "683", "684", "685", "686", "687", "688", "689",
93
+ "690", "691", "692", "693", "694", "695", "696", "697", "698", "699",
94
+
95
+ "700", "701", "702", "703", "704", "705", "706", "707", "708", "709",
96
+ "710", "711", "712", "713", "714", "715", "716", "717", "718", "719",
97
+ "720", "721", "722", "723", "724", "725", "726", "727", "728", "729",
98
+ "730", "731", "732", "733", "734", "735", "736", "737", "738", "739",
99
+ "740", "741", "742", "743", "744", "745", "746", "747", "748", "749",
100
+ "750", "751", "752", "753", "754", "755", "756", "757", "758", "759",
101
+ "760", "761", "762", "763", "764", "765", "766", "767", "768", "769",
102
+ "770", "771", "772", "773", "774", "775", "776", "777", "778", "779",
103
+ "780", "781", "782", "783", "784", "785", "786", "787", "788", "789",
104
+ "790", "791", "792", "793", "794", "795", "796", "797", "798", "799",
105
+
106
+ "800", "801", "802", "803", "804", "805", "806", "807", "808", "809",
107
+ "810", "811", "812", "813", "814", "815", "816", "817", "818", "819",
108
+ "820", "821", "822", "823", "824", "825", "826", "827", "828", "829",
109
+ "830", "831", "832", "833", "834", "835", "836", "837", "838", "839",
110
+ "840", "841", "842", "843", "844", "845", "846", "847", "848", "849",
111
+ "850", "851", "852", "853", "854", "855", "856", "857", "858", "859",
112
+ "860", "861", "862", "863", "864", "865", "866", "867", "868", "869",
113
+ "870", "871", "872", "873", "874", "875", "876", "877", "878", "879",
114
+ "880", "881", "882", "883", "884", "885", "886", "887", "888", "889",
115
+ "890", "891", "892", "893", "894", "895", "896", "897", "898", "899",
116
+
117
+ "900", "901", "902", "903", "904", "905", "906", "907", "908", "909",
118
+ "910", "911", "912", "913", "914", "915", "916", "917", "918", "919",
119
+ "920", "921", "922", "923", "924", "925", "926", "927", "928", "929",
120
+ "930", "931", "932", "933", "934", "935", "936", "937", "938", "939",
121
+ "940", "941", "942", "943", "944", "945", "946", "947", "948", "949",
122
+ "950", "951", "952", "953", "954", "955", "956", "957", "958", "959",
123
+ "960", "961", "962", "963", "964", "965", "966", "967", "968", "969",
124
+ "970", "971", "972", "973", "974", "975", "976", "977", "978", "979",
125
+ "980", "981", "982", "983", "984", "985", "986", "987", "988", "989",
126
+ "990", "991", "992", "993", "994", "995", "996", "997", "998", "999",
127
+ };
@@ -0,0 +1,93 @@
1
+ /* platform_hacks.h */
2
+ /* Copyright 2009, 2010 10gen Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+
18
+ /* all platform-specific ifdefs should go here */
19
+
20
+ #ifndef _PLATFORM_HACKS_H_
21
+ #define _PLATFORM_HACKS_H_
22
+
23
+ #ifdef __GNUC__
24
+ #define MONGO_INLINE static __inline__
25
+ #else
26
+ #define MONGO_INLINE static
27
+ #endif
28
+
29
+ #ifdef __cplusplus
30
+ #define MONGO_EXTERN_C_START extern "C" {
31
+ #define MONGO_EXTERN_C_END }
32
+ #else
33
+ #define MONGO_EXTERN_C_START
34
+ #define MONGO_EXTERN_C_END
35
+ #endif
36
+
37
+
38
+ #if defined(MONGO_HAVE_STDINT) || __STDC_VERSION__ >= 199901L
39
+ #include <stdint.h>
40
+ #elif defined(MONGO_HAVE_UNISTD)
41
+ #include <unistd.h>
42
+ #elif defined(MONGO_USE__INT64)
43
+ typedef __int64 int64_t;
44
+ typedef unsigned __int64 uint64_t;
45
+ #elif defined(MONGO_USE_LONG_LONG_INT)
46
+ typedef long long int int64_t;
47
+ typedef unsigned long long int uint64_t;
48
+ #else
49
+ #error must have a 64bit int type
50
+ #endif
51
+
52
+ /* big endian is only used for OID generation. little is used everywhere else */
53
+ #ifdef MONGO_BIG_ENDIAN
54
+ #define bson_little_endian64(out, in) ( bson_swap_endian64(out, in) )
55
+ #define bson_little_endian32(out, in) ( bson_swap_endian32(out, in) )
56
+ #define bson_big_endian64(out, in) ( memcpy(out, in, 8) )
57
+ #define bson_big_endian32(out, in) ( memcpy(out, in, 4) )
58
+ #else
59
+ #define bson_little_endian64(out, in) ( memcpy(out, in, 8) )
60
+ #define bson_little_endian32(out, in) ( memcpy(out, in, 4) )
61
+ #define bson_big_endian64(out, in) ( bson_swap_endian64(out, in) )
62
+ #define bson_big_endian32(out, in) ( bson_swap_endian32(out, in) )
63
+ #endif
64
+
65
+ MONGO_EXTERN_C_START
66
+
67
+ MONGO_INLINE void bson_swap_endian64(void* outp, const void* inp){
68
+ const char *in = (const char*)inp;
69
+ char *out = (char*)outp;
70
+
71
+ out[0] = in[7];
72
+ out[1] = in[6];
73
+ out[2] = in[5];
74
+ out[3] = in[4];
75
+ out[4] = in[3];
76
+ out[5] = in[2];
77
+ out[6] = in[1];
78
+ out[7] = in[0];
79
+
80
+ }
81
+ MONGO_INLINE void bson_swap_endian32(void* outp, const void* inp){
82
+ const char *in = (const char*)inp;
83
+ char *out = (char*)outp;
84
+
85
+ out[0] = in[3];
86
+ out[1] = in[2];
87
+ out[2] = in[1];
88
+ out[3] = in[0];
89
+ }
90
+
91
+ MONGO_EXTERN_C_END
92
+
93
+ #endif
@@ -0,0 +1,21 @@
1
+ #include "support.h"
2
+ #include "faststep_defines.h"
3
+ #include "bson_ruby_conversion.h"
4
+
5
+ void faststep_support_main() {
6
+ rb_mFaststepSupport = rb_define_module_under(rb_mFaststep, "Support");
7
+ rb_define_singleton_method(rb_mFaststepSupport, "ok?", faststep_support_ok, 1);
8
+ }
9
+
10
+ static VALUE faststep_support_ok(VALUE self, VALUE document) {
11
+ VALUE ok_value = rb_hash_aref(document, rb_str_new2("ok"));
12
+
13
+ bson_bool_t result = 0;
14
+
15
+ switch(TYPE(ok_value)) {
16
+ case T_FLOAT: result = FIX2INT(ok_value); break;
17
+ case T_TRUE: result = 1; break;
18
+ }
19
+
20
+ return bool_to_ruby(result);
21
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef SUPPORT_H
2
+ #include <ruby.h>
3
+ #define SUPPORT_H
4
+ void faststep_support_main();
5
+ static VALUE faststep_support_ok(VALUE, VALUE);
6
+ #endif
data/faststep.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "faststep/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "faststep"
7
+ s.version = Faststep::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Josh Clayton"]
10
+ s.email = ["joshua.clayton@gmail.com"]
11
+ s.summary = %q{Mongo on Speed}
12
+ s.description = %q{Mongo on Speed}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.extensions = ["ext/faststep/extconf.rb"]
20
+
21
+ s.add_dependency "rake-compiler", "0.7.6"
22
+ s.add_dependency "bson", "1.2.4"
23
+ s.add_dependency "bson_ext", "1.2.4"
24
+
25
+ s.add_development_dependency "rspec", "2.5.0"
26
+ end
@@ -0,0 +1,21 @@
1
+ module Faststep
2
+ class Collection
3
+ def find(selector = {}, options = {})
4
+ Cursor.new(self, "selector" => selector)
5
+ end
6
+
7
+ def find_one(spec_or_object_id=nil, opts={})
8
+ spec = case spec_or_object_id
9
+ when nil
10
+ {}
11
+ when BSON::ObjectId
12
+ {:_id => spec_or_object_id}
13
+ when Hash
14
+ spec_or_object_id
15
+ else
16
+ raise TypeError, "spec_or_object_id must be an instance of ObjectId or Hash, or nil"
17
+ end
18
+ find(spec, opts.merge(:limit => -1)).first
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Faststep
2
+ class Connection
3
+ DEFAULT_PORT = 27017
4
+
5
+ def db(database_name)
6
+ Db.new(database_name, self)
7
+ end
8
+
9
+ def drop_database(database_name)
10
+ Db.new(database_name, self).drop
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Faststep
2
+ class Cursor
3
+ def to_a
4
+ super
5
+ end
6
+ end
7
+ end