Connect your application to a native graph database.
Neo4j connector with Cypher-query-builder for Nest.
$ npm i --save nestjs-cypher-query-builder cypher-query-builder
Just two methods are supported now:
-
.forRoot(options)
where
options
istype Neo4jOptions = { scheme: "neo4j" | "neo4j+s" | "neo4j+scc" | "bolt" | "bolt+s" | "bolt+scc"; host: string; port: number | string; username: string; password: string; database?: string; };
-
.forRootAsync(asyncOptions)
where
asyncOptions
istype Neo4jAsyncOptions = { imports: NestImport[], useFactory: async (...yourInjectedServices): Promise<Neo4jOptions> {}, injects?: [...yourInjectedServices] }
Add Neo4jModule for your app.module.ts
file as:
Sync
import { Neo4jModule } from 'nestjs-cypher-query-builder';
@Module({
imports:[
// ...
Neo4jModule.forRoot({
scheme: 'neo4j',
host: 'localhost',
port: 7687,
username: 'neo4j',
password: 'neo4j',
})
// ...
],
//...
Async
import { Neo4jModule } from 'nestjs-cypher-query-builder';
@Module({
imports:[
// ...
Neo4jModule.forRootAsync({
imports: [ConfigsModule],
useFactory: async (opt: any): Promise<any> => {
console.log(3, opt);
return params
},
inject: [ DbConfigService ]
})
In your service you might use it now:
import { NEO4J } from 'neo4j-cypher-query-builder';
import { Connection, node } from 'cypher-query-builder';
// ...
@Injectable() / @Controller()
class YourService/YourController
constructor(
// Here you might inject it
@Inject(NEO4J) private readonly neo4jConnection: Connection
) {}
// ...
// you might use cypher-query-builder functionality all the time now
public async someFunc(...args: any[]): Promise<any> {
return this.neo4jConnection
.match([node('n', 'Movie')])
.return('n')
.limit(25)
.run()
}
Nest is MIT licensed.