collection.js 1.8 KB

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