     self.json = json
   }
 
-  init(_ id: Int64, jbl: SWJBL) throws {
+  init(_ id: Int64, swjbl: SWJBL) throws {
     self.id = id
-    self.json = try jbl.toString()
+    self.json = try swjbl.toString()
+  }
+
+  init(_ id: Int64, jbl: OpaquePointer) throws {
+    let xstr = iwxstr_new()
+    defer {
+      iwxstr_destroy(xstr)
+    }
+    try SWRC(jbl_as_json(jbl, jbl_xstr_json_printer, UnsafeMutableRawPointer(xstr), 0))
+    self.id = id
+    self.json = String(cString: iwxstr_ptr(xstr))
+  }
+
+  init(_ id: Int64, jbn: UnsafeMutablePointer<_JBL_NODE>) throws {
+    let xstr = iwxstr_new()
+    defer {
+      iwxstr_destroy(xstr)
+    }
+    try SWRC(jbl_node_as_json(jbn, jbl_xstr_json_printer, UnsafeMutableRawPointer(xstr), 0))
+    self.id = id
+    self.json = String(cString: iwxstr_ptr(xstr))
+  }
+
+  convenience init(_ doc: UnsafeMutablePointer<_EJDB_DOC>) throws {
+    let id = doc.pointee.id
+    if doc.pointee.node != nil {
+      try self.init(id, jbn: doc.pointee.node!)
+    } else {
+      try self.init(id, jbl: doc.pointee.raw!)
+    }
   }
 
   public let id: Int64

    return self
  }

  public func execute(_ visitor: (_ doc: JBDOC) -> Bool) throws {
    let _visitor:
      @convention(c) (
        _: UnsafeMutablePointer<_EJDB_EXEC>?,
        _: UnsafeMutablePointer<_EJDB_DOC>?,
        _: UnsafeMutablePointer<Int64>?
      ) -> iwrc = {
        let ux = $0!
        let doc = $1!
        let step = $2!



        // todo:

        return 0
      }
    var ux = _EJDB_EXEC(
      db: self.db.handle,
      q: self.handle,
      visitor: _visitor,
      opaque: nil,
      skip: _skip ?? 0,
      limit: _limit ?? 0,
      cnt: 0,
      log: nil,
      pool: nil
    )
    try SWRC(ejdb_exec(&ux))
  }
}


  public func get(_ collection: String, _ id: Int64) throws -> JBDOC {
    let jbl = SWJBL()
    try SWRC(ejdb_get(handle, collection, id, &jbl.handle))
    return try JBDOC(id, swjbl: jbl)
  }

  // https://github.com/belozierov/SwiftCoroutine

  public func close() throws {
    if handle != nil {
