         #TODO
 
 class KeyValueStore
-    #   c = new (require("cassandra").Salvus)(); d = c.key_value_store('test')
-    #   d.set(key:[1,2], value:[465, {abc:123, xyz:[1,2]}], ttl:5)
-    #   d.get(key:[1,2], console.log)   # but call it again in > 5 seconds and get nothing...
-    constructor: (opts={}) ->
+    constructor: (@db, opts={}) ->
         @opts = defaults(opts, name:required)
-        # TODO
+        @table = @db.table("key_value")
 
     set: (opts={}) =>
         opts = defaults opts,
+            key         : required
+            value       : required
+            cb          : undefined
+        # TODO: make a composite index so this stays fast
+        @table.filter(name:@opts.name, key:opts.key).run (err, r) =>
+            if err
+                cb(err); return
+            if r.length == 0
+                @table.insert({name: @opts.name, key:opts.key, value:opts.value}).run((err)=>opts.cb?(err))
+            else
+                @table.update({id:r[0].id, name: @opts.name, key:opts.key, value:opts.value}).run((err)=>opts.cb?(err))
+
+    get: (opts={}) =>
+        opts = defaults opts,
             key         : undefined
-            value       : undefined
-            ttl         : 0
-            cb          : undefined
-        # TODO
-
-    get: (opts={}) =>
-        opts = defaults opts,
-            key         : undefined
-            timestamp   : false      # if specified, result is {value:the_value, timestamp:the_timestamp} instead of just value.
-            cb          : undefined  # cb(error, value)
-        # TODO
+            cb          : required   # cb(error, value)
+        # TODO: make a composite index so this stays fast
+        @table.filter(name:@opts.name, key:opts.key).run (err, r) =>
+            if err
+                opts.cb(err)
+            else
+                opts.cb(undefined, r[0]?.value)
 
     delete: (opts={}) ->
         opts = defaults(opts, key:undefined, cb:undefined)


TABLES = misc.split(TABLES)


PROJECT_COLUMNS = exports.PROJECT_COLUMNS = ['project_id', 'account_id', 'title', 'last_edited', 'description', 'public', 'bup_location', 'size', 'deleted', 'hide_from_accounts'].concat(PROJECT_GROUPS)


        ], (err) => cb?(err))

    key_value_store: (opts={}) => # key_value_store(name:"the name")
        new KeyValueStore(@db, opts)

    uuid_value_store: (opts={}) => # uuid_value_store(name:"the name")
        new UUIDValueStore(@, opts)
