Skip to content

woolfi182/nestjs-cypher-query-builder

Repository files navigation

Nest Logo andNeo4j Logo

Connect your application to a native graph database.

NPM Version Package License NPM Downloads Travis Linux Coverage Discord Backers on Open Collective Sponsors on Open Collective

Description

Neo4j connector with Cypher-query-builder for Nest.

Installation

$ npm i --save nestjs-cypher-query-builder cypher-query-builder

Quick Start

Just two methods are supported now:

  • .forRoot(options)

    where options is

    type 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 is

    type 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()
  }

License

Nest is MIT licensed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published