SlideShare a Scribd company logo
1 of 30
Client-Side Storage in HTML5
Storage History
IE5.5의 userData(2000년)

           페이지당 128kb
           도메인당 1mb
Flash6의 Local Share Object(02년)
• Flash8에서 ExternalInterface을
  이용하여 JS로 접근 가능.(06년)
• 도메인당 100kb.
• Flash의 높은 설치율.
Google Gears (07년)
• Firefox, IE 플러그인.
• SQLLite 임베디드.
• 크기에 제한 없음.
Client-side Storage in HTML5
웹 어플리케이션에 적합한 API.

• Web Storage
  localStorage (sessionStorage)
  – Cookie, userData, LSO
• Web SQL Database
  – Google gears
• Indexed Database
Web Storage(DOM Storage)
Web Storage
• localStorage, sessionStorage
  localStorage.setItem("bar",”foo”); //값 저장
  var foo = localStorage.getItem("bar"); //값 반환

  var foo = localStorage["bar"];
  localStorage["bar"] = foo;

  localStorage.removeItem("bar"); // 값 삭제
  localStorage.clear(); // 모두 삭제
  localStorage.length ; // 저장된 수
Web Storage 특징
대부분의 브라우저에서 지원.
사용하기 쉽다.
유효기간이 없다.
용량이 크다.
오직 client을 위한 Storage.
브라우저간 공유.
문자만 저장, 객체는 toString한 결과 저장.
 {}->[object object], []->[object array]
Web Storage 지원 현황
•   Internet Explorer 8
•   Firefox 3.5
•   Safari 4
•   Google Chrome 4
•   Opera 10.50
•   iOS 2.0
•   Android 2.0
Web SQL Database
Web SQL Database
openDB : function(){
       this.db = openDatabase('AddressBook', '1.0', '데이터 베이스', (5 * 1024 * 1024));
},
createTable : function(){
   this.db.transaction(function(tx){
           tx.executeSql('CREATE TABLE contacts
                        (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                         name TEXT, email TEXT, cell TEXT)‟);
   });
},
selectRow : function(){
              this.db.transaction(function(tx){
                            tx.executeSql('SELECT * FROM contacts where id = ?„, // sql구문
                                             [“1”], // preparedstatement 문자
                                             function(transaction, resultSet){ //성공 콜백
                                                    for (var i = 0; i < resultSet.rows.length; i++) {
                                                                  console.log(resultSet.rows.item(i));
                                                    }
                                              },
                                             function(transaction, error){ //실패 콜백
                                                    console.log(error.message);
                                             });
              });
}
Web SQL Database 특징
Google gears와 같음.
SQLLite 3.6.19가 임베디드.
SQLLite의 문법을 그대로 사용.
도메인당 5mb를 제공.
단순한 API, 간단한 callback.
Web SQL Database 지원 현황
•   Safari 4.0
•   Chrome 4.0
•   Opera 10.50
•   iOS 3.0
•   Android 2.0
고민
Web SQL Database 문제

• SQLLite는 표준이 아님.

• 업그레이드 문제.

• 다른 디바이스 지원 문제.
Indexed DB(Web Simple DB)
indexed Database-DB생성

               Address Book




this.db =
window.mozIndexedDB.open(
            "AddressBook",//이름
            "책 관련 데이터 베이스“//설명
);
Object Store 생성

               Address Book

                             contracts




var store = this.db.createObjectStore(
     "contacts", //이름
     {"keyPath": "id"} //pk (in-line keys - 자동생성, out-of-line keys - 직접 입력)
     //false (자동 증가. firefox4 default false, w3c true)
);
Data 등록
                 AddressBook      contracts


                                     Id
                                     Name
                                     Email
                                     cell




