index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import * as Geo from './geo/index';
  2. import { CollectionReference } from './collection';
  3. import { Command } from './command';
  4. import { ServerDateConstructor } from './serverDate/index';
  5. import { RegExpConstructor } from './regexp/index';
  6. import { startTransaction, runTransaction } from './transaction/index';
  7. import { ObjectIdConstructor } from './ObjectId/index';
  8. export { Query } from './query';
  9. export { CollectionReference } from './collection';
  10. export { DocumentReference } from './document';
  11. export class Db {
  12. constructor(config) {
  13. this.config = config;
  14. this.Geo = Geo;
  15. this.serverDate = ServerDateConstructor;
  16. this.command = Command;
  17. this.RegExp = RegExpConstructor;
  18. this.ObjectId = ObjectIdConstructor;
  19. this.startTransaction = startTransaction;
  20. this.runTransaction = runTransaction;
  21. }
  22. collection(collName) {
  23. if (!collName) {
  24. throw new Error('Collection name is required');
  25. }
  26. return new CollectionReference(this, collName);
  27. }
  28. createCollection(collName) {
  29. let request = new Db.reqClass(this.config);
  30. const params = {
  31. collectionName: collName
  32. };
  33. return request.send('database.addCollection', params);
  34. }
  35. }