VibORM
Filtering

String Filters

Filter operators for string fields

String Filters

Filter operators available for string fields.

Operators

OperatorDescription
equalsExact match
notNot equal
inMatch any in array
notInMatch none in array
containsContains substring
startsWithStarts with prefix
endsWithEnds with suffix
modeCase sensitivity

equals / not

// Exact match
where: { email: "alice@example.com" }
where: { email: { equals: "alice@example.com" } }

// Not equal
where: { email: { not: "admin@example.com" } }

// Not with nested conditions
where: { email: { not: { contains: "spam" } } }

in / notIn

// Match any
where: { role: { in: ["ADMIN", "MODERATOR"] } }

// Match none
where: { status: { notIn: ["BANNED", "SUSPENDED"] } }

contains

// Contains substring
where: { name: { contains: "alice" } }

// Case insensitive
where: { name: { contains: "alice", mode: "insensitive" } }

startsWith / endsWith

// Starts with
where: { email: { startsWith: "admin" } }

// Ends with
where: { email: { endsWith: "@company.com" } }

// Case insensitive
where: { email: { endsWith: "@company.com", mode: "insensitive" } }

mode (Case Sensitivity)

// Default: case sensitive
where: { name: { contains: "Alice" } }

// Case insensitive
where: { name: { contains: "alice", mode: "insensitive" } }

PostgreSQL uses ILIKE for insensitive mode. MySQL uses collation settings.

Combined Example

// Search with multiple conditions
const users = await client.user.findMany({
  where: {
    OR: [
      { name: { contains: query, mode: "insensitive" } },
      { email: { contains: query, mode: "insensitive" } },
    ],
    NOT: {
      email: { endsWith: "@blocked.com" },
    },
  },
});

Examples

Search Function

async function searchUsers(query: string) {
  return client.user.findMany({
    where: {
      OR: [
        { name: { contains: query, mode: "insensitive" } },
        { email: { contains: query, mode: "insensitive" } },
        { bio: { contains: query, mode: "insensitive" } },
      ],
    },
    take: 20,
  });
}

Email Domain Filter

async function getUsersByDomain(domain: string) {
  return client.user.findMany({
    where: {
      email: { endsWith: `@${domain}` },
    },
  });
}

Username Validation

async function isUsernameAvailable(username: string) {
  const existing = await client.user.findFirst({
    where: {
      username: { equals: username, mode: "insensitive" },
    },
  });
  return !existing;
}

On this page