How to use the @nozbe/watermelondb.Q.sanitizeLikeString function in @nozbe/watermelondb

To help you get started, we’ve selected a few @nozbe/watermelondb 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 RocketChat / Rocket.Chat.ReactNative / app / lib / rocketchat.js View on Github external
async search({ text, filterUsers = true, filterRooms = true }) {
		const searchText = text.trim();

		if (this.oldPromise) {
			this.oldPromise('cancel');
		}

		if (searchText === '') {
			delete this.oldPromise;
			return [];
		}

		const db = database.active;
		let data = await db.collections.get('subscriptions').query(
			Q.where('name', Q.like(`%${ Q.sanitizeLikeString(searchText) }%`))
		).fetch();

		if (filterUsers && !filterRooms) {
			data = data.filter(item => item.t === 'd');
		} else if (!filterUsers && filterRooms) {
			data = data.filter(item => item.t !== 'd');
		}
		data = data.slice(0, 7);

		const usernames = data.map(sub => sub.name);
		try {
			if (data.length < 7) {
				const { users, rooms } = await Promise.race([
					RocketChat.spotlight(searchText, usernames, { users: filterUsers, rooms: filterRooms }),
					new Promise((resolve, reject) => this.oldPromise = reject)
				]);
github Nozbe / WatermelonDB / examples / web / src / components / BlogList / index.js View on Github external
withObservables(['search'], ({ database, search }) => ({
    blogs: database.collections
      .get('blogs')
      .query(Q.where('name', Q.like(`%${Q.sanitizeLikeString(search)}%`))),
  })),
  withStateHandlers(