Search code examples
node.jstypescriptneo4jgraph-databasesdrivine

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


I'm using Drivine, with Neo4j. The example shows how to inject a query stored in a separate file. How can I simply inline a query as a string?


Solution

  • The idea behind having a separate file is so that queries can be profiled, tested and have a life-cyle in their own right. You don't have to use this if it doesn't suit you.

    The example also shows how to create inline queries:

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

    For simple queries that don't need to be profiled or heavily tested, inline is easier.