使用jsstore处理来自GET请求的大数据时遇到问题。因此,对于初学者来说,我收到的数组超过9000+ json,我需要将它们存储在jsstore中以保持持久性(以避免对大型数据进行多次GET请求)。在这样做时,我遇到了一个问题,那就是无法及时解决。
这位于我的authService中
async getData() {
this.loadToken();
const headers = new HttpHeaders({
'Content-type': 'application/json',
'Authorization': 'Bearer ' + this.authToken
});
const data = this.http.get(this.ROUTE, {headers: headers})
.pipe(map(res => res));
return await data.subscribe((vals: any) => {
return this.storeDataInDB(vals.data);
}, err => {
console.log(err);
return false;
});
}
async storeDataInDB(data) {
return await this.DBService.storeData(data);
}
这在我的DBService中
async insert(data: any) {
return await this.connection.insert({
into: this.tableName,
return: false,
values: data
}).then(function(rowsInserted) {
if (rowsInserted > 0) {
console.log('Successfully added all records!');
}
}).catch(function(err) {
console.log(err);
});
}
这是我从jsstore收到的错误。我知道这是由于我之前遇到过类似的问题而无法及时解决。
消息:“列'unit_number'不允许为空值” 类型:“ null_value”
我已经尝试了很多事情,我不知道该怎么办。
答案 0 :(得分:0)
我建议尽快将诺言转换为可观察的。混合搭配可能会造成混淆。我认为数据的大小无关紧要,除非您遇到某种超时?
也许试试看: DBService
insert(data: any) {
return fromPromise(this.connection.insert({
into: this.tableName,
return: false,
values: data
}));
}
authService
getData() {
this.loadToken();
const headers = new HttpHeaders({
'Content-type': 'application/json',
'Authorization': 'Bearer ' + this.authToken
});
this.http.get(this.ROUTE, {headers: headers})
.pipe(
tap(vals => console.log(vals)),
switchMap(vals => this.DBService.storeData(vals.data)),
tap(rowsInserted => console.log(rowsInserted)),
).subscribe(rowsInserted => console.log(rowsInserted), err => console.log(err));
}
答案 1 :(得分:0)
错误消息-{消息:“'unit_number'列不允许使用空值””类型:““ null_value””}的意思是-列unit_number的数据中存在空值,并且您已在数据库模式中添加notNull。
如果您要跳过数据检查以插入数据,则可以对您的插入查询使用skipDataCheck,例如api或{{1}
bulkInsert
有关更多信息,请查看插入api-http://jsstore.net/tutorial/insert/。