MYSQL X DEV API Update method not working - node.js

I could not find a good template for the update method for the xdevapi library and thought maybe some one could help me out with getting this to work.
acts_table
.update()
.set('account_status', 'new account status')
.where('customer_number like :customer_number && original_account_number like :original_account_number')
.bind('01234588456')
.bind('12156464645')
.execute()
I think its just a formatting issue, but with no real examples in the XDEVAPI Documentation for update for Javascript I'm kind of at a lost. Please help. The error I get is Cannot Read property 'toArray' of undefined.

It was formatting, in the bind method I forgot to put the fields we were binding so the answer is this:
acts_table
.update()
.set('account_status', 'new account status')
.where('customer_number like :customer_number && original_account_number like :original_account_number')
.bind('customer_number','01234588456')
.bind('original_account_number', '12156464645')
.execute()

Related

dot notation and accessing module functions using strings

pretty new to python, so i tried googling around for answers but i was probably googling the wrong terminology.
So here's my problem
i have this
objectName ="Account"
sf.bulk.objectName.upsert(dataToSalesforce,externalIdField, batch_size=10000)
The above command should send an upsert request for salesforce upserting on the account object, but it gives me the error {'exceptionCode': 'InvalidJob', 'exceptionMessage': 'Unable to find object: objectName'}
the problem is it tried to query the object objectName and not Account.
Everything works fine when i use: sf.bulk.Account.upsert(dataToSalesforce,externalIdField, batch_size=10000) but in the current use case the object being upserted to may change.
When looking at errors i noticed it used the term attribute, and googling using that term i found i could do this
getattr(sf.bulk, objectName).upsert(dataToSalesforce, externalIdField,batch_size=10000, use_serial=True)
which solves the issue

Issue NestJS with oracle TypeORM

I'm trying to connect my NestJs Project with a Oracle db and I'm using TypeORM and the status of connection is ok but I don't know how I can connect with a function. This function is into of a package and at the same time this package is into of a schema. The structure is like:
mySchema:
--------->myPackage:
-------------------->myFunction(id)
In the NestJS code I'm define this import in the AppModule file:
When I try to use the entity I don't know what method can I use to connect with my function. With the ESLint I get the next methods:
I hope to be clear and thanks for all!
In you last picture you’re trying to make a request to the database and as you can see, when you mentioned the testRepository and dots(.) now you have to tell him what you want to do in your database and in the suggested list you have all the possible possibilities.
So if you want to get or fetch data from you database, you will use testRepository.find() this will give you everything in that particular entity. To do that, you have to do something like below, before that you code has something that I have never seen in Nest, (public); if it does exist but I won’t use that in my Example since I don’t know it in Nest and also; you have started writing without (return) I don’t know how you’re expecting to return what you will get from your database.
Here is my example:
in your controller:
#Get() AnyThing(): Promise<TestEntity[]> {return this.DaobscsService.whatEver(); }
And in your service:
#InjectRepository(TestEntity) private readonlytestRepository: Repository<TestEntity>, ) {}
async whatEver(): Promise<TestEntity[]> {return await this.testRepository.find();}
What ever name you gonna use instead (whatEver()) in the service that have used, remember to use the same name in your controller pointing to service (this.Boa...Service.(The name here) OOP system’s you know it I hope
This example is to get or fetch so if you don’t have any thing in your database then you will get nothing! if that’s not what u want then command with a full version of what exactly is your issue, what u expected and code from controller, service, and module.

DocumentDB Replace not Working

I recently realized that DocumentDB supports stand alone update operations via ReplaceDocumentAsync.
I've replaced the Upsert operation below with the Replace operation.
var result = _client
.UpsertDocumentAsync(_collectionUri, docObject)
.Result;
So this is now:
var result = _client
.ReplaceDocumentAsnyc(_collectionUri, docObject)
.Result;
However, now I get the exception:
Microsoft.Azure.Documents.BadRequestException : ResourceType Document is unexpected.
ActivityId: b1b2fd71-3029-4d0d-bd5d-87d8d0a2fc95
No idea why, upsert and replace are of the same vein and the object is the same that worked for upsert, so I would expect it to work without problems.
All help appreciated.
Thanks
Update: Have tried to implement this using the SelfLink approach, and it works for Replace, but selflink does not work with Upsert. The behavior is quite confusing. I don't like that I have to build a self link in code using string concatenation.
I'm afraid that building the selflink with string concatenation is your only option here because ReplaceDocument(...) requires a link to the document. You show a link to the collection in your example. It won't suck the id out and find the document as you might wish.
The NPM module, documentdb-utils, has library functions for building these links but it's just using string concatenation. I have seen an equivalent library for .NET but I can't remember where. Maybe it was in an Azure example or even in the SDK now.
You can build a document link for a replace using the UriFactory helper class:
var result = _client
.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseId, collectionId, docObject.Id), docObject)
.Result;
Unfortunately it's not very intuitive, as Larry has already pointed out, but a replace expects a document to already be there, while an upsert is what it says on the tin. Two different use-cases, I would say.
In order to update a document, you need to provide the Collection Uri. If you provide the Document Uri it returns the following:
ResourceType Document is unexpected.
Maybe the _collectionUri is a Document Uri, the assignment should look like this:
_collectionUri = UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName);

