How to use the sequelize.Op.gte function in sequelize

To help you get started, we’ve selected a few sequelize 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 opencollective / opencollective-api / server / models / Collective.js View on Github external
query.attributes = attributes;
    }

    // Hide expenses transactions on demand
    if (includeExpenseTransactions === false) {
      query.where.ExpenseId = null;
    }

    // Filter on host
    if (HostCollectiveId) {
      query.where.HostCollectiveId = HostCollectiveId;
    }

    // Filter on date
    if (startDate && endDate) {
      query.where.createdAt = { [Op.gte]: startDate, [Op.lt]: endDate };
    } else if (startDate) {
      query.where.createdAt = { [Op.gte]: startDate };
    } else if (endDate) {
      query.where.createdAt = { [Op.lt]: endDate };
    }

    // Filter on type
    if (type) query.where.type = type;

    // Pagination
    if (limit) query.limit = limit;
    if (offset) query.offset = offset;

    // OrderBy
    if (order) query.order = order;
github RiseVision / rise-node / src / apis / transactions.ts View on Github external
whereClause.timestamp[Op.gte] = body.fromTimestamp;

    whereClause.type[Op.eq] = body.type;

    // Computed stuff
    if (body.minConfirmations) {
      whereClause.height[Op.lte] = Math.min(
        Number.isInteger(whereClause.height[Op.lte]) ? whereClause.height[Op.lte] : Number.MAX_SAFE_INTEGER,
        this.blocksModule.lastBlock.height - body.minConfirmations
      );
    }

    if (body.fromUnixTime) {
      whereClause.timestamp[Op.gte] = Math.max(
        this.slots.getTime(body.fromUnixTime),
        Number.isInteger(whereClause.timestamp[Op.gte]) ? whereClause.timestamp[Op.gte] : 0
      );
    }
    if (body.toUnixTime) {
      whereClause.timestamp[Op.lte] = Math.min(
        this.slots.getTime(body.toUnixTime),
        Number.isInteger(whereClause.timestamp[Op.lte]) ? whereClause.timestamp[Op.lte] : 0
      );
    }

    if (Array.isArray(body.senderIds)) {
      whereClause.senderId = { [Op.in]: body.senderIds.map((item) => item.toUpperCase()) };
      if (body.senderId) {
        whereClause.senderId[Op.in].push(body.senderId.toUpperCase());
      }
    }