var writeTransaction = this.db.transaction(

                            [ "contacts" ],//잠글 object store명

                            IDBTransaction.READ_WRITE // Lock type (READ_ONLY, READ_WRITE)

                            //,30 timeout 밀리세컨드
);
var store = writeTransaction.objectStore( "contacts" );
var id = parseInt(Math.random() * 100);
var writeRequest = store.add({
      "name" : "mixed", "email" : "mixed@nhn.com", "cell":”0100003333”, "id" : id
});
Data 등록
                 AddressBook      contracts


                                     Id
                                     Name
                                     Email
                                     cell




writeRequest.onsuccess = function(e){
     console.log (writeRequest.result);//id
};
writeRequest.ontimeout = function ( e ) {
     alert("timeout");
     writeTransaction.abort();
};
Data 검색
                  AddressBook       contracts


                                        Id          Id      Id      Id
                                        Name        Name    Name    Name
                                        Email       Email   Email   Email
                                        cell        cell    cell    cell




var store = readTransaction.objectStore( "contacts" );
var readCursor = store.openCursor();


readCursor.onsuccess = function ( e ) {
 if ( readCursor.result ) {

     console.log( readCursor.result); //데이터
     readCursor.result["continue"]();
 }else{
       console.log("end");
 }
};
Indexed Database 특징
 Key/value형태.
 b-tree데이터 구조.
 보다 low레벨을 지원.
 Callback패턴이 아니라 다양한 event기반의
  패턴.
 속도가 빠름.
커뮤니티 반응
Indexed Database 지원 현황
• Firefox4 beta 10
• Chrome 11
활용 범위
• Web Storage : 검색 기록
• Web DB : offline일 때 저장하거나 검색.
 – 가계부, 메일, 캘린더 등…
한계
• 서버, 로컬 두 군데서 데이터를 관리하여
  무결성의 문제가 생김.
• 보안 이슈로 인하여 활용도가 떨어짐.
• 더욱 복잡해지는 클라이언트.
• 진행 중인 API.
Reference
•   http://www.w3.org/TR/IndexedDB/

•   http://diveintohtml5.org/storage.html

•   http://en.wikipedia.org/wiki/Browser_wars#The_first_browser_war

•   http://msdn.microsoft.com/en-us/library/ms531424(VS.85).aspx

•   http://hacks.mozilla.org/2010/06/beyond-html5-database-apis-and-the-road-to-indexeddb/

•   http://hacks.mozilla.org/2010/06/comparing-indexeddb-and-webdatabase/

•   http://en.wikipedia.org/wiki/Web_Storage

•   http://code.google.com/p/indexeddb/

•   http://www.hotcleaner.com/web_storage.html

•   http://antmicro.com/blog/2010/07/async-indexeddb-js-api-test/

•   http://sites.google.com/site/usingindexeddb/

•   https://developer.mozilla.org/en/IndexedDB

•   http://mxr.mozilla.org/mozilla-central/source/dom/indexedDB/test/test_key_requirements.html?force=1#33

•   http://nparashuram.com/trialtool/index.html#example=/ttd/IndexedDB/moz_indexedDB.html&selected=#db&

•   http://html5doctor.com/introducing-web-sql-databases/

•   http://uxebu.com/blog/2011/01/17/indexeddb-updates-ff4-09b/

•   http://news.cnet.com/8301-30685_3-20000376-264.html?tag=mncol;title

•   http://blogs.msdn.com/b/interoperability/archive/2010/12/21/indexeddb-prototype-available-for-internet-explorer.aspx

•   http://blogs.msdn.com/b/interoperability/archive/2011/02/03/the-indexeddb-prototype-gets-an-update.aspx

•   http://mikewest.org/2010/12/intro-to-indexeddb

•   http://blog.submitmy.info/2010/04/html5-client-side-storage/

•   https://developer.mozilla.org/en/IndexedDB/IndexedDB_primer
Client side storage in html5

More Related Content

What's hot

Jpa 잘 (하는 척) 하기
Jpa 잘 (하는 척) 하기Jpa 잘 (하는 척) 하기
Jpa 잘 (하는 척) 하기경원 이
 
DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)beom kyun choi
 
Node.js + Express + MongoDB
Node.js + Express + MongoDBNode.js + Express + MongoDB
Node.js + Express + MongoDBVincent Park
 
Laravel 로 배우는 서버사이드 #4
Laravel 로 배우는 서버사이드 #4Laravel 로 배우는 서버사이드 #4
Laravel 로 배우는 서버사이드 #4성일 한
 
5-3. html5 device access
5-3. html5 device access5-3. html5 device access
5-3. html5 device accessJinKyoungHeo
 
JWT (JSON web token)
JWT (JSON web token)JWT (JSON web token)
JWT (JSON web token)Jinhyuck Kim
 
자바 웹 개발 시작하기 (6주차 : 커뮤니티를 만들어보자!)
자바 웹 개발 시작하기 (6주차 : 커뮤니티를 만들어보자!)자바 웹 개발 시작하기 (6주차 : 커뮤니티를 만들어보자!)
자바 웹 개발 시작하기 (6주차 : 커뮤니티를 만들어보자!)DK Lee
 
처음배우는 자바스크립트, 제이쿼리 #1
처음배우는 자바스크립트, 제이쿼리 #1처음배우는 자바스크립트, 제이쿼리 #1
처음배우는 자바스크립트, 제이쿼리 #1성일 한
 
파이썬 언어 기초
파이썬 언어 기초파이썬 언어 기초
파이썬 언어 기초beom kyun choi
 
Html5&css 3장
Html5&css 3장Html5&css 3장
Html5&css 3장홍준 김
 

What's hot (14)

DDD Start Ch#3
DDD Start Ch#3DDD Start Ch#3
DDD Start Ch#3
 
4-2. ajax
4-2. ajax4-2. ajax
4-2. ajax
 
Jpa 잘 (하는 척) 하기
Jpa 잘 (하는 척) 하기Jpa 잘 (하는 척) 하기
Jpa 잘 (하는 척) 하기
 
DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)
 
Node.js + Express + MongoDB
Node.js + Express + MongoDBNode.js + Express + MongoDB
Node.js + Express + MongoDB
 
Laravel 로 배우는 서버사이드 #4
Laravel 로 배우는 서버사이드 #4Laravel 로 배우는 서버사이드 #4
Laravel 로 배우는 서버사이드 #4
 
5-3. html5 device access
5-3. html5 device access5-3. html5 device access
5-3. html5 device access
 
JWT (JSON web token)
JWT (JSON web token)JWT (JSON web token)
JWT (JSON web token)
 
DDD Repository
DDD RepositoryDDD Repository
DDD Repository
 
자바 웹 개발 시작하기 (6주차 : 커뮤니티를 만들어보자!)
자바 웹 개발 시작하기 (6주차 : 커뮤니티를 만들어보자!)자바 웹 개발 시작하기 (6주차 : 커뮤니티를 만들어보자!)
자바 웹 개발 시작하기 (6주차 : 커뮤니티를 만들어보자!)
 
처음배우는 자바스크립트, 제이쿼리 #1
처음배우는 자바스크립트, 제이쿼리 #1처음배우는 자바스크립트, 제이쿼리 #1
처음배우는 자바스크립트, 제이쿼리 #1
 
3-2. selector api
3-2. selector api3-2. selector api
3-2. selector api
 
파이썬 언어 기초
파이썬 언어 기초파이썬 언어 기초
파이썬 언어 기초
 
Html5&css 3장
Html5&css 3장Html5&css 3장
Html5&css 3장
 

Viewers also liked

Html5 시대의 웹앱 프로그래밍 방식의 변화
Html5 시대의 웹앱 프로그래밍 방식의 변화Html5 시대의 웹앱 프로그래밍 방식의 변화
Html5 시대의 웹앱 프로그래밍 방식의 변화yongwoo Jeon
 
