From 566a338c985eef37b31fcae25afb19b2ca60e220 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 6 Jul 2008 18:03:44 +0000 Subject: [PATCH] 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 --- chrome/content/zotero/xpcom/data/items.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index 6066c23bdd..4fed9aa39f 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -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() + ")";