DEV Community

Cover image for ๐Ÿš€ API Maker - Save Single or Multiple API Records [Bulk Insert] [Post operation]
API Makerยฎ
API Makerยฎ

Posted on

๐Ÿš€ API Maker - Save Single or Multiple API Records [Bulk Insert] [Post operation]

โœ… This API is available in all major 8 database types in API Maker

  • MongoDB
  • MySQL
  • SQL Server
  • MariaDB
  • Oracle DB
  • PostgreSQL DB
  • TiDB
  • Percona XtraDB

โœ… User can save single or multiple records
โ–ธ having some inbuilt validation and conversion functionality.

โœ… Generate Dummy Payload [Single | Multiple]
โ–ธ Based on schema, user can generate dummy data with a single click by using Generated Data option in body section.
โ–ธ To generate your data it will not perform any kind of operation on database.it will guess the data based on field name and types.

โœ… Modify response using Query Params [select | deep]
โ–ธ select - Retrieve the fields based on the user's needs.
โ–ธ deep - Obtain more precise / details data in a certain field.

โœ… This API work like Atomic operation [either save all or none]
โ–ธ for single object inside the array, entire array input will not be considered as atomic operation.


โญ Validation โญ

๐Ÿ‘‰ API Maker validate the payload using below validator.
โ–ธ required
โ–ธ email
โ–ธ max
โ–ธ maxLength
โ–ธ min
โ–ธ minLength
โ–ธ unique
โ–ธ validatorFun [Custom validator function]


โญ Conversion โญ

๐Ÿ‘‰ API Maker can convert the payload using below conversion.
โ–ธ encryption
โ–ธ hashing
โ–ธ toLowerCase
โ–ธ toUpperCase
โ–ธ trim
โ–ธ trimStart
โ–ธ trimEnd
โ–ธ conversionFun [Custom conversion function]


โญ API Example โญ

[
    {
        "first_name": "Bob",
        "last_name": "Lin"
    },
    {
        "first_name": "Alice",
        "last_name": "Page"
    }
]
Enter fullscreen mode Exit fullscreen mode

โญ Example in code โญ

// Perform bulk insert operation in schema based API
let saveSingleOrMultiple = await g.sys.db.saveSingleOrMultiple({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    saveData: [{
        "first_name": "Bob",
        "last_name": "Lin"
    },
    {
        "first_name": "Alice",
        "last_name": "Page"
    }]
});
Enter fullscreen mode Exit fullscreen mode
// Perform bulk insert operation in generated API, only for mongoDB
let saveSingleOrMultiple = await g.sys.db.gen.saveSingleOrMultipleGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    saveData: [{
        "first_name": "Bob",
        "last_name": "Lin"
    },
    {
        "first_name": "Alice",
        "last_name": "Page"
    }]
});
Enter fullscreen mode Exit fullscreen mode

Youtube video link

https://youtu.be/UmEVfKf2O6M

Websites

https://apimaker.dev

API Docs links

https://docs.apimaker.dev/v1/docs/apis-all/generated-apis/auto-generated-save-single-or-multiple-api.html

https://docs.apimaker.dev/v1/docs/apis-all/schema-apis/auto-generated-schema-based-save-single-or-multiple-api.html

More Examples

https://docs.apimaker.dev/v1/examples/sys/db/saveSingleOrMultiple.html

https://docs.apimaker.dev/v1/examples/sys/db/gen/saveSingleOrMultipleGen.html

Follow on twitter

https://twitter.com/api_maker

Linked In

https://www.linkedin.com/company/api-maker

More YouTube Videos

https://www.youtube.com/@api_maker/playlists

Top comments (0)