Addresses #971, Add support for secondary key

Zotero.Items.getByKey(key) -- retrieve an Item object by its secondary lookup key

No caching yet -- if this becomes a bottleneck, I'll add some
This commit is contained in:
Dan Stillman 2008-07-06 18:03:44 +00:00
parent ee589b0ed5
commit 566a338c98

View file

@ -27,6 +27,7 @@
Zotero.Items = new function() {
// Privileged methods
this.get = get;
this.getByKey = getByKey;
this.exist = exist;
this.getAll = getAll;
this.getUpdated = getUpdated;
@ -101,6 +102,22 @@ Zotero.Items = new function() {
}
/**
* Retrieves an item by its secondary lookup key
*
* @param string key Secondary lookup key
* @return object Zotero.Item object, or FALSE if not found
*/
function getByKey(key) {
var sql = "SELECT itemID FROM items WHERE key=?";
var itemID = Zotero.DB.valueQuery(sql, key);
if (!itemID) {
return false;
}
return Zotero.Items.get(itemID);
}
function exist(itemIDs) {
var sql = "SELECT itemID FROM items WHERE itemID IN ("
+ itemIDs.map(function () '?').join() + ")";