-TABLES = 'accounts  central_log'
+TABLES = 'accounts  central_log key_value'
 
 winston = require('winston')
 winston.remove(winston.transports.Console)

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

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

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

        #TODO

class KeyValueStore
    constructor: (@db, opts={}) ->
        @opts = defaults(opts, name:required)
        @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
            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)
