File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,20 @@ describe("collection", () => {
3131 expect ( coll . data . length ) . toEqual ( 1 ) ;
3232 } ) ;
3333
34+ it ( "collection rename works" , function ( ) {
35+ const db = new loki ( "test.db" ) ;
36+ db . addCollection ( "coll1" ) ;
37+
38+ let result = db . getCollection ( "coll1" ) ;
39+ expect ( result . name ) . toEqual ( "coll1" ) ;
40+
41+ db . renameCollection ( "coll1" , "coll2" ) ;
42+ result = db . getCollection ( "coll1" ) ;
43+ expect ( result ) . toBeNull ( ) ;
44+ result = db . getCollection ( "coll2" ) ;
45+ expect ( result . name ) . toEqual ( "coll2" ) ;
46+ } ) ;
47+
3448 it ( "findAndUpdate works" , ( ) => {
3549 const db = new loki ( "test.db" ) ;
3650 const coll = db . addCollection ( "testcoll" ) ;
Original file line number Diff line number Diff line change @@ -283,6 +283,21 @@ export class Loki extends LokiEventEmitter {
283283 return null ;
284284 }
285285
286+ /**
287+ * Renames an existing loki collection
288+ * @param {string } oldName - name of collection to rename
289+ * @param {string } newName - new name of collection
290+ * @returns {Collection } reference to the newly renamed collection
291+ */
292+ renameCollection ( oldName , newName ) {
293+ const c = this . getCollection ( oldName ) ;
294+ if ( c ) {
295+ c . name = newName ;
296+ }
297+
298+ return c ;
299+ }
300+
286301 listCollections ( ) {
287302 let i = this . collections . length ;
288303 const colls = [ ] ;
You can’t perform that action at this time.
0 commit comments