How to use the knex.Promise.all function in knex

To help you get started, we’ve selected a few knex examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Vincit / objection.js / src / queryBuilder / GraphInserter.js View on Github external
_executeNextBatch(inserter) {
    let batch = this._nextBatch();

    if (!batch) {
      // If we get here, we are done. All we need to do now is to finalize the object graph
      // and return it as the final output.
      return this._finalize();
    }

    // Insert the batch using the `inserter` function.
    return Promise.all(_.map(batch, tableInsertion => {
      let uids;

      if (!tableInsertion.isJoinTableInsertion) {
        // We need to omit the uid properties so that they don't get inserted
        // into the database. Join table insertions never have uids.
        uids = this._omitUids(tableInsertion);
      }

      return inserter(tableInsertion).then(() => {
        if (!tableInsertion.isJoinTableInsertion) {
          // Resolve dependencies to the inserted objects.
          this._resolveDepsForInsertion(tableInsertion, uids);
        }
      });
    })).then(() => this._executeNextBatch(inserter));
  }
github Vincit / objection.js / tests / integration / find.js View on Github external
it('should return all related rows when no knex methods are chained', function () {
          return Promise.all([
            parent1
              .$relatedQuery('model2Relation1')
              .orderBy('id')
              .then(function (related) {
                expect(related.length).to.equal(3);
                expect(parent1.model2Relation1).to.eql(related);
                expect(related[0]).to.be.a(Model1);
                expect(related[1]).to.be.a(Model1);
                expect(related[2]).to.be.a(Model1);
                expect(_.map(related, 'model1Prop1').sort()).to.eql(['blaa 1', 'blaa 2', 'blaa 3']);
                expect(_.map(related, 'extra3').sort()).to.eql([null, null, null]);
                expect(related[0]).to.eql({
                  id: 3,
                  model1Id: null,
                  model1Prop1: 'blaa 1',
                  model1Prop2: 6,
github Vincit / objection.js / tests / integration / jsonQueries.js View on Github external
1,
          "string in jsonArray[3]",
          false,
          [
            { noMoreLevels: true },
            null,
            1,
            "string in jsonArray[5][3]",
            true
          ]
        ]
      };

      complexJsonObj.jsonObject.jsonArray = _.cloneDeep(complexJsonObj.jsonArray);

      return Promise
        .all([
          BoundModel.query().insert(complexJsonObj),
          BoundModel.query().insert({ id:2, name: "empty object and array", jsonObject: {}, jsonArray: [] }),
          BoundModel.query().insert({ id:3, name: "null object and array"}),
          BoundModel.query().insert({ id:4, name: "empty object and [1,2]",   jsonObject: {}, jsonArray: [1,2] }),
          BoundModel.query().insert({ id:5, name: "empty object and array [ null ]",   jsonObject: {}, jsonArray: [ null ] }),
          BoundModel.query().insert({ id:6, name: "{a: 1} and empty array", jsonObject: {a: 1}, jsonArray: [] }),
          BoundModel.query().insert({
            id: 7,
            name: "{a: {1:1, 2:2}, b:{2:2, 1:1}} for equality comparisons",
            jsonObject: {a: {1:1, 2:2}, b:{2:2, 1:1}}, jsonArray: []
          })
        ]);
    });