Querydeck Docs
  • 👋Welcome to Query Deck
  • Getting Started
    • 😃Get Started With QueryDeck
      • Quickstart With QueryDeck
    • How It Works?
  • REST
    • Select Method
      • Joins
      • Sorting
        • Ascending/ Descending ordering
        • Dynamic Sorting
      • Filter
        • Dynamic Filtering
        • Groups
        • Exists clause
      • Pagination
        • Offset
        • Limit
    • Insert/Upsert Method
      • Nested Inserts (Joins)
      • Conflicting Columns
    • Update Method
      • Filters
    • Delete Method
    • Authentication
    • Authorization
    • Select by Id
  • GraphQL
    • Introduction to GraphQL in QueryDeck
    • Enabling GraphQL for Columns in QueryDeck
  • Testing Endpoints
Powered by GitBook
On this page
  • Overview
  • Using the Insert or Upsert query:
  • Testing
  1. REST

Insert/Upsert Method

PreviousLimitNextNested Inserts (Joins)

Last updated 2 months ago

Overview

The Insert method in QueryDeck allows you to add new records to your database. The Upsert method is a combination of "update" and "insert," allowing you to either insert a new record or update an existing one if a conflict occurs. This ensures data consistency and prevents duplicate entries when using unique constraints.

With QueryDeck’s Insert/Upsert method, you can:

  • Add new records to your database.

  • Handle conflicts using the on_conflict clause.

  • Update records if they already exist based on specified constraints.

Using the Insert or Upsert query:

1. Select the Base Table

  • From the left pane in the demo app, choose a base table to use. For this example, we will use the customers table.

2. Configure the Query Method

  • In the left pane:

    • Change the Method to Insert or Upsert.

  • Update the Route Name if required.

3. Save the Endpoint

  • Click on the Save button at the bottom of the left pane.

  • Your endpoint for Insert/Upsert is now ready.

Testing

  • Copy the endpoint URL by clicking it in the top right corner

  • Open Postman:

    • Paste the endpoint URL into the input field.

    • Change the request method to POST.

Add a Sample Request Body

  • Under the Body tab in Postman:

    • Select raw as the body type.

    • Paste a sample request body in JSON format. For example:

{
  "customer": [
    {
      "store_id": 1,
      "first_name": "Jared",
      "last_name": "Ely",
      "address_id": 530,
      "active": 1,
      "activebool": true,
      "create_date": "2006-02-14T00:00:00.000Z",
      "email": "jared.ely@sakilacustomer.org",
      "last_update": "2013-05-26T14:49:45.738Z"
    },
    {
      "store_id": 1,
      "first_name": "Mary",
      "last_name": "Smith",
      "address_id": 5,
      "active": 1,
      "activebool": true,
      "create_date": "2006-02-14T00:00:00.000Z",
      "email": "mary.smith@sakilacustomer.org",
      "last_update": "2013-05-26T14:49:45.738Z"
    }
  ]
}

Send the Request

  • Click on the Send button in Postman.

  • You will receive a response indicating that the query was successful.

You have now successfully created and tested your Insert/Upsert query.