Add ignore,validation #212
Replies: 2 comments 6 replies
-
Just gut stuck for a few hours trying to figure out why autoIncrement value was not getting set in the meta. Scenario: The schema of the table in question was: var tblDataTracker = {
name: 'DataTracker',
columns: {
Id:{ primaryKey: true, autoIncrement: true },
dataId: { notNull: false, dataType: JsStore.DATA_TYPE.Number },
totalUpdated: { notNull: false, dataType: JsStore.DATA_TYPE.Number, default: 0 },
isComplete: { notNull: false, dataType: JsStore.DATA_TYPE.Number, default: 0 },
startDate: { notNull: true, dataType: JsStore.DATA_TYPE.DateTime },
}
}; After clearing the table or using a new db, I was unable to import the data unless I use This is my import function: async function importFromJson(forceColumnMatching=false, forceUpsert=false){
importFormElement_Name = document.querySelector("#tblImportName");
importFormElement_File = document.querySelector("#tblImportFile");
tableName = importFormElement_Name.value;
importFile = importFormElement_File;
let file = importFile.files[0];
let reader = new FileReader();
reader.readAsText(file);
reader.onload = async function() {
let importObject = JSON.parse(reader.result);
objectStoreNamesSet = new Set(jsstore_connection.database.tables);
tableArray = Array.from(objectStoreNamesSet);
tableObject = tableArray.filter(tbl => tbl.name == tableName);
tableProperties = Object.values(tableObject)[0];
importObjectKeys = Object.keys(importObject[0]);
if(forceColumnMatching){
//Compare incoming columns with existing table columns (ie. remove any data not matching table schema)
importObject.forEach(item => {
importObjectKeys.forEach((column, index) => {
if (!(column in tableProperties.columns)) {
delete item[column];
}
});
});
}
let upsertData = await jsstore_connection.insert({
into: tableName,
upsert: forceUpsert, //Update if entry already exists (requires primary key to be sent in values object)
values: importObject
,validation: false //required when importing data that has autoincrement and/or date_time columns
//,skipDataCheck : true //will prevent error on "date_time" fields but will not refresh autoIncrement value in JSStore meta
}).then(function (newCount) {
if(newCount >= 1){
console.info(`SUCCESS ${tableName}.total:${newCount}`);
}else{
console.error(`ERROR ${tableName}.total:0`);
}
});
};
reader.onerror = function() {
console.error(reader.error);
};
} |
Beta Was this translation helpful? Give feedback.
-
also regarding manual setup of autoincrement field - i would suggest not to do it. You might end up with something bad - let jsstore take care of it. |
Beta Was this translation helpful? Give feedback.
-
This discussion was created from the release Add ignore,validation.
Beta Was this translation helpful? Give feedback.
All reactions