How to use the sequelize.Op.in 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 RiseVision / rise-node / src / apis / transportv2API.ts View on Github external
// Remove quotes
      .replace(/['"]+/g, '')
      // Separate by comma into an array
      .split(',')
      // Reject any non-numeric values
      .filter((id) => /^[0-9]+$/.test(id));
    if (excapedIds.length === 0 || excapedIds.length > 10) {
      this.peersModule.remove(req.ip, parseInt(req.headers.port as string, 10));
      throw new APIError('Invalid block id sequence', 200);
    }

    const common     = await this.BlocksModel.findOne({
      limit: 1,
      order: [['height', 'DESC']],
      raw  : true,
      where: { id: { [Op.in]: excapedIds } },
    });

    const tmpPB = this.pblocksFactory({data: {block: common}});
    const bytesBlock = common !== null ? tmpPB.generateBytesBlock(common) : null;
    return this.getResponse({ common: bytesBlock }, 'transportBlocks', 'commonBlock');
  }
github opencollective / opencollective-api / cron / daily / 10-backyourstack-dispatch-subscriptions.js View on Github external
console.log('Could not find any matching tiers.');
    process.exit(1);
  }

  const tierIds = tiers.map(tier => tier.id);

  const allOrders = await models.Order.findAll({
    where: {
      status: status.ACTIVE,
      SubscriptionId: { [Op.ne]: null },
      deletedAt: null,
    },
    include: [
      {
        model: models.Tier,
        where: { id: { [Op.in]: tierIds } },
      },
      { model: models.Collective, as: 'fromCollective' },
      { model: models.User, as: 'createdByUser' },
      { model: models.Collective, as: 'collective' },
      {
        model: models.Subscription,
        where: {
          isActive: true,
          deletedAt: null,
          deactivatedAt: null,
        },
      },
    ],
  });

  return filter(allOrders, order => {
github pubpub / pubpub / tools / 5to6 / interim / interimMigration.js View on Github external
.then(([hdsrPubIds]) => {
		console.log('hi', hdsrPubIds);
		const findBranches = v6_Branch.findAll({
			where: {
				pubId: { [Op.in]: hdsrPubIds },
			},
		});
		const findBranchPermissions = v6_BranchPermission.findAll({
			where: {
				pubId: { [Op.in]: hdsrPubIds },
			},
		});
		const findMerges = v6_Merge.findAll({
			where: {
				pubId: { [Op.in]: hdsrPubIds },
			},
		});
		return Promise.all([findBranches, findBranchPermissions, findMerges]);
	})
	.then(([branches, branchPermissions, merges]) => {
github turt2live / matrix-dimension / src / api / controllers / TermsController.ts View on Github external
public async signTermsMatching(user: IMSCUser, urls: string[]): Promise {
        const terms = await TermsTextRecord.findAll({where: {url: {[Op.in]: urls}}});
        const signed = await TermsSignedRecord.findAll({where: {userId: user.userId}});

        const toAdd = terms.filter(t => !signed.find(s => s.termsId === t.termsId));
        for (const termsToSign of toAdd) {
            await TermsSignedRecord.create({termsId: termsToSign.id, userId: user.userId});
        }
    }
github dengue8830 / node-seed / src / common / connection.ts View on Github external
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,
  $notBetween: Op.notBetween,
  $overlap: Op.overlap,
  $contains: Op.contains,
  $contained: Op.contained,
  $adjacent: Op.adjacent,
github RiseVision / rise-node / src / apis / transactions.ts View on Github external
if (body.senderId) {
        whereClause.senderId[Op.in].push(body.senderId.toUpperCase());
      }
    }

    if (Array.isArray(body.recipientIds)) {
      whereClause.recipientId = { [Op.in]: body.recipientIds.map((item) => item.toUpperCase()) };
      if (body.recipientId) {
        whereClause.recipientId[Op.in].push(body.recipientId.toUpperCase());
      }
    }

    if (Array.isArray(body.senderPublicKeys)) {
      whereClause.senderPublicKey = { [Op.in]: body.senderPublicKeys.map((pk) => Buffer.from(pk, 'hex')) };
      if (body.senderPublicKey) {
        whereClause.senderPublicKey[Op.in].push(Buffer.from(body.senderPublicKey, 'hex'));
      }
    }

    removeEmptyObjKeys(whereClause, true);
    for (const k in whereClause) {
      if (Object.keys(whereClause[k]).length === 0 && Object.getOwnPropertySymbols(whereClause[k]).length === 0) {
        delete whereClause[k];
      }
    }
    return whereClause;
  }
github smileShirmy / smile-blog-koa / app / dao / articleAuthor.js View on Github external
async getArticleAuthor(articleId, options = {}) {
    const result = await ArticleAuthor.findAll({
      where: {
        article_id: articleId
      }
    })
    let ids = result.map(v => v.author_id)
    return await Author.findAll({
      where: {
        id: {
          [Op.in]: ids
        }
      },
      ...options
    })
  }
github salesforce / refocus / db / helpers / generatorUtil.js View on Github external
function validateGeneratorNames(seq, generatorNames) {
  if (!generatorNames || !generatorNames.length) {
    return Promise.resolve([]);
  }

  if (common.checkDuplicatesInStringArray(generatorNames)) {
    throw new dbErrors.DuplicateGeneratorError({
      resourceType: 'Generator',
      resourceKey: generatorNames,
    });
  }

  if (!generatorNames || !generatorNames.length) return [];

  return seq.models.Generator.findAll({
    where: { name: { [Op.in]: generatorNames } },
  })
  .then((generators) => {
    if (generators.length === generatorNames.length) {
      return generators;
    } else {
      throw new dbErrors.ResourceNotFoundError({
        resourceType: 'Generator',
        resourceKey: generatorNames,
      });
    }
  });
}
github opencollective / opencollective-api / server / models / Notification.js View on Github external
const getUsers = memberships => {
      if (!memberships || memberships.length === 0) return [];
      return models.User.findAll({
        where: {
          CollectiveId: { [Op.in]: memberships.map(m => m.MemberCollectiveId) },
        },
      });
    };
github opencollective / opencollective-api / server / models / Tier.js View on Github external
Tier.appendTier = (collective, backerCollectives) => {
    const backerCollectivesIds = backerCollectives.map(b => b.id);
    debug('appendTier', collective.name, 'backers: ', backerCollectives.length);
    return models.Member.findAll({
      where: {
        MemberCollectiveId: { [Op.in]: backerCollectivesIds },
        CollectiveId: collective.id,
      },
      include: [{ model: models.Tier }],
    }).then(memberships => {
      const membershipsForBackerCollective = {};
      memberships.map(m => {
        membershipsForBackerCollective[m.MemberCollectiveId] = m.Tier;
      });
      return backerCollectives.map(backerCollective => {
        backerCollective.tier = membershipsForBackerCollective[backerCollective.id];
        debug('appendTier for', backerCollective.name, ':', backerCollective.tier && backerCollective.tier.slug);
        return backerCollective;
      });
    });
  };

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

Package Health Score

95 / 100
Full package analysis