Children first, parents after
The deepest object is saved first. Its new id replaces the object in its parent, which is saved next, and so on.
API Maker
The framework for AI era
Database APIs
Save a whole tree of related objects in one call, across tables and databases.
Send a city with its state and the country of that state as nested objects. API Maker saves the deepest object first, puts its new id in the parent, and goes up to the top. Objects that carry their key are updated instead. If a step fails, what was saved is removed and what was updated is restored.
Step through it, slow it down, or open the full canvas.
Send the whole tree in one call. A city, its state and the country of that state, as nested objects. The schema knows which table, database and type each goes to.
A city, its state and the country of that state, as nested objects. The schema knows which table, database and type each goes to.
The country goes to PostgreSQL and gets id 303. In the payload, the object is replaced by that id.
The state is saved in SQL Server with country_id 303 and gets id 204, which takes its place in turn.
The city is saved in MySQL with state_id 204 and the API answers 201 Created with the saved row.
The state carries id 201 and its row exists: it is updated, its old values kept as a backup, and the new city points to it.
The city has no city_name: after its country and state were saved, it fails validation. Both are deleted again and the API answers 400.
The deepest object is saved first. Its new id replaces the object in its parent, which is saved next, and so on.
An object without its primary key is inserted. An object with its key is updated, and its old values are kept to revert it if needed.
When any object fails, for example on validation, the rows saved by the call are deleted and the updated ones restored, then the error is returned.
The schema says where each nested object goes, so one payload can write to MySQL, SQL Server and PostgreSQL.
Every object is converted and validated with the schema of its own table before it is written.
With virtual fields, a parent can carry the array of its children, like an invoice with its lines, in the same payload.
A form creates an invoice with its lines and a new customer at once. One master save writes the customer, the invoice and every line in the right order. If one line is invalid, nothing of it stays in the database.
POST /api/schema/admin/mysql/geo/cities/master-savex-am-authorization: <API user token>{ "city_name": "Wembley", "state_id": { "state_name": "London", "country_id": { "id": 302, "country_name": "UK" } }}The country has its id, so it is updated. The state has none, so it is inserted and its new id goes into the city.
Save inserts the objects you send into one table. Master save walks the nested objects into their own tables, inserts or updates each one, and links them with the new ids.
Yes. Send an array: every item is saved with its own nested objects.
The saved top object with 201 Created. Add select or deep to the call to shape what comes back.
Documentation