Star

Created With
You are viewing the documentation for Neogma v1. This version is in maintenance mode, and you can upgrade to v2 following the migration guide. For the latest features and improvements, see the Neogma v2 documentation.

linkGetting Started

linkInstalling

1link$npm i neogma

1link$yarn add neogma

1link$pnpm i neogma

linkImporting

The used classes and functions can be imported as follows:

1linkimport { BindParam, ModelFactory, Neogma, QueryBuilder, QueryRunner, Where, Literal, getSession, Op, neo4jDriver } from 'neogma';

2link// importing types

3linkimport {

4link /* --> used in Model definition */

5link ModelRelatedNodesI,

6link NeogmaInstance,

7link /* --> all possible neo4j types which can be used in Models */

8link Neo4jSupportedTypes

9link} from 'neogma';

1linkconst { BindParam, ModelFactory, Neogma, QueryBuilder, QueryRunner, Where, Literal, getSession, Op, neo4jDriver } = require('neogma');

The neo4jDriver exports everything from the neo4j-driver package, including types, validators, etc:

1link/* --> validator */

2linkneo4jDriver.Date();

3link/* --> type constructor */

4linkneo4jDriver.types.DateTime();

5link/* --> typescript interface */

6linkneo4jDriver.Point;

linkInitializing

To get started, a Neogma instance needs to be initialized

1linkconst neogma = new Neogma(

2link {

3link url: 'bolt://localhost:7687',

4link username: 'neo4j',

5link password: 'password',

6link /* --> (optional) the database to be used by default for sessions */

7link database: 'myDb',

8link },

9link {

10link /* --> (optional) logs every query that Neogma runs, using the given function */

11link logger: console.log,

12link /* --> any driver configuration can be used */

13link encrypted: true,

14link }

15link);

This instance must be used when defining Models.

linkVerify connectivity

You can run

1linkawait neogma.verifyConnectivity();

If there is a connectivity error in either the neogma initialization, or with verifyConnectivity, a NeogmaConnectivityError error will be thrown.

linkUtilities

It also has the neo4j Driver and a QueryRunner instance. For more information about how to run your own queries and other non-model operations, refer to its documentation.

1link/* --> gets the neo4j driver */

2linkconst driver = neogma.driver;

3link/* --> gets the QueryRunner instance used by this neogma instance */

4linkconst queryRunner = neogma.queryRunner;

5link/* --> wrapper for getSession */

6linkconst getSession = neogma.getSession; // @see [Sessions](./Sessions)

7link/* --> the defined Models by their names */

8linkconst modelsByName = neogma.modelsByName; // @see [Defining a Model](./Models/Defining-a-Model)

Getting StartedInstallingImportingInitializingVerify connectivityUtilities

Introduction Getting Started

Modelschevron_right

Sessions and Transactions

Query Builderchevron_right
Query Runnerchevron_right

Bind Parameters

Where Parameters