     isSubjOf: ->
     defines: ->
     isObjOf: ->
+
+    addMethod: (name, code, compiler) ->
+      @methods[name] = compiler(code).bind this
+      @methods[name].code = code
+      @methods[name].compiler = compiler
 
   class Relation extends Euclidic
     constructor: ({@subj, @rel, @obj, @params}) ->

      @isSubjOf = @isObjOf = @defines = {}
      @util.initContexts this
      @ctx.engine.name = name

    name: -> @ctx.engine.name


    toString: ->
      "#{@subj.name} #{@name} #{@obj.name}"

  class Context extends Euclidic
    constructor: ({name}) ->
      super arguments[0]



  class Db
    constructor: (@namespace, @prefix = '$') ->
      @names = {}
      @o = {}
      @relationships = {}
      @contexts = {}

      @create 'sys'
      @create 'root'
      @create name: 'context', klass: Context
        .spawn 'engine'
        .spawn 'core'
      @create name: 'relation', klass: Relation

    addContext: ->
      @names.context.spawn arguments[0]

    relate: (subj, rel, obj) ->
      @names.relation.spawn
        subj: subj
        rel: rel
        obj: obj

    create: ({name, klass = Euclidic}) ->
      name or= arguments[0]
