Skip to main content

Examples

💡PostgreSQL Support

For all examples below, to create records in an external PostgreSQL database, include the db parameter with your connection name. If omitted, Manta defaults to its internal storage.

await manta.createRecords({
db: "your_postgres_db",
table: "users",
data: { name: "John Doe" },
});

Global URL validation​

This example applies a rule to check if the name field in every record is a valid URL.

TypeScript
await manta.createRecords({
table: "products",
data: [
{ product_id: "P-A122", name: "https://github.com" },
{ product_id: "P-B122", name: "https://yo2.com" },
],
options: { validationRule: { name: { format: "url" } } },
});

Per-row and global validation combined​

This example shows the flexibility of combining global rules (minimum length for name) with per-row rules (ensuring email has the correct format).

TypeScript
await manta.createRecords({
table: "users",
data: [
{
name: "Alice",
email: "real@example.com",
validation: { email: { format: "email" } },
},
{ name: "Bob", email: "not-an-email" },
],
options: { validationRule: { name: { minLength: 2 } } },
});

Continue on error​

This example uses continueOnError: true so the valid record (good@example.com) is inserted successfully, while the invalid record (bad) is returned with a failure message.

TypeScript
await manta.createRecords({
table: "users",
data: [{ email: "good@example.com" }, { email: "bad" }],
options: {
validationRule: {
email: {
format: "email",
},
},
continueOnError: true,
},
});