DoctypeHTML5 (Hyderabad) Presentation on Multimedia
DoctypeHTML5 (Hyderabad) Presentation on MultimediaDoctypeHTML5 (Hyderabad) Presentation on Multimedia
DoctypeHTML5 (Hyderabad) Presentation on MultimediaParashuram N
 
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...Stephan Hochdörfer
 
Mobile html5 today
Mobile html5 todayMobile html5 today
Mobile html5 todayIdo Green
 

Viewers also liked (8)

Html5 시대의 웹앱 프로그래밍 방식의 변화
Html5 시대의 웹앱 프로그래밍 방식의 변화Html5 시대의 웹앱 프로그래밍 방식의 변화
Html5 시대의 웹앱 프로그래밍 방식의 변화
 
Web notification
Web notificationWeb notification
Web notification
 
DoctypeHTML5 (Hyderabad) Presentation on Multimedia
DoctypeHTML5 (Hyderabad) Presentation on MultimediaDoctypeHTML5 (Hyderabad) Presentation on Multimedia
DoctypeHTML5 (Hyderabad) Presentation on Multimedia
 
Indexed DB
Indexed DBIndexed DB
Indexed DB
 
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
Offline. Na und? Strategien für offlinefähige Applikationen in HTML5 - Herbst...
 
Mobile html5 today
Mobile html5 todayMobile html5 today
Mobile html5 today
 
2011 11 2_reconocimiento_arbizu_sesion5
2011 11 2_reconocimiento_arbizu_sesion52011 11 2_reconocimiento_arbizu_sesion5
2011 11 2_reconocimiento_arbizu_sesion5
 
deview2014
deview2014deview2014
deview2014
 

Similar to Client side storage in html5

GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출
GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출
GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출GDG Korea
 
[아꿈사/111105] html5 9장 클라이언트측 데이터로 작업하기
[아꿈사/111105] html5 9장 클라이언트측 데이터로 작업하기[아꿈사/111105] html5 9장 클라이언트측 데이터로 작업하기
[아꿈사/111105] html5 9장 클라이언트측 데이터로 작업하기sung ki choi
 
Secrets of the JavaScript Ninja - Chapter 12. DOM modification
Secrets of the JavaScript Ninja - Chapter 12. DOM modificationSecrets of the JavaScript Ninja - Chapter 12. DOM modification
Secrets of the JavaScript Ninja - Chapter 12. DOM modificationHyuncheol Jeon
 
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)Sang Don Kim
 
Mongodb2.2와 2.4의 신 기능 소개
Mongodb2.2와 2.4의 신 기능 소개Mongodb2.2와 2.4의 신 기능 소개
Mongodb2.2와 2.4의 신 기능 소개흥배 최
 
데이터베이스패턴
데이터베이스패턴데이터베이스패턴
데이터베이스패턴Suan Lee
 
Apache solr소개 20120629
Apache solr소개 20120629Apache solr소개 20120629
Apache solr소개 20120629Dosang Yoon
 
Blockchain 2nd ethereum_core
Blockchain 2nd ethereum_coreBlockchain 2nd ethereum_core
Blockchain 2nd ethereum_coreihpark92
 
처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4성일 한
 
안드로이드 개발자를 위한 스위프트
안드로이드 개발자를 위한 스위프트안드로이드 개발자를 위한 스위프트
안드로이드 개발자를 위한 스위프트병한 유
 
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjsNodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs기동 이
 
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive Elasticsearch
 
진짜기초 Node.js
진짜기초 Node.js진짜기초 Node.js
진짜기초 Node.jsWoo Jin Kim
 
Web server page_ed10
Web server page_ed10Web server page_ed10
Web server page_ed10hungrok
 
Ji 개발 리뷰 (신림프로그래머)
Ji 개발 리뷰 (신림프로그래머)Ji 개발 리뷰 (신림프로그래머)
Ji 개발 리뷰 (신림프로그래머)beom kyun choi
 

