WhereJsonHasPostgresOperation.js 596 B

123456789101112131415161718192021
  1. const jsonApi = require('./postgresJsonApi');
  2. const ObjectionToKnexConvertingOperation = require('../ObjectionToKnexConvertingOperation');
  3. class WhereJsonHasPostgresOperation extends ObjectionToKnexConvertingOperation {
  4. onBuildKnex(knexBuilder, builder) {
  5. const sql = jsonApi.whereJsonFieldRightStringArrayOnLeftQuery(
  6. builder.knex(),
  7. this.args[0],
  8. this.opt.operator,
  9. this.args[1]
  10. );
  11. if (this.opt.bool === 'or') {
  12. knexBuilder.orWhereRaw(sql);
  13. } else {
  14. knexBuilder.whereRaw(sql);
  15. }
  16. }
  17. }
  18. module.exports = WhereJsonHasPostgresOperation;