Understanding mongoose findOne().remove()

As you know, in mongoose, we can remove all users with age 30 like this:
User.find({age: 30}).remove(callback);
Now, replace find() with findOne(), and I think it should remove only 1 user:
User.findOne({age: 30}).remove(callback);
oh, not as I expected, the code above also remove ALL instead of ONE
So, why findOne().remove() remove ALL instead of ONE? Is that a bug or a feature and why?
Thanks in advance!
P/S: I know findOneAndRemove() would remove one user for me, but in this question I want to understand findOne().remove()
I have reported this question to mongoose team, and got a reply:
https://github.com/LearnBoost/mongoose/issues/1851#issuecomment-31355346
Here's the message from aheckmann
"that's a good catch. findOne just sets the command name to run, remove() changes it back to a rice command but no limit was ever set. We should probably change that in 3.9 so that findOne sets
the limit as well."
Both find and findOne returns mongoose Query objects which only contains information about the model and the specified query. It's not taking into account findOne which is applied first in the callback. What you expect to happen is to have options be set like this User.findOne({age: 30}, null, {limit: 1}).remove() as this would only remove one and you could argue that this is a bug, but that depends on the usage. Like you have already pointed out, the right way to go is to use findOneAndRemove().
I'm kind of a noob but wouldn't you need to put your remove in the callback because this is an asynchronous function? Try something like:
User.findOne({age: 30}, function(err, user){
user.remove()
})

does mongoose have an isDirty check?

I have a mongoose setup which involves an embedded-schema, lets say: A Blogpost with embedded comments. Comments can be edited by the original publisher as well as by an editor/admin. After adding / editing a comment the entire blogpost is saved.
I have some custom mongoose's 'pre' middleware set up on the embedded comment-schema which automatically sets the lasteditdate for that particular comment.
The thing is that 'pre' is called on EVERY comment on the blogpost, since I call save() on the blogpost. (For other reasons I need to do it like this) . Therefore, I need a way to check which comments have changed (or are new) since they were last saved (as part of the Blogpost overall save())
The questio: how to check in 'pre' whether a comment has changed or not? Obviously calling this.isNew isn't sufficient, since comments could be edited (i.e: aren't new) as well.
Is there any isDirty or similar that I'm overlooking?
For version 3.x
if(doc.isModified()){
// do stuff
}
In Mongoose you can use the Document method isModified(#STRING).
The most recent documentation for the method can be found here.
So to check a specific property with doc.isModified you can do this:
doc.comments[4].message = "Hi, I've made an edit to my post";
// inside pre hook
if ( this.isModified('comments') ) {
// do something
}
If you want to check a specific comment you can do that with the following notation this.isModified('comments.0.message')
Since the argument takes a string if you needed to know specifically which comment was modified you could loop through each comment and run this.isModified('comments['+i+']message')
You may use the modified getter:
if (doc.modified) {
// :)
}
This may be relevant to Mongoose users circa mid-2020 who are seeing this error:
"errorType": "TypeError",
"errorMessage": "Cannot set property 'isDirty' of null",
Upgrade to the latest version of Mongoose to fix it.
https://github.com/Automattic/mongoose/issues/8719

Resources