Skip to content

Quick Start

Connections come from the environment, or a .env file that Drivine loads. The default database is configured with DATABASE_*, and a named one with <NAME>_DATABASE_*:

Terminal window
DATABASE_TYPE=NEO4J # NEO4J, MEMGRAPH, FALKORDB, ORACLE, NEPTUNE or POSTGRES
DATABASE_HOST=localhost
DATABASE_PORT=7687
DATABASE_USER=neo4j
DATABASE_PASSWORD=password
DATABASE_NAME=neo4j # optional on the graph engines; on Oracle, the service, e.g. FREEPDB1
DATABASE_POOL_MAX=40
DATABASE_CONNECTION_TIMEOUT=5000

Then register the connections with the module:

@Module({
imports: [
DrivineModule.withOptions({
connectionProviders: [DatabaseRegistry.buildOrResolveFromEnv()]
})
],
providers: [PersonRepository]
})
export class AppModule {}
@Injectable()
export class RouteRepository {
constructor(
@InjectPersistenceManager() readonly persistenceManager: PersistenceManager,
@InjectCypher(__dirname, 'routesBetween') readonly routesBetween: CypherStatement
) {}
@Transactional() // Propagation.REQUIRED by default: join the current transaction, or start one.
async findFastestBetween(start: string, destination: string): Promise<Route> {
return this.persistenceManager.getOne(
new QuerySpecification<Route>()
.withStatement(this.routesBetween)
.bind([start, destination])
.limit(1)
.transform(Route)
);
}
}

Or, with the object manager, declare what you want and let Drivine write the statement:

@Injectable()
export class PersonService {
constructor(@InjectGraphObjectManager() readonly gom: StatelessGraphObjectManager) {}
async leads(): Promise<PersonCareer[]> {
return this.gom.loadAll(PersonCareer, (q) => ({ where: q.person.bio.contains('Lead') }));
}
}

When you write a statement yourself, return a single map or a scalar, not several columns. That maps cleanly with .transform() and avoids trouble with nulls:

-- Wrong: several columns, awkward to map
RETURN a.name, a.age, b.title
-- Right: one map
RETURN { name: a.name, age: a.age, title: b.title } AS result
-- Right: a node's properties, or a scalar
RETURN properties(p)
RETURN count(p) AS total