Syntax
First, import the MantaClient from the library, see Getting Started:
Getting Started
💡Prerequisite
Before using this method, ensure that the target database has been set up and configured.
This method accepts a single object as its parameter.
TypeScript
manta.fetchOneRecord(object);
Basic usage​
- Manta Studio
- PostgreSQL
TypeScript
const user = await manta.fetchOneRecord({
table: 'users',
where: { user_id: 'user-1' },
fields: ['user_id', 'first_name', 'last_name', 'email']
});
TypeScript
const user = await manta.fetchOneRecord({
table: 'users',
where: { user_id: 'user-1' },
fields: ['user_id', 'first_name', 'last_name', 'email']
});
Response structure​
The fetchOneRecord method returns a Promise that resolves to an object containing your fetched data.
Example response​
JSON
{
"message": "Record fetched successfully",
"status": true,
"data": {
"_id": "689a839636d9638ca29a58b1",
"user_id": "user-1",
"first_name": "Alice",
"last_name": "Smith",
"email": "alice@example.com",
"orders": [
{
"_id": "689a8d51b9b7dbafde63911d",
"order_id": "order-1",
"product_name": "Laptop Pro",
"amount": 1200
}
]
}
}
When no record matches the provided criteria, the API returns a successful status but provides a message and details about the query that did not return any records.
JSON
{
"message": "No records found in table 'product-list' with the given criteria",
"status": true,
"data": {
"table": "product-list",
"fields": ["id", "productid", "name", "category"],
"timestamp": "2025-09-18T17:35:02.637Z"
}
}
Best practices​
- Be explicit with parameters: Always specify a
wherefilter to ensure you retrieve a single, specific record. - Improve performance: Use the
fieldsparameter to return only the data you need. This reduces payload size and improves performance. - Handle errors and empty results: Always use a
try/catchblock to handle network or SDK errors. Check for anullresponse to handle cases where no record is found. - External databases: For external DB tables, use the fully qualified table name (
schema.table) and ensure the database is properly connected and synced in your MantaHQ workspace.