Quick Start
1. Configuration
Section titled “1. Configuration”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_*:
DATABASE_TYPE=NEO4J # NEO4J, MEMGRAPH, FALKORDB, ORACLE, NEPTUNE or POSTGRESDATABASE_HOST=localhostDATABASE_PORT=7687DATABASE_USER=neo4jDATABASE_PASSWORD=passwordDATABASE_NAME=neo4j # optional on the graph engines; on Oracle, the service, e.g. FREEPDB1DATABASE_POOL_MAX=40DATABASE_CONNECTION_TIMEOUT=5000Then register the connections with the module:
@Module({ imports: [ DrivineModule.withOptions({ connectionProviders: [DatabaseRegistry.buildOrResolveFromEnv()] }) ], providers: [PersonRepository]})export class AppModule {}2. A Repository
Section titled “2. A Repository”@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') })); }}Return One Map
Section titled “Return One Map”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 mapRETURN a.name, a.age, b.title
-- Right: one mapRETURN { name: a.name, age: a.age, title: b.title } AS result
-- Right: a node's properties, or a scalarRETURN properties(p)RETURN count(p) AS total
