Azure Mobile Client, how to do a bulk insert in Angular 4? - performance

I am current using the js library:
<script src="//zumo.blob.core.windows.net/sdk/azure-mobile-apps-client.2.0.0.js"></script>
And I am currently trying to do a bulk insert instead of foreach. Is there any method call, that I can use?
addSubjectSpecialization(specialization): Promise<any>{
var orderTable = this.client.getTable("specialization");
return new Promise((resolve, reject) => {
orderTable.insert(specialization).then((res) => {
resolve(res);
}, (err) => reject(err))
})
}
In my component I am doing a foreach, to insert multiple objects. Is there any better way? That means: Instead of foreach, do we have a function for bulk insert?
Ref: https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-html-how-to-use-client-library#inserting
Note: I have seen the suggestions provided by Stackoverflow. And none solves the issue. The suggestions where MobileClient(.Net) has tableStorage bulk insert. And I am not sure how can I do it in typescript.

Currently, there is no function we can use for bulk insert. But you may post a feature request on this Github repository.

Related

Nest js promise interceptor

Is there a way for me to wrap a request in nest js inside a callback?
I'm trying to create a prisma transaction interceptor but the problem is that nest js interceptor requires an obserable as return type.
In order to achieve my goal I need to wrap my request in a callback like:
await prisma.$transaction(async p => {
await requestToBeFinished()
})
But all nest js provides me is an observable like
return next
.handle()
.pipe(
tap(() => {console.log('After execution')}),
);
Is there a solution to this?
Thanks

How to use data returned from the asyncValidate function in react and redux?

I have created a form that is being validated using data from serve. If successful that validating function returns some data from server.
My Question is: How can I use those data from server!? More specific, how can I store them in redux store!?
Yes!
I've got the solution that is, The validation functions may also pass store dispatch function, that may be used to dispatch action and the data to the reducer so as to update the state!!
const asyncValidate = (values, dispatch) =>
{
axios(...).then(res => dispatch({type:'UPDATE_STATE', payload: res}))
}
thanks for all who viewed this question. Regards!!

How to delete all objects of Class in Parse Server?

I want to delete all object of my class with jobs. I have created my job and I wrote below code to achieve my goal but my code did not work.
Parse.Cloud.job("deleteWeeklyScore", (request) => {
const mySchema = new Parse.Schema('WeeklyGameScore');
mySchema.purge();
});
I can delete field from my schema but delete all objects does not work
purge() returns a promise. You have to resolve your promise.
schema.purge().then(...) or await schema.purge() or return schema.purge()
I don't know if Job resolves a promise.

Using the result of an AJAX call as an AMD module [duplicate]

This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Closed 5 years ago.
I'm using RequireJS while prototyping an application. I'm "faking" a real database by loading a json file via ajax.
I have several modules that need this json file, which I noticed results in multiple http requests. Since I'm already using RequireJS, I thought to myself "hey, why not load this json file as another module". Since a module can return an object, it seemed reasonable.
So I tried this:
// data.js
define(function(require){
const $ = require('jquery')
var data = {}
$.getJSON('/path/to/data.json', function(json_data){
data = json_data
})
// this does not work because getJSON is async
return data
})
// some_module.js
define(function(require){
const my_data = require('data')
console.log(data) // undefined, but want it to be an object
})
I understand why what I'm doing is not working. I'm not sure what the best way to actually do this would be though.
Things I don't want to do:
Change getJSON to async: false
add a while (data == null) {} before trying to return data
Is there an AMD-y want to accomplish what I'm trying to do? I'm sure there's a better approach here.
Edit
I just tried this. It works, but I'm not sure if this is a good or terrible idea:
// in data.js
return $.getJSON('/path/to/data.json')
// in some_module.js
const my_data = require('data')
my_data.then(function(){
console.log(my_data.responseText)
// do stuff with my_data.responseText
})
My concern is (1) browser support (this is a "promise", right?) and (2) if multiple modules do this at the same time, will it explode.
Because this question is specifically referring to using JQuery, you can actually do this without a native promise using JQuery's deferred.then().
// in data.js
return $.getJSON('/path/to/data.json')
// in some_module.js
const my_data = require('data') // this is a JQuery object
// using JQuery's .then(), not a promise
my_data.then(function(){
console.log(my_data.responseText)
// do stuff with my_data.responseText
})
Based on the description of then() in JQuery's docs, it looks like this is using a promise behind the scenes:
As of jQuery 1.8, the deferred.then() method returns a new promise that can filter the status and values of a deferred through a function, replacing the now-deprecated deferred.pipe() method. [...]
Callbacks are executed in the order they were added. Since deferred.then returns a Promise, other methods of the Promise object can be chained to this one, including additional .then() methods.
Since JQuery's .then() does work in IE, I guess they are polyfilling the promise for IE behind the scenes.

Cache all records from query in laravel 5

I'm trying to cache all records of the query for 60 minutes by the following method (Method 1)
Route::get('categoryList', function() {
return app\CategoryDetails::remember(60)->get();
});
I followed this tutorial link (Tip 5: Cache Database Queries)
But I'm getting this error:
Call to undefined method Illuminate\Database\Query\Builder::remember()
I don't know what I'm missing here.
BTW, I know I can cache entire records by the following method (Method 2):
Route::get('categoryList', function() {
$category = Cache::remember('category', 10, function() {
return \App\CategoryDetails::all();
});
return $category;
});
and this is working perfectly.
I am just curious why the first method is not working for me.
Laravel 5 removed this functionality. You now have to store the cache yourself:
Route::get('categoryList', function () {
return Cache::remember('category-details', 60, function () {
return App\CategoryDetails::all();
});
});
From the upgrade docs:
Eloquent no longer provides the remember method for caching queries. You now are responsible for caching your queries manually using the Cache::remember function.
Consider using a laravel eloquent query caching library called rememberable
It does a pretty good job.

Resources