www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 566a338c985eef37b31fcae25afb19b2ca60e220
parent ee589b0ed59deb2855ae0f256f9de5ae7cf31669
Author: Dan Stillman <dstillman@zotero.org>
Date:   Sun,  6 Jul 2008 18:03:44 +0000

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



Diffstat:
Mchrome/content/zotero/xpcom/data/items.js | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git 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() + ")";