2012-05-09 5 views

답변

2

정상적인 웹 데이터베이스 API를 사용할 수 : http://www.w3.org/TR/webdatabase/

:

var db = openDatabase('mydb', '1.0', 'example database', 2 * 1024 * 1024); 
db.transaction(function (tx) { 
    tx.executeSql('CREATE TABLE IF NOT EXISTS foo (id unique, text)'); 
    tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "foobar")'); 
}); 

db.transaction(function (tx) { 
    tx.executeSql('DROP TABLE foo'); 

    // known to fail - so should rollback the DROP statement 
    tx.executeSql('INSERT INTO foo (id, text) VALUES (1, "foobar")'); 
    forge.logging.error("INSERT into non-existent table succeeded!"); 
}, function (err) { 
    forge.logging.info("error callback invoked, as expected"); 
}); 

db.transaction(function (tx) { 
    tx.executeSql('SELECT * FROM foo', [], function (tx, results) { 
     forge.logging.info("row: "+results); 
    }); 
}); 
: 모든 브라우저는 웹 SQL 예를 들어 http://caniuse.com/#feat=sql-storage

지원, 우리가 실행 테스트 중 하나는이 유사하다

+1

감사합니다. 그것을 시도 할 것입니다 – user567666

+0

사양은 부적절한 것으로 표시됩니다. 다른 방법이 있습니까? –

+0

IndexedDB는 http://www.w3.org/TR/IndexedDB/를 대체 할 예정이지만 아직 모바일 브라우저를 사용하지는 않았습니다 : http://caniuse.com/indexeddb –

0

최근에는 LocalForage과 같은 것을 사용하여 indexedDB에서 webSQL to localStorage로 폴백 할 수 있으며, 일관된 API를 제공합니다. 그리고 Angular/Ionic을 사용하고 있다면 이것은 사업입니다 : Angular-LocalForage