Ajaxian의 Dion Almaer씨는 구글 기어즈(Google Gears)의 API는 너무 저수준이라며 불평을 토로하고, 기어즈 데이터베이스 객체의 간단한 추상화를 위한 gears-dblib를 공개했다.
// License: Apache License 2.0
// author: Dion Almaer
var db = new GearsDB('gears-test');
var bob = {id: 3, name: 'Bob', url: 'http://bob.com', description: 'whee'};
db.insertRow('person', bob);
db.insertRow('person', bob, 'name = ?', ['Bob']);
db.selectAll('select * from person', null, function(person) {
document.getElementById('selectAll').innerHTML += ' ' + person.name;
});
db.selectRows('person', 'name like ?', ['%'], function(person) {
document.getElementById('selectRows').innerHTML += ' ' + person.name;
});
var person = db.selectRow('person', 'id = 1');
document.getElementById('selectRow').innerHTML = person.name;
// update
person.name = 'Harry';
db.updateRow('person', person);
person = db.selectRow('person', 'id = 1');
document.getElementById('updateRow').innerHTML = person.name;
// force
person.name = 'Sally';
db.forceRow('person', person);
person = db.selectRow('person', 'id = 1');
document.getElementById('forceRow').innerHTML = person.name;
var adam = {name: 'Adam', url: 'http://adam.com', description: 'long hair'};
db.forceRow('person', adam);
person = db.selectRow('person', 'id = 4');
document.getElementById('forceRow2').innerHTML = person.name;
db.deleteRow('person', bob);
위 코드의 파이어버그(라이트)에서 돌아가는 디버그 모드도 준비되어 있다. 참고로 Uriel Katz씨가 작성한 Simple ORM(Object-relational mapping) for Gears도 눈여겨보자.
와.. 개념없이 접근하려니 계속 삽질이다. 우선 SQLite부터 공부해야겠다.
Comments
Got something to add? You can just leave a comment.
미친듯이 빠르게 나오는군요.
추상화를 위한 래퍼는 그렇다쳐도 벌써 ORM 까지 나오다니.
reply edit
ORM방식이 자바스크립트와 잘 어울리는 듯한 느낌을 받았습니다. 마치 가비지 변수를 할당하듯이 쿼리를 생성하고 호출할 수 있군요. 놀랍습니다.
reply edit
얼마 전까지만 해도 상상도 못했던 JavaScript ORM이 눈앞에…
reply edit
그러게 말입니다. 로컬에서 돌아가니 성능문제는 더이상 걸고넘어질 대상이 아니로군요. 므하하
reply edit
Your Reaction Time!