text: var settings = require('./Settings.js'),
      projects = require('./projects.js'),
      ueberdb2 = require('ueberdb2')
  
  // Database connection
  var db = new ueberdb2.database(settings.dbType, settings.dbSettings);
  
  // Init..
  db.init(function(err){
    if(err){
      console.error(err);
    }
  });
  
  // Write to teh database
  exports.storeProject = function(room) {
    var project = projects.projects[room].project;
    var json = project.exportJSON();
    console.log("Writing project to database");
    db.set(room, {project: json});
  }
  
  // Try to load room from database
  exports.load = function(room, socket) {
    console.log("load from db");
    if (projects.projects[room] && projects.projects[room].project) {
      var project = projects.projects[room].project;
      db.get(room, function(err, value) {
        if (value && project && project.activeLayer) {
          socket.emit('loading:start');
          // Clear default layer as importing JSON adds a new layer.
          // We want the project to always only have one layer.
          project.activeLayer.remove();
          project.importJSON(value.project);
          socket.emit('project:load', value);
        }
        socket.emit('loading:end');
      });
      socket.emit('loading:end'); // used for sending back a blank database in case we try to load from DB but no project exists
    } else {
      loadError(socket);
    }
  }
  
  exports.db = db;
  