How to use the sequelize.Op.or 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 uuchat / uuchat / src / server / controllers / shortcutController.js View on Github external
shortcutController.listAll = function (req, res, next) {
    var csid = req.params.csid || '';

    if (!csid) return res.json({code: 9000, msg: 'csid_null'});

    var condition = {
        [Op.or]: [
            getCondition(''),
            getCondition(csid)
        ]
    };
    var attributes = ['id', 'type', 'shortcut', 'msg'];

    Shortcut.listAll(attributes, condition, function (err, data) {
        if (err) return next(err);

        // remove repeat shortcut
        var msg = _.uniqBy(_.orderBy(data, ['type'], ['desc']), 'shortcut');

        // remove property:type
        msg = _.map(msg, function (item) {
            return _.omit(item, 'type');
        });
github RiseVision / rise-node / packages / core-transactions / src / api / httpApi.ts View on Github external
const orBody = {};
    Object.keys(body)
      .filter((what) => !what.startsWith('and:'))
      .forEach((k) => (orBody[k] = body[k]));
    const orWhereClause = this.createWhereClause(orBody);

    let orderBy;
    if (body.orderBy) {
      orderBy = [body.orderBy.split(':')];
    }

    const where = removeEmptyObjKeys(
      { ...andWhereClause, [Op.or]: orWhereClause },
      true
    );
    if (Object.keys(where[Op.or]).length === 0) {
      delete where[Op.or];
    }
    const { rows: transactions, count } = await this.TXModel.findAndCountAll({
      limit: body.limit || 100,
      offset: body.offset || 0,
      order: orderBy,
      raw: true,
      where,
    });
    // Reattach transactions asset
    await this.txLogic.attachAssets(transactions);

    return {
      count,
      transactions: transactions.map((t) =>
        this.TXModel.toTransportTransaction(t)
github maoxiaoquan / kite / server / controllers / client / upload.js View on Github external
static async uploadUserAvatar (ctx) {
    try {
      await upload('avatarImg').single('file')(ctx)
      if (ctx.req.file) {
        let destination = ctx.req.file.destination.split('static')[1]
        let filename = ctx.req.file.filename
        let origin = ctx.request.header.origin
        let { user = '' } = ctx.request

        let userRoleAll = await models.user_role.findAll({
          where: {
            user_role_id: {
              [Op.or]: user.user_role_ids.split(',')
            },
            user_role_type: 1 // 用户角色类型1是默认角色
          }
        })
        let userAuthorityIds = ''
        userRoleAll.map(roleItem => {
          userAuthorityIds += roleItem.user_authority_ids + ','
        })
        let message = ''
        if (~userAuthorityIds.indexOf(config.USER.dfUserAvatarNoReviewId)) {
          message = '上传用户头像成功'
          await models.user.update(
            {
              avatar: `${origin}${destination}/${filename}`
            },
            {
github smileShirmy / smile-blog-koa / app / dao / article.js View on Github external
let query = {
      category_id: categoryId === 0 ? undefined : categoryId,
      status: statusId === 0 ? undefined : statusId,
      public: publicId === 0 ? undefined : publicId,
      star: starId === 0 ? undefined : starId
    }

    // 忽略值为空的key
    let target = omitBy(query, isUndefined)
    let opIn = ids.length ? {
      id: {
        [Op.in]: ids
      }
    } : {}
    let like = search ? {
      [Op.or]: [
        {
          title: {
            [Op.like]: `${search}%`,
          }
        },
        {
          content: {
            [Op.like]: `${search}%`,
          }
        }
      ]
    } : {}

    // step3: 构建查询条件
    const where = {
      ...target,
github opencollective / opencollective-api / server / models / PaymentMethod.js View on Github external
// Independently of the balance of the external source, the owner of the payment method
    // may have set up a monthlyLimitPerMember or an initialBalance
    if (!this.initialBalance && (!this.monthlyLimitPerMember || (user && user.isAdmin(this.CollectiveId)))) {
      return { amount: balanceAmount, currency: this.currency };
    }

    let limit = Infinity; // no no, no no no no, no no no no limit!
    const query = {
      where: { type: TransactionTypes.DEBIT },
      include: [
        {
          model: models.PaymentMethod,
          require: true,
          attributes: [],
          where: { [Op.or]: { id: this.id, SourcePaymentMethodId: this.id } },
        },
      ],
    };

    if (this.monthlyLimitPerMember) {
      limit = this.monthlyLimitPerMember;
      const d = new Date();
      const firstOfTheMonth = new Date(d.getFullYear(), d.getMonth(), 1);
      query.where.createdAt = { [Op.gte]: firstOfTheMonth };
      query.where.CreatedByUserId = user.id;
    }

    if (this.initialBalance) {
      limit = this.initialBalance > limit ? limit : this.initialBalance;
    }
github thx / rap2-delos / src / routes / repository.ts View on Github external
if (access === false) {
      ctx.body = {
        isOk: false,
        errMsg: Consts.COMMON_MSGS.ACCESS_DENY
      }
      return
    }
  }

  // tslint:disable-next-line:no-null-keyword
  if (user) Object.assign(where, { ownerId: user, organizationId: null })
  if (organization) Object.assign(where, { organizationId: organization })
  if (name) {
    Object.assign(where, {
      [Op.or]: [
        { name: { [Op.like]: `%${name}%` } },
        { id: name } // name => id
      ]
    })
  }
  let total = await Repository.count({
    where,
    include: [
      QueryInclude.Creator,
      QueryInclude.Owner,
      QueryInclude.Locker,
    ],
  } as any)
  let pagination = new Pagination(total, ctx.query.cursor || 1, ctx.query.limit || 100)
  let repositories = await Repository.findAll({
    where,
github opencollective / opencollective-api / server / models / User.js View on Github external
User.findByEmailOrPaypalEmail = email => {
    return User.findOne({
      where: {
        [Op.or]: {
          email,
          paypalEmail: email,
        },
      },
    });
  };
github connect-foundation / 2019-06 / server / src / v1 / mail / search / service.js View on Github external
let { page, perPageNum } = queryOptions;

  page = +page;
  perPageNum = +perPageNum;

  const wastebasketNo = await getWastebasketCategoryNo(userNo);
  const query = getQueryByOptions({
    userNo,
    perPageNum,
    page,
    sort,
    wastebasketNo,
  });

  query.mailTemplateFilter = {
    [Op.or]: [
      { subject: { [Op.substring]: searchWord } },
      { text: { [Op.substring]: searchWord } },
    ],
  };

  const pagingAndMails = await getPagingInfoAndMails({ page, perPageNum, query });
  return pagingAndMails;
};
github ArkEcosystem / core / app / database / sequelize / repositories / transactions.js View on Github external
findAllByWallet (wallet, paginator) {
    return this.findAll({
      ...{
        [Op.or]: [{
          senderPublicKey: wallet.publicKey
        }, {
          recipientId: wallet.address
        }]
      },
      ...paginator
    })
  }

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 6 days ago

Package Health Score

95 / 100
Full package analysis