index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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. export { Query } from './query';
  8. export { CollectionReference } from './collection';
  9. export { DocumentReference } from './document';
  10. export class Db {
  11. constructor(config) {
  12. this.config = config;
  13. this.Geo = Geo;
  14. this.serverDate = ServerDateConstructor;
  15. this.command = Command;
  16. this.RegExp = RegExpConstructor;
  17. this.startTransaction = startTransaction;
  18. this.runTransaction = runTransaction;
  19. }
  20. collection(collName) {
  21. if (!collName) {
  22. throw new Error('Collection name is required');
  23. }
  24. return new CollectionReference(this, collName);
  25. }
  26. createCollection(collName) {
  27. let request = new Db.reqClass(this.config);
  28. const params = {
  29. collectionName: collName
  30. };
  31. return request.send('database.addCollection', params);
  32. }
  33. }