最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何使用 Nodejs 客户端获取 TypeDB 中实体的值?

网站源码admin43浏览0评论

如何使用 Nodejs 客户端获取 TypeDB 中实体的值?

如何使用 Nodejs 客户端获取 TypeDB 中实体的值?

我尝试在 nodejs 客户端中获取实体属性的实际值,但我只获取字符串 ID。我尝试了许多不同版本的 .getValue() 或 asAttribute 或 getAttribute,但只收到错误消息。如何检索属性的实际值?

这是我的代码

export async function getMarketByTitle(title: string) {
  const database = "know_graph"; // Replace this with the name of your TypeDB database
  const { client, session, transaction } = await openTransaction(database);

  try {
    const query = `
      match
      $m isa market, has title "${title}", has background_information $background_information;
      $m has title $m_title;
      get $m, $m_title, $background_information;
    `;

    const iterator = await transaction.query.match(query);
    let market;
    for await (const answer of iterator) {
      const mConcept = answer.get("m");
      const mTitle = answer.get("m_title");
      const backgroundInformation = answer.get("background_information");
      const checkEntity = mConcept.isEntity();
      const checkAttribute = mTitle.isAttribute();

      market = {
        id: mConcept.toString(),
        title: msTitle.toString(),
        backgroundInformation: backgroundInformation.toString(),
        entity: checkEntity.toString(),
        attribute: checkAttribute.toString
      };

      return market;
    }```
回答如下:

我相信你应该像这样使用

.map
.value

      const mTitle = answer.map.get("m_title").value;
      const backgroundInformation = answer.map.get("background_information").value;

根据https://docs.vaticle/docs/concept-api/thing#retrieve-value-(local)(确保在该页面上将语法切换为javascript)。

发布评论

评论列表(0)

  1. 暂无评论