Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(loki): rename collection #32

Merged
merged 1 commit into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions packages/loki/spec/generic/collection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ describe("collection", () => {
expect(coll.data.length).toEqual(1);
});

it("collection rename works", function () {
const db = new loki("test.db");
db.addCollection("coll1");

let result = db.getCollection("coll1");
expect(result.name).toEqual("coll1");

db.renameCollection("coll1", "coll2");
result = db.getCollection("coll1");
expect(result).toBeNull();
result = db.getCollection("coll2");
expect(result.name).toEqual("coll2");
});

it("findAndUpdate works", () => {
const db = new loki("test.db");
const coll = db.addCollection("testcoll");
Expand Down
15 changes: 15 additions & 0 deletions packages/loki/src/loki.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,21 @@ export class Loki extends LokiEventEmitter {
return null;
}

/**
* Renames an existing loki collection
* @param {string} oldName - name of collection to rename
* @param {string} newName - new name of collection
* @returns {Collection} reference to the newly renamed collection
*/
renameCollection(oldName, newName) {
const c = this.getCollection(oldName);
if (c) {
c.name = newName;
}

return c;
}

listCollections() {
let i = this.collections.length;
const colls = [];
Expand Down