DBILITY

indexeddb 본문

reference

indexeddb

DBILITY 2021. 4. 30. 11:35
반응형

developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB

 

Using IndexedDB - Web APIs | MDN

Using IndexedDB IndexedDB is a way for you to persistently store data inside a user's browser. Because it lets you create web applications with rich query abilities regardless of network availability, your applications can work both online and offline. 

developer.mozilla.org

//삭제시 IDBOpenDBRequest를 즉시 return하는데 문제는 비동기실행으로 result가 undefined라는 것.
//versionchange event가 발생한다고 함.
//page reload하고 development mode에서 보면 삭제가 되어 있다.

function log(msg) {
	console.log('log -> ', msg);
}
function dropDb(name) {
	return new Promise(function (resolve, reject) {
		var request = window.indexedDB.deleteDatabase(name);
		//idb는 connetion연결 성공시 result
		idb.onversionchange = function(e){
			log('The version of this database has changed');
			resolve(1);
		};
		request.onsuccess = function (e) {};
		request.onerror = function (e) {
			reject("db error [" + e.target.error.name +"] ["+ e.target.error.code +"] " + e.target.error.message);
			e.stopPropagation();
		};
	});
}
 
dropDb(dbName).then(function (result) {
	log(result);
	if(result==1){
		window.location.reload();
	}
}).catch(function (error) {
	log(error);
});

index4.html
0.02MB

반응형

'reference' 카테고리의 다른 글

C# websoket-sharp  (0) 2021.05.09
favicon generator  (0) 2021.05.08
https://jwt.io/ json web token  (0) 2021.04.09
https://docs.videojs.com/  (0) 2021.04.09
A painless self-hosted Git service.  (0) 2021.03.13
Comments