使用 Drivine 和 Neo4j,如何将查询内联为字符串,而不是注入单独的文件

Using Drivine and Neo4j, how can inline a query as a string, rather than injecting a separate file

我在 Drivine 中使用 Neo4j。该示例显示了如何注入存储在单独文件中的查询。我怎样才能简单地将查询内联为字符串?

拥有一个单独的文件背后的想法是,查询可以被分析、测试并拥有自己的生命周期。如果它不适合你,你不必使用它。

example 还展示了如何创建内联查询:

async countAllVertices(): Promise<number> {
    const results = await this.persistenceManager.query<any>(
        new QuerySpecification(`match (n) return count(n) as count`)
    );

    return results[0].count;
}

对于不需要分析或大量测试的简单查询,内联更容易。