Overview Defining a Model Instances Creating Nodes and Relationships Merging Nodes and Relationships Updating Nodes and Relationships Deleting Nodes Deleting Relationships Finding Nodes and Relationships Hooks Temporary Databases
1link$npm i neogma
1link$yarn add neogma
The used classes and functions can be imported as follows:
1linkconst { BindParam, ModelFactory, Neogma, QueryBuilder, QueryRunner, Where, Literal, getSession, Op, neo4jDriver } = require('neogma');
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';
The neo4jDriver
exports everything from the neo4j-driver
package, including types, validators, etc:
1link/* --> validator */
2linkneo4jDriver.Date();
3link/* --> type contructor */
4linkneo4jDriver.types.DateTime();
5link/* --> typescript interface */
6linkneo4jDriver.Point;
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.
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.
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)