Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions localstoragedb.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,41 @@
return new_data;
}

function renameTable(old_table, new_table){

if (old_table == new_table){
throw "The new table name is the same as the old one";
}

if (!db.data.hasOwnProperty(old_table) && !db.tables.hasOwnProperty(old_table)){
throw "The table doesn't exists on database";
}

if (db.data.hasOwnProperty(new_table) || db.tables.hasOwnProperty(new_table)){
throw "New table name already exists on database";
}

db.data[new_table] = db.data[old_table];
db.tables[new_table] = db.tables[old_table];

delete db.data[old_table];
delete db.tables[old_table];

storage.setItem(db_id, JSON.stringify(db));

return true;
}

function showTables() {
var list = [];
for(var table in db.tables) {
if( db.tables.hasOwnProperty(table) ) {
list.push(table);
}
}
return list;
}

// ______________________ public methods

return {
Expand All @@ -419,6 +454,14 @@
drop();
},

// Rename table
renameTable: function(old_table, new_table){
return renameTable(old_table, new_table);
},

// Added
showTables: showTables,

// serialize the database
serialize: function() {
return serialize();
Expand Down