 
 class Database extends EventEmitter
 
-  constructor: (name) ->
+  constructor: (name, store) ->
     @_name = name
+    @_store = store
 
   load: (callback) ->
-    ledger.storage.databases.get @_name, (json) =>
+    @_store.get @_name, (json) =>
       try
         @_db = new loki(@_name)
         @_db.loadJSON JSON.stringify(json[@_name]) if json[@_name]?

      callback?()

  open: (databaseName, callback) ->
    db = new Database databaseName
    db.load callback
    db


      clearTimeout @_scheduledFlush if @_scheduledFlush?
      serializedData = {}
      serializedData[@_name] = @_db
      @_store.set serializedData, callback

  scheduleFlush: () ->
    clearTimeout @_scheduledFlush if @_scheduledFlush?
