다음 함수는 데이터를 추가하는 IndexedDB의 예입니다.
function add() {
var request = db.transaction(["employee"], "readwrite")
.objectStore("employee")
.add({ id: "001", name: "Amit", age: 28, email: "demo1@example.com" });
request.onsuccess = function(event) {
alert("Amit has been added to your database.");
};
request.onerror = function(event) {
alert("Unable to add data\r\nAmit is already exist in your database! ");
}
} 위에서 데이터베이스에 다음 세부 정보를 추가했습니다.
const employeeData = [
{ id: "001", name: "Amit", age: 28, email: "demo1@example.com" },
];