Comments (20)
Don't necessarily need NestJS, however:
- As yet there isn't an example of using without NestJS.
- Some features are NestJS specific.
- Dependencies haven't been split into separate npms - at the moment, the main one will pull in NestJS, at the moment, even if it is not used.
from drivine.
Thanks @jasperblues ... do you plan to package deps accordingly in near future ? I am trying one to build for aws hope it works out . :)
from drivine.
I could do it when time permits, however have you thought about using NestJS from Lambda?
https://github.com/rdlabo/serverless-nestjs
from drivine.
I read that however i feel its an over head.. most of the things are taken care by API Gw.. and the package size gets added.
from drivine.
@jasperblues I am trying to get the Drivine running in aws lambda without nestjs.
For that have using a global function like this.
I am not so good with node world and learning as I age... so forgive for my grave mistakes in case.
return inDrivineContext().run(async () => {
DbRegistry.buildOrResolveFromEnv();
});
}
export class BomRepositoryImpl implements BomRepository {
private logger = getLogger(BomRepositoryImpl.name);
private persistenceManager: PersistenceManager;
constructor() {
this.persistenceManager = new TransactionalPersistenceManager(TransactionContextHolder.getInstance(),
ServiceConfig.db.name);
}
@Transactional()
async getAllBoms(id: string): Promise<Tenant> {
this.logger.debug(`Start getting bom ${id}`);
const spec = new QuerySpecification<Tenant>()
.withStatement(
`MATCH (Tenant{_id:$1}) return Tenant`
)
.bind([id])
.transform(Tenant);
return this.persistenceManager.getOne(spec);
}
}
This has 2 issues which i am not able to solve
- the class-transformer is not able to map the values returns me always a null object.
- When i re-run the api i get below error
Error: No context available. ns.run() or ns.bind() must be called first.
at Namespace.set (/opt/glabbr/code/infniti/ms/bom-service-node/node_modules/cls-hooked/context.js:36:11)
at o.set (/opt/glabbr/code/infniti/ms/bom-service-node/.webpack/service/src/api/webpack:/src/db/transaction/TransactonContextHolder.ts:66:24)
at o.currentTransaction (/opt/glabbr/code/infniti/ms/bom-service-node/.webpack/service/src/api/webpack:/src/db/transaction/TransactonContextHolder.ts:50:14)
at new u (/opt/glabbr/code/infniti/ms/bom-service-node/.webpack/service/src/api/webpack:/src/db/transaction/Transaction.ts:28:28)
at runInTransaction (/opt/glabbr/code/infniti/ms/bom-service-node/.webpack/service/src/api/webpack:/src/db/transaction/Transactional.ts:35:61)
at n.getAllBoms (/opt/glabbr/code/infniti/ms/bom-service-node/.webpack/service/src/api/webpack:/src/db/transaction/Transactional.ts:15:20)
at c.getAllBoms (/opt/glabbr/code/infniti/ms/bom-service-node/.webpack/service/src/api/webpack:/src/service/bom-service-impl.ts:12:19)
at e.getBOM (/opt/glabbr/code/infniti/ms/bom-service-node/.webpack/service/src/api/webpack:/src/api/get-bom.ts:47:35)```
from drivine.
Let's solve the 2nd problem first. Transactions need to be called in a Drivine context. You can do this manually or set up a middleware. Here's the NestJS middleware:
@Injectable()
export class TransactionContextMiddleware implements NestMiddleware {
constructor(readonly transactionContext: TransactionContextHolder, readonly databaseRegistry: DatabaseRegistry) {}
async use(req: express.Request, res: express.Response, next: express.NextFunction): Promise<any> {
return inDrivineContext().run(async () => {
this.transactionContext.databaseRegistry = this.databaseRegistry;
return Promise.resolve(next());
});
}
}
from drivine.
Let's solve the 2nd problem first. Transactions need to be called in a Drivine context. You can do this manually or set up a middleware. Here's the NestJS middleware:
@Injectable() export class TransactionContextMiddleware implements NestMiddleware { constructor(readonly transactionContext: TransactionContextHolder, readonly databaseRegistry: DatabaseRegistry) {} async use(req: express.Request, res: express.Response, next: express.NextFunction): Promise<any> { return inDrivineContext().run(async () => { this.transactionContext.databaseRegistry = this.databaseRegistry; return Promise.resolve(next()); }); } }
Yes if this is what I did in first stamement.
inDrivineContext().run(async () => {
DbRegistry.buildOrResolveFromEnv();
});
this works for me but only once next time i hit the api again. it gives me the error.
from drivine.
You run your queries in context, not the setting up of drivine.
The middleware above means that any endpoint invocation is already in context.
Need to set up the equivalent for AWS.
from drivine.
ok while i figure out the way for this in AWS ... can you help me with the data to class issue ?
from drivine.
What happens when you use NonTransactionalPersistenceManager
? Can you log the output without a mapper? Let's see if it is something compatible for mapping.
from drivine.
No luck with NonTxPresistMgr
output of query before mapQueryResult
[
{
"keys":[
"Tenant"
],
"length":1,
"_fields":[
{
"identity":{
"low":0,
"high":0
},
"labels":[
"Tenant"
],
"properties":{
"_id":"amZXSkaZsX",
"usr":"amZXSkaZsX",
"passwd":"amZXSkaZsX",
"uri":"neo4j://localhost:7687",
"dbName":"bom-service-WTGVmpb",
"ownerEmail":"[email protected]"
}
}
],
"_fieldLookup":{
"Tenant":0
}
}
]
Output for const results = this.mapToNative(records); before
plainToClass(spec.transformType, results);
[
{
"Tenant":{
"_id":"amZXSkaZsX",
"usr":"amZXSkaZsX",
"passwd":"amZXSkaZsX",
"uri":"neo4j://localhost:7687",
"dbName":"bom-service-WTGVmpb",
"ownerEmail":"[email protected]"
}
}
]
I think the this.mapToNative(records) should return only
[
{
"_id":"amZXSkaZsX",
"usr":"amZXSkaZsX",
"passwd":"amZXSkaZsX",
"uri":"neo4j://localhost:7687",
"dbName":"bom-service-WTGVmpb",
"ownerEmail":"[email protected]"
}
]
My Tenant class
export class Tenant {
_id: string;
usr: string;
passwd: string;
uri: string;
dbName: string;
ownerEmail: string;
}
from drivine.
If it was me I would call JSON.strinfigy on the result, and then create a unit test that class plainToClass on that - to debug the mapping.
from drivine.
Yes that what i did called JSON.strinfigy on result, i could understand that in current code you are mapping all the properties against the lable/key due to which the plainToClass is not working.
When i removed the key it started working.
I was trying to run the test cases however they are not working on my laptop not sure why. the change i made was
const item = {};
for (let j = 0; j < record.keys.length; j++) {
const key = record.keys[j];
item[key] = toNative(record.get(j));
}
data[i] = item;
to
let item = {};
for (let j = 0; j < record.keys.length; j++) {
// const key = record.keys[j];
// @ts-ignore
item = toNative(record.get(j));
}
data[i] = item;
from drivine.
You should not need to change that.
from drivine.
What do you suggest how should we fix it ?
from drivine.
Seems like there are two issues:
- New to learning how Drivine works.
- Converting to AWS Lambda, despite there being no sample/howto for this yet.
Are you able to submit a failing test case using standard drivine (with NestJS) ? Or if it works on standard setup, it is clear the problem is in the AWS assembly.
from drivine.
I feel the query is not working which i have shown below is a simple query.
Not sure if it changes something specific to AWS / Nest.
const spec = new QuerySpecification<Tenant>()
.withStatement(
`MATCH (Tenant{_id:$1}) return Tenant`
)
.bind([id])
.transform(Tenant);
from drivine.
Can you try:
MATCH (t:Tenant{_id:$1}) with t return {
t.firstPropertyOfInterest,
t.secondProp,
t.anotherProp
}
I forgot to mention that with drivine's performance goals, we pluck what we like from the results.
(I also forgot that it works like this, as I was working on something completely different for 10+ weeks)
from drivine.
Hey @jasperblues thanks , I will try this and let you ASAP.
from drivine.
It will surely work. Sorry that this wasn't obvious to me earlier (it should have been) - I got a bit sidetracked in that we were also converting for NestJS-less and Lambda.
We can also easily support mapping without having to push the results into a JS object compatible structure in the query. Just will require a few considerations.
from drivine.
Related Issues (20)
- Migrating to agens-graph on my my nestjs app HOT 5
- TransactionContextMiddleware seems unnecessary HOT 5
- Error: variable does not exist - Apache AGE HOT 5
- Website is down HOT 1
- Could not perform discovery errors HOT 14
- drivine.org a sign of status? HOT 5
- Broken link for the user guide HOT 1
- Calling `RunWithDrivine()` when using `it.each` in a test file causes `TypeError: it.each is not a function` HOT 7
- Neo4j connections are not properly released when using @Transactional and concurrency HOT 11
- Transactional persistence manager is used when no @Transactional decorator is set when running concurrent queries HOT 11
- Domain drivine.org leads to 404 page HOT 2
- Mismatch between npm package licence and licens on github HOT 1
- Error: SRID expected to be either a number or an Integer object but was: undefined HOT 6
- @nestjs/common@">= 6 <= 7" from @liberation-data/[email protected] HOT 2
- Upgrade nanoid dependency version to solve moderate vulnerability
- Use Transactions in Tests HOT 3
- [Question] Possible to initialize with configuration (or any other injected service) and how are environment variables parsed? HOT 5
- [Bug] @InjectPersistenceManager not resolved as dependency when other @Inject parameters are present HOT 10
- [Docs] Show examples of unit testing with Drivine HOT 13
- [Docs] [Bug] The documentation site does not have a side menu HOT 1
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.