comparison plugins/storage/mod_storage.lua @ 3277:da0f55661e2b

mod_storage: Make DBI a soft dependency, not a hard one.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 18 Jun 2010 14:22:17 +0500
parents c5882e2e12b5
children
comparison
equal deleted inserted replaced
3276:4e44469b0583 3277:da0f55661e2b
3 3
4 local cache = { data = {} }; 4 local cache = { data = {} };
5 function cache:get(key) return self.data[key]; end 5 function cache:get(key) return self.data[key]; end
6 function cache:set(key, val) self.data[key] = val; return val; end 6 function cache:set(key, val) self.data[key] = val; return val; end
7 7
8 local DBI = require "DBI"; 8 local _,DBI = pcall(require, "DBI");
9 function get_database(driver, db, ...) 9 function get_database(driver, db, ...)
10 local uri = "dbi:"..driver..":"..db; 10 local uri = "dbi:"..driver..":"..db;
11 return cache:get(uri) or cache:set(uri, (function(...) 11 return cache:get(uri) or cache:set(uri, (function(...)
12 module:log("debug", "Opening database: %s", uri); 12 module:log("debug", "Opening database: %s", uri);
13 prosody.unlock_globals(); 13 prosody.unlock_globals();