html5 - in indexed database, how to get a keysList in which key start with "some string"? -
function fetchemployeebyemail() { try { var result = document.getelementbyid("result"); result.innerhtml = ""; if (localdatabase != null && localdatabase.db != null) { var range = idbkeyrange.lowerbound("john"); var store = localdatabase.db.transaction("employees").objectstore("employees"); var index = store.index("emailindex"); index.get(range).onsuccess = function(evt) { var employee = evt.target.result; var jsonstr = json.stringify(employee); result.innerhtml = jsonstr; }; } } catch(e){ console.log(e); } }
in above sample, how emails have first name "john"????
a nosql approach databases means should think alternate storage access patterns. if want support query first name, , want in performant manner, consider storing derived first name property per employee, create index on derived property, , query index.
storing derived property redundant 1 point of view, sure. intuitively feels normalization violation. however, idea here disk space cheap , available time not. can make trade off in space time want. have 2 ways:
- don't store derived property. in query, loop on employees. each employee, access email property, check, push value array if meets condition, , array of matches.
- redundantly store first-name property in employee store. create index on first-name property. access store via index , condition.
Comments
Post a Comment