Giter Site home page Giter Site logo

Comments (20)

jasperblues avatar jasperblues commented on June 6, 2024

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.

grizzly-monkey avatar grizzly-monkey commented on June 6, 2024

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.

jasperblues avatar jasperblues commented on June 6, 2024

I could do it when time permits, however have you thought about using NestJS from Lambda?

https://github.com/rdlabo/serverless-nestjs

from drivine.

grizzly-monkey avatar grizzly-monkey commented on June 6, 2024

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.

grizzly-monkey avatar grizzly-monkey commented on June 6, 2024

@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

  1. the class-transformer is not able to map the values returns me always a null object.

Screenshot 2020-05-05 at 1 26 06 AM

Screenshot 2020-05-05 at 12 14 58 AM

rec.txt

  1. 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.

jasperblues avatar jasperblues commented on June 6, 2024

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.

grizzly-monkey avatar grizzly-monkey commented on June 6, 2024

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.

jasperblues avatar jasperblues commented on June 6, 2024

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.

grizzly-monkey avatar grizzly-monkey commented on June 6, 2024

ok while i figure out the way for this in AWS ... can you help me with the data to class issue ?

from drivine.

jasperblues avatar jasperblues commented on June 6, 2024

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.

grizzly-monkey avatar grizzly-monkey commented on June 6, 2024

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.

jasperblues avatar jasperblues commented on June 6, 2024

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.

grizzly-monkey avatar grizzly-monkey commented on June 6, 2024

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.

jasperblues avatar jasperblues commented on June 6, 2024

You should not need to change that.

from drivine.

grizzly-monkey avatar grizzly-monkey commented on June 6, 2024

What do you suggest how should we fix it ?

from drivine.

jasperblues avatar jasperblues commented on June 6, 2024

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.

grizzly-monkey avatar grizzly-monkey commented on June 6, 2024

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.

jasperblues avatar jasperblues commented on June 6, 2024

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.

grizzly-monkey avatar grizzly-monkey commented on June 6, 2024

Hey @jasperblues thanks , I will try this and let you ASAP.

from drivine.

jasperblues avatar jasperblues commented on June 6, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.