Syntax
First, import the MantaClient from the library, see Getting Started:
💡Prerequisite
Before using this method, ensure you have configured your target table in Manta or connected your external PostgreSQL database in the MantaHQ dashboard.
The fetchAllRecords method accepts a single configuration object as its parameter.
TypeScript
manta.fetchAllRecords(object);
Basic usage​
The following examples show how to fetch the first 10 active users.
- Manta data table
- PostgreSQL
TypeScript
const users = await manta.fetchAllRecords({
table: 'users',
fields: ['user_id', 'first_name', 'last_name', 'email'],
page: 1,
list: 10,
orderBy: 'first_name',
order: 'asc'
});
TypeScript
const users = await manta.fetchAllRecords({
db: 'analytics_pg', // Your PostgreSQL connection name
table: 'users',
fields: ['user_id', 'first_name', 'last_name', 'email'],
page: 1,
list: 10,
orderBy: 'first_name',
order: 'asc'
});
Response structure​
The fetchAllRecords method returns a Promise that resolves to a standard MantaResponse object. This object contains your data and query metadata.
TypeScript
interface MantaResponse<T = any> {
message: string;
status: boolean;
data: T;
meta?: QueryMeta;
}
interface QueryMeta {
page: number;
list: number;
total: number;
totalPages: number;
}
Example response​
This example shows the structure of a successful response, including the array of fetched records and the meta object for pagination.
JSON
{
"message": "Records fetched successfully",
"status": true,
"data": [
{
"_id": "689a839636d9638ca29a58b1",
"user_id": "user-1",
"first_name": "Alice",
"last_name": "Smith",
"email": "alice@example.com"
},
{
"_id": "689a839636d9638ca29a58b2",
"user_id": "user-2",
"first_name": "Bob",
"last_name": "Johnson",
"email": "bob@example.com"
}
],
"meta": {
"page": 1,
"list": 10,
"total": 2,
"totalPages": 1
}
}