Filtering
The where parameter allows you to retrieve a subset of records by specifying filter conditions. You can use simple equality checks or a variety of powerful operators to build your query.
Available filter operators
You can use the following operators to build complex and precise filters.
| Operator | Description | Example |
|---|---|---|
equals | Finds an exact match. | { field: 'value' } |
notEquals | Finds records where the field is not equal to a value. | { field: { notEquals: 'value' } } |
greaterThan | Finds records with a value greater than the specified number. | { field: { greaterThan: 100 } } |
lessThan | Finds records with a value less than the specified number. | { field: { lessThan: 100 } } |
atLeast | Finds records with a value greater than or equal to a number. | { field: { atLeast: 100 } } |
atMost | Finds records with a value less than or equal to a number. | { field: { atMost: 100 } } |
in | Finds records where the field's value is in the given array. | { field: { in: ['a', 'b', 'c'] } } |
notIn | Finds records where the field's value is not in the given array. | { field: { notIn: ['a', 'b', 'c'] } } |
Simple filters
Example 1: This example retrieves all active users from the users table.
- Manta Studio
- PostgreSQL
TypeScript
// Simple filter to get active users
const users = await manta.fetchAllRecords({
table: 'users',
where: { status: 'active' },
page: 1,
list: 10
});
TypeScript
// Simple filter to get active users from PostgreSQL
const users = await manta.fetchAllRecords({
db: 'analytics_pg',
table: 'users',
where: { status: 'active' },
page: 1,
list: 10
});
Example 2: This example retrieves all completed orders with an amount greater than $100.
- Manta Studio
- PostgreSQL
TypeScript
// Multiple conditions to find completed orders over $100
const orders = await manta.fetchAllRecords({
table: 'orders',
where: {
status: 'completed',
amount: { greaterThan: 100 }
},
page: 1,
list: 10
});
TypeScript
// Multiple conditions to find completed orders over 100 from PostgreSQL
const orders = await manta.fetchAllRecords({
db: 'sales_db',
table: 'orders',
where: {
status: 'completed',
amount: { greaterThan: 100 }
},
page: 1,
list: 10
});
Complex filtering
Example 1: This example retrieves all orders with an amount between $10 and $1000, excluding those with a status of "cancelled".
- Manta Studio
- PostgreSQL
TypeScript
// Filter for a range of values
const orders = await manta.fetchAllRecords({
table: "orders",
where: {
amount: { greaterThan: 10, atMost: 1000 },
status: { notEquals: "cancelled" },
},
page: 1,
list: 10,
});
TypeScript
// Filter for a range of values in PostgreSQL
const orders = await manta.fetchAllRecords({
db: 'sales_db',
table: "orders",
where: {
amount: { greaterThan: 10, atMost: 1000 },
status: { notEquals: "cancelled" },
},
page: 1,
list: 10,
});
Example 2: This example retrieves all users whose role is either "admin", "manager", or "editor", but excludes those in the "HR" or "Finance" departments.
- Manta Studio
- PostgreSQL
TypeScript
// Filter by values contained in an array
const users = await manta.fetchAllRecords({
table: "users",
where: {
role: { in: ["admin", "manager", "editor"] },
department: { notIn: ["HR", "Finance"] },
},
page: 1,
list: 10,
});
TypeScript
// Filter by values contained in an array in PostgreSQL
const users = await manta.fetchAllRecords({
db: 'analytics_pg',
table: "users",
where: {
role: { in: ["admin", "manager", "editor"] },
department: { notIn: ["HR", "Finance"] },
},
page: 1,
list: 10,
});