Basic usage & filtering
The most common way to use fetchOneRecord is by providing a table and a where filter to uniquely identify the record.
Simple filter
This example shows how to fetch a single user record by their unique user_id
- Manta Studio
- PostgreSQL
TypeScript
const user = await db.fetchOneRecord({
table: "users",
where: { user_id: 12345 },
});
console.log(user);
TypeScript
const user = await db.fetchOneRecord({
table: "users",
where: { user_id: 12345 },
});
console.log(user);
Multiple conditions
You can combine multiple conditions to narrow your search.
- Manta Studio
- PostgreSQL
TypeScript
const user = await manta.fetchOneRecord({
table: 'users',
where: {
user_id: 'user-1',
email: 'alice@example.com'
}
});
TypeScript
const user = await manta.fetchOneRecord({
table: 'users',
where: {
user_id: 'user-1',
email: 'alice@example.com'
}
});
Available filter operators
fetchOneRecord supports the same
user-friendly operators as fetchAllRecords.
| Operator | Description | Example |
|---|---|---|
equals | Exact match | { field: 'value' } or { field: { equals: 'value' } } |
notEquals | Not equal | { field: { notEquals: 'value' } } |
greaterThan | Greater than | { field: { greaterThan: 100 } } |
lessThan | Less than | { field: { lessThan: 100 } } |
atLeast | Greater than or equal | { field: { atLeast: 100 } } |
atMost | Less than or equal | { field: { atMost: 100 } } |
in | In array | { field: { in: ['a', 'b', 'c'] } } |
notIn | Not in array | { field: { notIn: ['a', 'b', 'c'] } } |
- Manta Studio
- PostgreSQL
TypeScript
// using filter operators
const order = await manta.fetchOneRecord({
table: "orders",
where: {
amount: { greaterThan: 100 },
status: "completed",
},
});
TypeScript
// using filter operators
const order = await manta.fetchOneRecord({
table: "orders",
where: {
amount: { greaterThan: 100 },
status: "completed",
},
});