@pbvision/firestore-orm 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/models.js +21 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pbvision/firestore-orm",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "Firestore ORM Library",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/src/models.js CHANGED
@@ -61,6 +61,27 @@ export class Model {
61
61
  Object.seal(this)
62
62
  }
63
63
 
64
+ /** Returns a query object for querying this model. */
65
+ static makeQuery () {
66
+ return Key.firestoreDB.collection(this.collectionName)
67
+ }
68
+
69
+ /**
70
+ * Runs a query object returned by this model's makeQuery() function.
71
+ * @returns {Array<Model>} returns an array of instances of this class that
72
+ * matched the query
73
+ */
74
+ static async runQuery (query) {
75
+ const results = await query.get()
76
+ const ret = []
77
+ results.forEach(raw => {
78
+ const vals = raw.data()
79
+ vals.__id = raw.id
80
+ ret.push(new this(false, vals))
81
+ })
82
+ return ret
83
+ }
84
+
64
85
  static async register (registrar) {
65
86
  this.__doOneTimeModelPrep()
66
87
  await registrar.registerModel(this)