Similar to Client side storage in html5 (20)

Html5 performance
Html5 performanceHtml5 performance
Html5 performance
 
GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출
GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출
GKAC 2015 Apr. - Battery, 안드로이드를 위한 쉬운 웹 API 호출
 
[아꿈사/111105] html5 9장 클라이언트측 데이터로 작업하기
[아꿈사/111105] html5 9장 클라이언트측 데이터로 작업하기[아꿈사/111105] html5 9장 클라이언트측 데이터로 작업하기
[아꿈사/111105] html5 9장 클라이언트측 데이터로 작업하기
 
Node.js at OKJSP
Node.js at OKJSPNode.js at OKJSP
Node.js at OKJSP
 
Secrets of the JavaScript Ninja - Chapter 12. DOM modification
Secrets of the JavaScript Ninja - Chapter 12. DOM modificationSecrets of the JavaScript Ninja - Chapter 12. DOM modification
Secrets of the JavaScript Ninja - Chapter 12. DOM modification
 
Html5
Html5 Html5
Html5
 
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)
 
Mongodb2.2와 2.4의 신 기능 소개
Mongodb2.2와 2.4의 신 기능 소개Mongodb2.2와 2.4의 신 기능 소개
Mongodb2.2와 2.4의 신 기능 소개
 
데이터베이스패턴
데이터베이스패턴데이터베이스패턴
데이터베이스패턴
 
Apache solr소개 20120629
Apache solr소개 20120629Apache solr소개 20120629
Apache solr소개 20120629
 
Mongo db 최범균
Mongo db 최범균Mongo db 최범균
Mongo db 최범균
 
Blockchain 2nd ethereum_core
Blockchain 2nd ethereum_coreBlockchain 2nd ethereum_core
Blockchain 2nd ethereum_core
 
처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4
 
안드로이드 개발자를 위한 스위프트
안드로이드 개발자를 위한 스위프트안드로이드 개발자를 위한 스위프트
안드로이드 개발자를 위한 스위프트
 
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjsNodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs
 
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive
Partner Story(Megazone): 금융사 실전 프로젝트 DeepDive
 
진짜기초 Node.js
진짜기초 Node.js진짜기초 Node.js
진짜기초 Node.js
 
Node.js 첫걸음
Node.js 첫걸음Node.js 첫걸음
Node.js 첫걸음
 
Web server page_ed10
Web server page_ed10Web server page_ed10
Web server page_ed10
 
Ji 개발 리뷰 (신림프로그래머)
Ji 개발 리뷰 (신림프로그래머)Ji 개발 리뷰 (신림프로그래머)
Ji 개발 리뷰 (신림프로그래머)
 

More from yongwoo Jeon

EcmaScript6(2015) Overview
EcmaScript6(2015) OverviewEcmaScript6(2015) Overview
EcmaScript6(2015) Overviewyongwoo Jeon
 
Web Components 101 polymer & brick
Web Components 101 polymer & brickWeb Components 101 polymer & brick
Web Components 101 polymer & brickyongwoo Jeon
 
Html5 앱과 웹사이트를 보다 빠르게 하는 50가지
Html5 앱과 웹사이트를 보다 빠르게 하는 50가지Html5 앱과 웹사이트를 보다 빠르게 하는 50가지
Html5 앱과 웹사이트를 보다 빠르게 하는 50가지yongwoo Jeon
 
모바일 디버깅
모바일 디버깅모바일 디버깅
모바일 디버깅yongwoo Jeon
 

More from yongwoo Jeon (11)

EcmaScript6(2015) Overview
EcmaScript6(2015) OverviewEcmaScript6(2015) Overview
EcmaScript6(2015) Overview
 
Web Components 101 polymer & brick
Web Components 101 polymer & brickWeb Components 101 polymer & brick
Web Components 101 polymer & brick
 
