Many-to-one item note support in the schema and data layer -- still some issues on (I think) the interface side
This commit is contained in:
parent
e417d8e690
commit
fd85af40f8
3 changed files with 70 additions and 3 deletions
|
@ -675,6 +675,62 @@ Scholar.Item.prototype.save = function(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Methods dealing with item notes
|
||||||
|
//
|
||||||
|
// save() is not required for note functions
|
||||||
|
//
|
||||||
|
/**
|
||||||
|
* Add a new note to an item and return the noteID
|
||||||
|
**/
|
||||||
|
Scholar.Item.prototype.addNote = function(text){
|
||||||
|
Scholar.DB.beginTransaction();
|
||||||
|
var noteID = Scholar.getRandomID('itemNotes', 'noteID', 65535);
|
||||||
|
var sql = "INSERT INTO itemNotes (noteID, itemID, note) VALUES (?,?,?)";
|
||||||
|
Scholar.DB.query(sql,
|
||||||
|
[{'int':noteID}, {'int':this.getID()}, {'string':text}]
|
||||||
|
);
|
||||||
|
Scholar.DB.commitTransaction();
|
||||||
|
return noteID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an item note
|
||||||
|
**/
|
||||||
|
Scholar.Item.prototype.updateNote = function(noteID, text){
|
||||||
|
var sql = "UPDATE itemNotes SET note=? WHERE itemID=? AND noteID=?";
|
||||||
|
return Scholar.DB.query(sql,
|
||||||
|
[{'string':text}, {'int':this.getID()}, {'int':noteID}]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete an item note
|
||||||
|
**/
|
||||||
|
Scholar.Item.prototype.removeNote = function(noteID){
|
||||||
|
var sql = "DELETE FROM itemNotes WHERE itemID=" + this.getID()
|
||||||
|
+ " AND noteID=" + noteID;
|
||||||
|
return Scholar.DB.query(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the text of an item note
|
||||||
|
**/
|
||||||
|
Scholar.Item.prototype.getNote = function(noteID){
|
||||||
|
var sql = "SELECT note FROM itemNotes WHERE itemID=" + this.getID()
|
||||||
|
+ " AND noteID=" + noteID;
|
||||||
|
return Scholar.DB.valueQuery(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of noteIDs for this item
|
||||||
|
**/
|
||||||
|
Scholar.Item.prototype.getNotes = function(){
|
||||||
|
var sql = "SELECT noteID FROM itemNotes WHERE itemID=" + this.getID();
|
||||||
|
return Scholar.DB.columnQuery(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete item from database and clear from Scholar.Items internal array
|
* Delete item from database and clear from Scholar.Items internal array
|
||||||
**/
|
**/
|
||||||
|
|
|
@ -370,7 +370,7 @@ Scholar.Schema = new function(){
|
||||||
//
|
//
|
||||||
// Change this value to match the schema version
|
// Change this value to match the schema version
|
||||||
//
|
//
|
||||||
var toVersion = 19;
|
var toVersion = 20;
|
||||||
|
|
||||||
if (toVersion != _getSchemaSQLVersion()){
|
if (toVersion != _getSchemaSQLVersion()){
|
||||||
throw('Schema version does not match version in _migrateSchema()');
|
throw('Schema version does not match version in _migrateSchema()');
|
||||||
|
@ -385,7 +385,7 @@ Scholar.Schema = new function(){
|
||||||
// Each block performs the changes necessary to move from the
|
// Each block performs the changes necessary to move from the
|
||||||
// previous revision to that one.
|
// previous revision to that one.
|
||||||
for (var i=parseInt(fromVersion) + 1; i<=toVersion; i++){
|
for (var i=parseInt(fromVersion) + 1; i<=toVersion; i++){
|
||||||
if (i==19){
|
if (i==20){
|
||||||
_initializeSchema();
|
_initializeSchema();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
schema.sql
13
schema.sql
|
@ -1,4 +1,4 @@
|
||||||
-- 19
|
-- 20
|
||||||
|
|
||||||
DROP TABLE IF EXISTS version;
|
DROP TABLE IF EXISTS version;
|
||||||
CREATE TABLE version (
|
CREATE TABLE version (
|
||||||
|
@ -60,6 +60,17 @@
|
||||||
DROP INDEX IF EXISTS value;
|
DROP INDEX IF EXISTS value;
|
||||||
CREATE INDEX value ON itemData(value);
|
CREATE INDEX value ON itemData(value);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS itemNotes;
|
||||||
|
CREATE TABLE itemNotes (
|
||||||
|
noteID INT,
|
||||||
|
itemID INT,
|
||||||
|
note TEXT,
|
||||||
|
PRIMARY KEY (noteID),
|
||||||
|
FOREIGN KEY (itemID) REFERENCES items(itemID)
|
||||||
|
);
|
||||||
|
DROP INDEX IF EXISTS itemNotes_itemID;
|
||||||
|
CREATE INDEX itemNotes_itemID ON itemNotes(itemID);
|
||||||
|
|
||||||
DROP TABLE IF EXISTS keywords;
|
DROP TABLE IF EXISTS keywords;
|
||||||
CREATE TABLE keywords (
|
CREATE TABLE keywords (
|
||||||
keywordID INTEGER PRIMARY KEY,
|
keywordID INTEGER PRIMARY KEY,
|
||||||
|
|
Loading…
Reference in a new issue