async function InsertIntoContentDatabase(db:D1Database, content:ContentDataType): Promise<D1Result<unknown>[]>{
try {
if(content.contentDataItemType === undefined){
console.log('No contentDataItemType');
throw('Missing contentDataItemType Array');
}
//Because we may have multiple items to push into the database, we need to batch the call
const batcher = await db.prepare("INSERT INTO content_models (contentGroupRef, projectRef, contentElementRef, contentBakedStatement, publishState) VALUES (?1, ?2, ?3, ?4, ?5)")
let binderCollection=[];
for (let index = 0; index < content.contentDataItemType.length; index++) {
const element = content.contentDataItemType[index];
let temp = batcher.bind(
element.contentGroupRef,
element.projectRef,
element.contentElementRef,
element.contentBakedStatement,
element.publishState
);
binderCollection.push(temp);
console.log('Loop Batch=>', JSON.stringify(temp));
}
return await db.batch(binderCollection);
} catch (error:any) {
console.log('D1 Instance=>', JSON.stringify(db.dump()));
console.log({
message: error.message,
cause: error.cause.message,
});
throw(error);
}
}
async function InsertIntoContentDatabase(db:D1Database, content:ContentDataType): Promise<D1Result<unknown>[]>{
try {
if(content.contentDataItemType === undefined){
console.log('No contentDataItemType');
throw('Missing contentDataItemType Array');
}
//Because we may have multiple items to push into the database, we need to batch the call
const batcher = await db.prepare("INSERT INTO content_models (contentGroupRef, projectRef, contentElementRef, contentBakedStatement, publishState) VALUES (?1, ?2, ?3, ?4, ?5)")
let binderCollection=[];
for (let index = 0; index < content.contentDataItemType.length; index++) {
const element = content.contentDataItemType[index];
let temp = batcher.bind(
element.contentGroupRef,
element.projectRef,
element.contentElementRef,
element.contentBakedStatement,
element.publishState
);
binderCollection.push(temp);
console.log('Loop Batch=>', JSON.stringify(temp));
}
return await db.batch(binderCollection);
} catch (error:any) {
console.log('D1 Instance=>', JSON.stringify(db.dump()));
console.log({
message: error.message,
cause: error.cause.message,
});
throw(error);
}
}