Comments (7)
Remove NEO_
prefix form the DB registration, so that it looks like:
DATABASE_TYPE=NEO4J
DATABASE_USER=neo4j
DATABASE_PASSWORD=neo4j
DATABASE_HOST=localhost
DATABASE_PORT=7687
This is required to make @InjectPersistenceManager(undefined/null)
to work. With the .env as is, it would be necessary to have @InjectPersistenceManager('NEO')
If this fixes the issue, let us know, so that it can be closed.
Explanation
In Drivine you can have one database defined as the default
and this is the one that will be provided when using @InjectPersistenceManager()
with no arguments. There can be additional named databases to use with @InjectPersistenceManger('name'). When loading from
.env` files the name is the prefix part.
Interesting Points
- It is also possible to register databases on the fly, at runtime, using
DatabaseRegistry
. - Once there are additional databases, we can have transactions spanning multiple DBs. (Though these are not true XA transactions - discussion for another day).
from drivine-inspiration.
Potentially related to this issue liberation-data/drivine#47
from drivine-inspiration.
Experiencing the same problem.
app.module.ts
imports: [
DrivineModule.withOptions(<DrivineModuleOptions>{
connectionProviders: [DatabaseRegistry.buildOrResolveFromEnv('NEO')],
}),
IngredientModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
ingredient.module.ts
import { Module } from '@nestjs/common';
import { IngredientService } from './ingredient.service';
import { IngredientRepository } from './ingredient.repository';
@Module({
providers: [IngredientService, IngredientRepository],
exports: [IngredientService],
})
export class IngredientModule {}
ingredient.repository.ts
import { Injectable } from '@nestjs/common';
import {
InjectPersistenceManager,
PersistenceManager,
QuerySpecification,
} from '@liberation-data/drivine';
import { CreateIngredientDto, Ingredient } from './model/ingredient';
@Injectable()
export class IngredientRepository {
constructor(
@InjectPersistenceManager() readonly persistenceManager: PersistenceManager,
) {}
public async create(dto: CreateIngredientDto): Promise<Ingredient> {
return this.persistenceManager.getOne<Ingredient>(
new QuerySpecification<Ingredient>(
'CREATE (i:INGREDIENT {id:apoc.create.uuid(), name: $name}) RETURN i',
)
.bind([dto.name])
.transform(Ingredient),
);
}
}
from drivine-inspiration.
All ok @ElePhontitis ? Can I close the issue?
from drivine-inspiration.
@jasperblues as I did not open it, I didn't feel entitled to determine that, but you have an ok from my side. Thanks a lot for your quick response!
from drivine-inspiration.
Oops, sorry! I didn't realize that there were two people having the same issue.
Let's wait for @jdelibas to confirm that the issue is solved for him too. I'm going to have to improve the docs.
from drivine-inspiration.
I had the same problem, but I followed the steps informed and everything went well
env file
NEO_DATABASE_TYPE=NEO4J
NEO_DATABASE_USER=neo4j
NEO_DATABASE_PASSWORD=secure_password
NEO_DATABASE_HOST=localhost
NEO_DATABASE_PORT=7687
Main module
@Module({
imports: [
DrivineModule.withOptions(<DrivineModuleOptions>{
connectionProviders: [DatabaseRegistry.buildOrResolveFromEnv('NEO')],
}),
UserModule,
TaskModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
User module context
@Module({
imports: [],
controllers: [UserController],
providers: [UserRepository, UserService],
exports: [],
})
export class UserModule {}
Repository
@Injectable()
export class UserRepository {
constructor(
@InjectPersistenceManager('NEO')
readonly persistenceManager: PersistenceManager,
) {}
async save(user: User): Promise<void> {
await this.persistenceManager.execute(
new QuerySpecification(
`MERGE (u:User {ID: "${user.ID}", name: "${user.name}"} )`,
),
);
}
}
All running perfectly. I Think can close this issue
Full example follow Github repository
from drivine-inspiration.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drivine-inspiration.