How to use the sequelize.Op.iLike 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 salesforce / refocus / tests / api / v1 / users / patch.js View on Github external
before((done) => {
      let adminProfileId = '';
      User.findOne({
        where: {
          name: {
            [Op.iLike]: OBAdminUser.name,
          },
        },
      })
      .then((OBAdminUser) => adminProfileId = OBAdminUser.profileId)

      // create a normal user
      .then(() => User.create({
        profileId: profileOneId,
        name: userZero,
        email: userZero,
        password: userZero,
      }))

      // create a normal user
      .then(() => User.create({
        profileId: profileOneId,
github salesforce / refocus / api / v1 / controllers / userTokens.js View on Github external
function whereClauseForUser(userNameOrId) {
  const whr = {};
  if (u.looksLikeId(userNameOrId)) {
    /*
     * need to use '$table.field$' for association fields. User IDs in the url
     * are case-sensitve.
     */
    whr.where = { '$user.id$': {} };
    whr.where['$user.id$'] = userNameOrId;
  } else {
    whr.where = { '$user.name$': {} };
    whr.where['$user.name$'][Op.iLike] = userNameOrId;
  }

  return whr;
} // whereClauseForUser
github salesforce / refocus / api / v1 / helpers / verbs / findUtils.js View on Github external
if (optsWhereOR && Array.isArray(optsWhereOR)) { // multiple values
      let isWildCardExp = false;
      optsWhereOR.forEach((orObj) => {
        if (orObj[Op.iLike] &&
         orObj[Op.iLike].indexOf('%') > MINUS_ONE) {
          isWildCardExp = true;
        }
      });

      if (!isWildCardExp) { // if no wildcard value, set limit to no. of values
        opts.limit = optsWhereOR.length;
      }
    }

    // single value
    const optsWhereFieldLike = opts.where[uniqueFieldName][Op.iLike];
    if (optsWhereFieldLike && optsWhereFieldLike.indexOf('%') < ZERO) {
      opts.limit = 1; // set limit to 1 if no wildcard value
    }
  }
}
github salesforce / refocus / tests / api / v1 / samples / patch.js View on Github external
.then((samp) => {
        const subjectName = samp.name.split('|')[0].toLowerCase();
        return Subject.findOne({ where: { name: { [Op.iLike]: subjectName } } });
      })
      .then((sub) => {
github salesforce / refocus / tests / api / v1 / botData / deleteWithoutPerms.js View on Github external
.then((botData) => {
      testBotData = botData;
      return BotData.findOne({ where: { name: { [Op.iLike]: testBotData.name } } });
    })
    .then((rt) => rt.addWriters(user))
github salesforce / refocus / tests / db / model / profile / admin.js View on Github external
before((done) => {
    Profile.findOne({
      where: {
        name: {
          [Op.iLike]: conf.db.adminProfile.name,
        },
      },
    })
    .then((found) => {
      ap = found;
      done();
    });
  });
github salesforce / refocus / tests / db / model / sample / upsert.js View on Github external
setTimeout(() => {
          Sample.findOne({
            where: {
              name: {
                [Op.iLike]: updatedSubjectName + '|' + aspectName,
              },
            },
          })
          .then((sample) => {
            expect(sample).to.equal(null);
            done();
          });
        }, 500);
      })
github salesforce / refocus / tests / db / model / sample / timeout.js View on Github external
.then(() => Sample.findAll({
      where: {
        name: {
          [Op.iLike]: `${tu.namePrefix}Subject|%`,
        },
      },
    })
    .each((s) => {
      switch (s.name) {
        case `${tu.namePrefix}Subject|${tu.namePrefix}OneSecond`:
          expect(s.status).to.equal(defaultForStatus);
          break;
        case `${tu.namePrefix}Subject|${tu.namePrefix}TwoMinutes`:
          expect(s.status).to.equal(defaultForStatus);
          break;
        case `${tu.namePrefix}Subject|${tu.namePrefix}ThreeHours`:
          expect(s.status).to.equal(defaultForStatus);
          break;
        case `${tu.namePrefix}Subject|${tu.namePrefix}NinetyDays`:
          expect(s.status).to.not.equal(defaultForStatus);
github pubpub / pubpub / server / user / queries.js View on Github external
export const createUser = (inputValues) => {
	const email = inputValues.email.toLowerCase().trim();
	const firstName = inputValues.firstName.trim();
	const lastName = inputValues.lastName.trim();
	const fullName = `${firstName} ${lastName}`;
	const initials = `${firstName[0]}${lastName[0]}`;
	const newSlug = slugifyString(fullName);
	return User.count({
		where: {
			slug: { [Op.iLike]: `${newSlug}%` },
		},
	})
		.then((existingSlugCount) => {
			const newUser = {
				slug: `${newSlug}${existingSlugCount ? `-${existingSlugCount + 1}` : ''}`,
				firstName: firstName,
				lastName: lastName,
				fullName: fullName,
				initials: initials,
				email: email,
				avatar: inputValues.avatar,
				title: inputValues.title,
				bio: inputValues.bio,
				location: inputValues.location,
				website: inputValues.website,
				orcid: inputValues.orcid,
github salesforce / refocus / db / utils.js View on Github external
function initializeAdminUserAndProfile() {
  const profileFinder = {
    where: { name: { [Op.iLike]: conf.db.adminProfile.name } },
  };
  const userFinder = {
    where: {
      name: {
        [Op.iLike]: conf.db.adminUser.name,
      },
    },
  };
  let pid;
  return seq.models.Profile.upsert(conf.db.adminProfile)
  .then(() => seq.models.Profile.findOne(profileFinder))
  .then((profile) => {
    pid = profile.id;
    return seq.models.User.findOne(userFinder);
  })
  .then((u) => {

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