     teacherproperties: trequire("#{data_dir}/teacherproperties")
     schools: trequire("#{data_dir}/schools")
     schoolproperties: trequire("#{data_dir}/schoolproperties")
+
+  # clever.map[resources] are maps from ids to resources (for faster lookup)
+  # This doesn't just replace clever.db for compatibility reasons..for now..
+  clever.refresh_map = ->
+    map_id_to_val = (db, resource, id_key) ->
+      map = {}
+      map[obj[id_key]] = obj for i, obj of db[resource]
+      map
+    clever.map =
+      districts: map_id_to_val clever.db, 'districts', 'id'
+      districtproperties: map_id_to_val clever.db, 'districtproperties', 'district'
+      students: map_id_to_val clever.db, 'students', 'id'
+      studentproperties: map_id_to_val clever.db, 'studentproperties', 'student'
+      teachers: map_id_to_val clever.db, 'teachers', 'id'
+      teacherproperties: map_id_to_val clever.db, 'teacherproperties', 'teacher'
+      schools: map_id_to_val clever.db, 'schools', 'id'
+      schoolproperties: map_id_to_val clever.db, 'schoolproperties', 'school'
+  clever.refresh_map()
 
   sandbox = sinon.sandbox.create()
 

_.mixin require('underscore.string').exports()
_.mixin require('underscore.deep')

module.exports = (api_key, data_dir) ->
  throw new Error "Must provide api_key" unless api_key?
  throw new Error "Must provide data_dir" unless data_dir?

  clever = require("./index") api_key, "localhost"

  trequire = (fp) ->
    val = []
    if fs.existsSync("#{fp}.coffee") or fs.existsSync("#{fp}.js") or fs.existsSync("#{fp}.json")
      try
        val = require(fp)
      catch err
        throw new Error "Error loading file at #{fp}: #{err}"
    val

  # clever.db[resource] are arrays of resources
  clever.db =
    districts: trequire("#{data_dir}/districts")
    districtproperties: trequire("#{data_dir}/districtproperties")