github RiseVision / rise-node / packages / core-transactions / src / api / httpApi.ts View on Github external
whereClause.timestamp[Op.gte] = body.fromTimestamp;

    whereClause.type[Op.eq] = body.type;

    // Computed stuff
    if (body.minConfirmations) {
      whereClause.height[Op.lte] = Math.min(
        Number.isInteger(whereClause.height[Op.lte])
          ? whereClause.height[Op.lte]
          : Number.MAX_SAFE_INTEGER,
        this.blocksModule.lastBlock.height - body.minConfirmations
      );
    }

    if (body.fromUnixTime) {
      whereClause.timestamp[Op.gte] = Math.max(
        this.timeToEpoch.getTime(body.fromUnixTime * 1000),
        Number.isInteger(whereClause.timestamp[Op.gte])
          ? whereClause.timestamp[Op.gte]
          : 0
      );
    }
    if (body.toUnixTime) {
      whereClause.timestamp[Op.lte] = Math.min(
        this.timeToEpoch.getTime(body.toUnixTime * 1000),
        Number.isInteger(whereClause.timestamp[Op.lte])
          ? whereClause.timestamp[Op.lte]
          : Number.MAX_SAFE_INTEGER
      );
    }

    if (Array.isArray(body.senderIds)) {
github RiseVision / rise-node / tests / unit / modules / blocks / utils.spec.ts View on Github external
it('should allow specify start time in unix timestamp', async () => {
      const constants = container.get(Symbols.helpers.constants);
      await inst.aggregateBlockReward({
        generatorPublicKey: 'aabb',
        start             : Math.floor(constants.epochTime.getTime() / 1000 + 1000),
      });
      expect(findOneStub.called).is.true;
      expect(findOneStub.firstCall.args[0]).to.be.deep.eq({
        attributes: [ {val: 'COUNT(1)'}, {val: 'SUM("reward") as rewards' }],
        raw: true,
        where: {
          generatorPublicKey: Buffer.from('aabb', 'hex'),
          timestamp: { [Op.gte]: 1000},
        },
      });
      expect(findOneStub.firstCall.args[0].where.timestamp[Op.gte]).eq(1000);
    });
    it('should allow specify end time in unix timestamp', async () => {
github salesforce / refocus / tests / api / v1 / globalconfig / utils.js View on Github external
forceDelete(done, startTime=testStartTime) {
    tu.db.GlobalConfig.destroy({
      where: {
        key: {
          [Op.iLike]: tu.namePrefix + '%',
        },
        createdAt: {
          [Op.lt]: new Date(),
          [Op.gte]: startTime,
        },
      },
      force: true,
    })
    .then(() => tu.forceDelete(tu.db.User, startTime))
    .then(() => tu.forceDelete(tu.db.Token, startTime))
    .then(() => done())
    .catch(done);
  },
};
github salesforce / refocus / tests / db / model / event / utils.js View on Github external
forceDelete(done) {
    tu.db.Event.destroy({
      where: {
        createdAt: {
          [Op.lt]: new Date(),
          [Op.gte]: testStartTime,
        },
      },
      force: true,
    })
    .then(() => tu.forceDelete(tu.db.BotData, testStartTime))
    .then(() => tu.forceDelete(tu.db.BotAction, testStartTime))
    .then(() => tu.forceDelete(tu.db.Bot, testStartTime))
    .then(() => tu.forceDelete(tu.db.Room, testStartTime))
    .then(() => tu.forceDelete(tu.db.RoomType, testStartTime))
    .then(() => done())
    .catch(done);
  },
};
github connect-foundation / 2019-06 / server / src / v1 / mail / search / service.js View on Github external
query.mailTemplateFilter.from = {
      [Op.substring]: from,
    };
  }

  if (to) {
    query.mailTemplateFilter.to = {
      [Op.substring]: to,
    };
  }

  if (startDate) {
    const date = new Date(...startDate.split('/'));
    date.setMonth(date.getMonth() - 1);
    query.mailTemplateFilter.createdAt = {
      [Op.gte]: date,
    };
  }

  if (endDate) {
    const date = new Date(...endDate.split('/'));
    date.setMonth(date.getMonth() - 1);
    date.setDate(date.getDate() + 1);
    query.mailTemplateFilter.createdAt = {
      ...query.mailTemplateFilter.createdAt,
      [Op.lt]: date,
    };
  }

  return query;
};
github RiseVision / rise-node / packages / core-transactions / src / api / httpApi.ts View on Github external
private createWhereClause(body: any) {
    const whereClause = {
      amount: {},
      blockId: {},
      height: {},
      recipientId: {},
      senderId: {},
      senderPubData: {},
      timestamp: {},
      type: {},
    };
    whereClause.amount[Op.lte] = body.maxAmount;
    whereClause.amount[Op.gte] = body.minAmount;

    whereClause.blockId[Op.eq] = body.blockId;

    whereClause.height[Op.gte] = body.fromHeight;
    whereClause.height[Op.lte] = body.toHeight;

    whereClause.recipientId[Op.eq] = body.recipientId;

    whereClause.senderId[Op.eq] = body.senderId;

    whereClause.senderPubData[Op.eq] = body.senderPubData
      ? Buffer.from(body.senderPubData, 'hex')
      : undefined;

    whereClause.timestamp[Op.lte] = body.toTimestamp;
    whereClause.timestamp[Op.gte] = body.fromTimestamp;
github birkir / prime / packages / prime-core / src / utils / processWhereQuery.ts View on Github external
import { Op } from 'sequelize';

const logicalOperators = {
  OR: Op.or,
  AND: Op.and,
};

const compareOperators = {
  eq: Op.eq,
  neq: Op.ne,
  gt: Op.gt,
  gte: Op.gte,
  lt: Op.lt,
  lte: Op.lte,
};

function formatCompareOperators(obj): any {
  return Object.entries(obj).reduce((acc, [key, val]: [string, object]) => {
    if (compareOperators[key]) {
      acc[compareOperators[key]] = val;
    } else {
      acc[key] = val;
    }

    return acc;
  }, {});
}
github dengue8830 / node-seed / src / common / connection.ts View on Github external
import { CommonUtil } from './utils/common.util';
import { Sequelize, Op } from 'sequelize';
import { logger } from './logger';
import * as sqlFormatter from 'sql-formatter';
import { config } from './config';

const bd = config.getBd();

const operatorsAliases = {
  $eq: Op.eq,
  $ne: Op.ne,
  $gte: Op.gte,
  $gt: Op.gt,
  $lte: Op.lte,
  $lt: Op.lt,
  $not: Op.not,
  $in: Op.in,
  $notIn: Op.notIn,
  $is: Op.is,
  $like: Op.like,
  $notLike: Op.notLike,
  $iLike: Op.iLike,
  $notILike: Op.notILike,
  $regexp: Op.regexp,
  $notRegexp: Op.notRegexp,
  $iRegexp: Op.iRegexp,
  $notIRegexp: Op.notIRegexp,
  $between: Op.between,

sequelize

Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Amazon Redshift and Snowflake’s Data Cloud. It features solid transaction support, relations, eager and lazy loading, read replication and more.

MIT
Latest version published 28 days ago

Package Health Score

95 / 100
Full package analysis