collection.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = function (d, b) {
  3. extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return extendStatics(d, b);
  7. };
  8. return function (d, b) {
  9. extendStatics(d, b);
  10. function __() { this.constructor = d; }
  11. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  12. };
  13. })();
  14. import { DocumentReference } from './document';
  15. import { Query } from './query';
  16. var CollectionReference = (function (_super) {
  17. __extends(CollectionReference, _super);
  18. function CollectionReference(transaction, coll) {
  19. return _super.call(this, transaction, coll) || this;
  20. }
  21. Object.defineProperty(CollectionReference.prototype, "name", {
  22. get: function () {
  23. return this._coll;
  24. },
  25. enumerable: true,
  26. configurable: true
  27. });
  28. CollectionReference.prototype.doc = function (docID) {
  29. if (typeof docID !== 'string' && typeof docID !== 'number') {
  30. throw new Error('docId必须为字符串或数字');
  31. }
  32. return new DocumentReference(this._transaction, this._coll, docID);
  33. };
  34. CollectionReference.prototype.add = function (data) {
  35. var docID;
  36. if (data._id !== undefined) {
  37. docID = data._id;
  38. }
  39. var docRef = new DocumentReference(this._transaction, this._coll, docID);
  40. return docRef.create(data);
  41. };
  42. return CollectionReference;
  43. }(Query));
  44. export { CollectionReference };