comparison mod_storage_mongodb/mod_storage_mongodb.lua @ 508:9831506dcfd6

mod_storage_mongodb: move database connecting to inside driver:open
author James Callahan <james@chatid.com>
date Wed, 14 Dec 2011 12:56:07 +1100
parents 46f578da4ff0
children bf2ad6d6c778
comparison
equal deleted inserted replaced
507:46f578da4ff0 508:9831506dcfd6
3 3
4 local params = assert ( module:get_option("mongodb") , "mongodb configuration not found" ); 4 local params = assert ( module:get_option("mongodb") , "mongodb configuration not found" );
5 5
6 local mongo = require "mongo"; 6 local mongo = require "mongo";
7 7
8 local conn = mongo.Connection.New ( true ); 8 local conn
9 conn:connect ( params.server );
10 conn:auth ( params );
11 9
12 local keyval_store = {}; 10 local keyval_store = {};
13 keyval_store.__index = keyval_store; 11 keyval_store.__index = keyval_store;
14 12
15 function keyval_store:get(username) 13 function keyval_store:get(username)
45 end 43 end
46 44
47 local driver = { name = "mongodb" }; 45 local driver = { name = "mongodb" };
48 46
49 function driver:open(store, typ) 47 function driver:open(store, typ)
48 if not conn then
49 conn = assert ( mongo.Connection.New ( true ) );
50 assert ( conn:connect ( params.server ) );
51 assert ( conn:auth ( params ) );
52 end
53
50 if not typ then -- default key-value store 54 if not typ then -- default key-value store
51 return setmetatable({ store = store }, keyval_store); 55 return setmetatable({ store = store }, keyval_store);
52 end; 56 end;
53 return nil, "unsupported-store"; 57 return nil, "unsupported-store";
54 end 58 end