File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,20 @@ describe("collection", () => {
31
31
expect ( coll . data . length ) . toEqual ( 1 ) ;
32
32
} ) ;
33
33
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
+
34
48
it ( "findAndUpdate works" , ( ) => {
35
49
const db = new loki ( "test.db" ) ;
36
50
const coll = db . addCollection ( "testcoll" ) ;
Original file line number Diff line number Diff line change @@ -283,6 +283,21 @@ export class Loki extends LokiEventEmitter {
283
283
return null ;
284
284
}
285
285
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
+
286
301
listCollections ( ) {
287
302
let i = this . collections . length ;
288
303
const colls = [ ] ;
You can’t perform that action at this time.
0 commit comments