asm.js
asm.jsasm.js
asm.js
 
Html5 앱과 웹사이트를 보다 빠르게 하는 50가지
Html5 앱과 웹사이트를 보다 빠르게 하는 50가지Html5 앱과 웹사이트를 보다 빠르게 하는 50가지
Html5 앱과 웹사이트를 보다 빠르게 하는 50가지
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
모바일 디버깅
모바일 디버깅모바일 디버깅
모바일 디버깅
 
Web component
Web componentWeb component
Web component
 
Html5 use cases
Html5 use casesHtml5 use cases
Html5 use cases
 
Devfest
DevfestDevfest
Devfest
 
Scriptable cache
Scriptable cacheScriptable cache
Scriptable cache
 
Whats jindo
Whats jindoWhats jindo
Whats jindo
 

Client side storage in html5

  • 3. IE5.5의 userData(2000년) 페이지당 128kb 도메인당 1mb
  • 4. Flash6의 Local Share Object(02년) • Flash8에서 ExternalInterface을 이용하여 JS로 접근 가능.(06년) • 도메인당 100kb. • Flash의 높은 설치율.
  • 5. Google Gears (07년) • Firefox, IE 플러그인. • SQLLite 임베디드. • 크기에 제한 없음.
  • 6. Client-side Storage in HTML5 웹 어플리케이션에 적합한 API. • Web Storage localStorage (sessionStorage) – Cookie, userData, LSO • Web SQL Database – Google gears • Indexed Database
  • 8. Web Storage • localStorage, sessionStorage localStorage.setItem("bar",”foo”); //값 저장 var foo = localStorage.getItem("bar"); //값 반환 var foo = localStorage["bar"]; localStorage["bar"] = foo; localStorage.removeItem("bar"); // 값 삭제 localStorage.clear(); // 모두 삭제 localStorage.length ; // 저장된 수
  • 9. Web Storage 특징 대부분의 브라우저에서 지원. 사용하기 쉽다. 유효기간이 없다. 용량이 크다. 오직 client을 위한 Storage. 브라우저간 공유. 문자만 저장, 객체는 toString한 결과 저장. {}->[object object], []->[object array]
  • 10. Web Storage 지원 현황 • Internet Explorer 8 • Firefox 3.5 • Safari 4 • Google Chrome 4 • Opera 10.50 • iOS 2.0 • Android 2.0
  • 12. Web SQL Database openDB : function(){ this.db = openDatabase('AddressBook', '1.0', '데이터 베이스', (5 * 1024 * 1024)); }, createTable : function(){ this.db.transaction(function(tx){ tx.executeSql('CREATE TABLE contacts (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT, cell TEXT)‟); }); }, selectRow : function(){ this.db.transaction(function(tx){ tx.executeSql('SELECT * FROM contacts where id = ?„, // sql구문 [“1”], // preparedstatement 문자 function(transaction, resultSet){ //성공 콜백 for (var i = 0; i < resultSet.rows.length; i++) { console.log(resultSet.rows.item(i)); } }, function(transaction, error){ //실패 콜백 console.log(error.message); }); }); }
  • 13. Web SQL Database 특징 Google gears와 같음. SQLLite 3.6.19가 임베디드. SQLLite의 문법을 그대로 사용. 도메인당 5mb를 제공. 단순한 API, 간단한 callback.
  • 14. Web SQL Database 지원 현황 • Safari 4.0 • Chrome 4.0 • Opera 10.50 • iOS 3.0 • Android 2.0
  • 16. Web SQL Database 문제 • SQLLite는 표준이 아님. • 업그레이드 문제. • 다른 디바이스 지원 문제.
  • 18. indexed Database-DB생성 Address Book this.db = window.mozIndexedDB.open( "AddressBook",//이름 "책 관련 데이터 베이스“//설명 );
  • 19. Object Store 생성 Address Book contracts var store = this.db.createObjectStore( "contacts", //이름 {"keyPath": "id"} //pk (in-line keys - 자동생성, out-of-line keys - 직접 입력) //false (자동 증가. firefox4 default false, w3c true) );
  • 20. Data 등록 AddressBook contracts Id Name Email cell var writeTransaction = this.db.transaction( [ "contacts" ],//잠글 object store명 IDBTransaction.READ_WRITE // Lock type (READ_ONLY, READ_WRITE) //,30 timeout 밀리세컨드 ); var store = writeTransaction.objectStore( "contacts" ); var id = parseInt(Math.random() * 100); var writeRequest = store.add({ "name" : "mixed", "email" : "mixed@nhn.com", "cell":”0100003333”, "id" : id });
  • 21. Data 등록 AddressBook contracts Id Name Email cell writeRequest.onsuccess = function(e){ console.log (writeRequest.result);//id }; writeRequest.ontimeout = function ( e ) { alert("timeout"); writeTransaction.abort(); };
  • 22. Data 검색 AddressBook contracts Id Id Id Id Name Name Name Name Email Email Email Email cell cell cell cell var store = readTransaction.objectStore( "contacts" ); var readCursor = store.openCursor(); readCursor.onsuccess = function ( e ) { if ( readCursor.result ) { console.log( readCursor.result); //데이터 readCursor.result["continue"](); }else{ console.log("end"); } };
  • 23. Indexed Database 특징  Key/value형태.  b-tree데이터 구조.  보다 low레벨을 지원.  Callback패턴이 아니라 다양한 event기반의 패턴.  속도가 빠름.
  • 25. Indexed Database 지원 현황 • Firefox4 beta 10 • Chrome 11
  • 26. 활용 범위 • Web Storage : 검색 기록 • Web DB : offline일 때 저장하거나 검색. – 가계부, 메일, 캘린더 등…
  • 27. 한계 • 서버, 로컬 두 군데서 데이터를 관리하여 무결성의 문제가 생김. • 보안 이슈로 인하여 활용도가 떨어짐. • 더욱 복잡해지는 클라이언트. • 진행 중인 API.
  • 28.
  • 29. Reference • http://www.w3.org/TR/IndexedDB/ • http://diveintohtml5.org/storage.html • http://en.wikipedia.org/wiki/Browser_wars#The_first_browser_war • http://msdn.microsoft.com/en-us/library/ms531424(VS.85).aspx • http://hacks.mozilla.org/2010/06/beyond-html5-database-apis-and-the-road-to-indexeddb/ • http://hacks.mozilla.org/2010/06/comparing-indexeddb-and-webdatabase/ • http://en.wikipedia.org/wiki/Web_Storage • http://code.google.com/p/indexeddb/ • http://www.hotcleaner.com/web_storage.html • http://antmicro.com/blog/2010/07/async-indexeddb-js-api-test/ • http://sites.google.com/site/usingindexeddb/ • https://developer.mozilla.org/en/IndexedDB • http://mxr.mozilla.org/mozilla-central/source/dom/indexedDB/test/test_key_requirements.html?force=1#33 • http://nparashuram.com/trialtool/index.html#example=/ttd/IndexedDB/moz_indexedDB.html&selected=#db& • http://html5doctor.com/introducing-web-sql-databases/ • http://uxebu.com/blog/2011/01/17/indexeddb-updates-ff4-09b/ • http://news.cnet.com/8301-30685_3-20000376-264.html?tag=mncol;title • http://blogs.msdn.com/b/interoperability/archive/2010/12/21/indexeddb-prototype-available-for-internet-explorer.aspx • http://blogs.msdn.com/b/interoperability/archive/2011/02/03/the-indexeddb-prototype-gets-an-update.aspx • http://mikewest.org/2010/12/intro-to-indexeddb • http://blog.submitmy.info/2010/04/html5-client-side-storage/ • https://developer.mozilla.org/en/IndexedDB/IndexedDB_primer