Skip to main content

"deleteRecords"

Abstract

deleteRecords deletes one or more records from a database table using one or ore IDs.

The "deleteRecords" action deletes one or more records from a database table using one or more IDs or primary keys.

Things to know

  • The action returns the values from the deleted records in case you want to insert them again, view them, or verify the correct records are deleted.

  • If the specified records do not exist, the action returns success because this is the desired end result.

  • The "totalRecordCount" property in the response is the number of records that are deleted by this action.

  • A table must have a primary key to delete records.

    • Tables created by the "createTable" action, automatically have an auto increment "id" field indexed as primary key.

    • Tables created by other APIs may not have an "id" field; instead, they may have a primary key index that includes one or more fields in the table.

    • The "deleteRecords" action provides an optional  "primaryKeys" property that can retrieve records using any primary key index.

    • The "primaryKeys"  and "ids" properties are mutually exclusive.

Request examples

Minimal request example

{
  "api": "db",
  "authToken": "replaceWithAuthtokenFromCreateSession",
  "action": "deleteRecords",
  "params": {
    "tableName": "test1",
    "ids": [
      1,
      2
    ]
  }
}
{
  "api": "db",
  "authToken": "replaceWithAuthtokenFromCreateSession",
  "action": "deleteRecords",
  "params":
  {
    "tableName": "pk_example",
    "primaryKeys": 
    [ 
      [
        {
          "fieldName": "first_name",
          "value": "Sam"
        },
        {
          "fieldName": "last_name",
          "value": "I-am"
        }
      ]
    ]
  }
}
{
  "api": "db",
  "authToken": "replaceWithAuthtokenFromCreateSession",
  "action": "deleteRecords",
  "params":
  {
    "tableName": "pk_example",
    "primaryKeys": 
    [ 
      [
        {
          "fieldName": "first_name",
          "value": "Sam"
        },
        {
          "fieldName": "last_name",
          "value": "I-am"
        }
      ],
      [
        {
          "fieldName": "first_name",
          "value": "The Cat"
        },
        {
          "fieldName": "last_name",
          "value": "in the Hat"
        }
      ]
    ]
  }
}
{
  "api": "db",
  "apiVersion": "1.0",
  "requestId": "4",
  "authToken": "replaceWithAuthtokenFromCreateSession",
  "action": "deleteRecords",
  "params": {
    "databaseName": "ctreeSQL",
    "ownerName": "admin",
    "tableName": "test1",
    "ids": [
      1,
      2
    ]
  },
  "responseOptions": {
    "binaryFormat": "hex",
    "dataFormat": "objects",
    "numberFormat": "string",
    "includeFields": [],
    "excludeFields": []
  },
  "debug": "max"
}

Response examples

{
  "authToken": "authToken",
  "result": {
    "dataFormat": "objects",
    "binaryFormat": "hex",
    "fields": [
      {
        "name": "id",
        "type": "bigint",
        "length": null,
        "scale": null,
        "defaultValue": null,
        "nullable": false,
        "primaryKey": 1,
        "autoValue": "incrementOnInsert"
      },
      {
        "name": "changeId",
        "type": "bigint",
        "length": null,
        "scale": null,
        "defaultValue": null,
        "nullable": true,
        "primaryKey": 0,
        "autoValue": "changeId"
      },
      {
        "name": "name",
        "type": "varchar",
        "length": 50,
        "scale": null,
        "defaultValue": null,
        "nullable": true,
        "primaryKey": 0,
        "autoValue": "none"
      }
    ],
    "data": [],
    "primaryKeyFields": [
      "id"
    ],
    "changeIdField": "changeId",
    "totalRecordCount": 0
  },
  "errorCode": 0,
  "errorMessage": ""
}
{
  "authToken": "authToken",
    "result": {
        "dataFormat": "objects",
        "binaryFormat": "hexadecimal",
        "fields": [
            {
                "name": "id",
                "type": "bigint",
                "length": null,
                "scale": null,
                "autoTimestamp": "none",
                "defaultValue": null,
                "nullable": false
            },
            {
                "name": "changeId",
                "type": "bigint",
                "length": null,
                "scale": null,
                "autoTimestamp": "none",
                "defaultValue": null,
                "nullable": true
            },
            {
                "name": "name",
                "type": "varchar",
                "length": 50,
                "scale": null,
                "autoTimestamp": "none",
                "defaultValue": null,
                "nullable": true
            }
        ],
        "data": [
            {
                "changeId": 22788,
                "id": 2,
                "name": "jane"
            }
        ],
        "totalRecordCount": 1
    },
    "requestId": "4",
    "debugInfo": {
        "request": {
            "authToken": "authToken",
            "api": "db",
            "action": "deleteRecords",
            "params": {
                "databaseName": "ctreeSQL",
                "ownerName": "admin",
                "tableName": "test1",
                "ids": [
                    2
                ]
            },
            "apiVersion": "1.0",
            "requestId": "4",
            "responseOptions": {},
            "debug": "max"
        },
        "serverSuppliedValues": {
            "databaseName": "ctreeSQL",
            "ownerName": "admin"
        },
        "errorData": {
            "errorData": null
        },
        "warnings": []
    },
    "errorCode": 0,
    "errorMessage": ""
}

"params"

The "params" property is an object that contains an action's parameters. Each action defines its own required and optional properties.

Property summary

Table 1. "params" property summaries

Property

Description

Default

Type

Limits (inclusive)

"databaseName"

contains the name of a database

Defaults to the "defaultDatabaseName" value that is set during "createSession". If no default is set during "createSession", then "faircom" is used.

string

Minimum length: 1
Maximum length: 64

"ids"

contains a unique identifier for a row in a table

Note

Mutually exclusive with "primaryKeys".

"null"

Note

Required when "primaryKeys" is omitted.

array

"ownerName"

contains the unique name of a schema in a database

""

string

Minimum length: 1
Maximum length: 64

"primaryKeys"

contains key values used by "getRecordsByIds" to find and return one or more records

Note

Mutually exclusive with "ids"

"null"

Note

Required when "ids" is omitted.

array of arrays

"tableName"

contains the name of a table

Required - No default value

string

Minimum length: 1
Maximum length 64


The "databaseName" property is an optional string that specifies the database that contains the tables. It defaults to the database name supplied at login.

Note

In the API Explorer, "defaultDatabaseName" is set to "ctreeSQL" in the "createSession" action that happens at login.

Things to know:
  • A zero-length "databaseName" is invalid.

  • Its limits are from 0 to 64 bytes.

  • If the "databaseName" property is omitted or set to null, the server will use the default database name specified at login.

  • If no default database is specified during "createSession", "defaultDatabaseName" will be set to the "defaultDatabaseName" value that is specified in the services.json file.

The "ids" property is an array that contains a unique identifier for a row in a table. Its default value is "null" but it is required if the "primaryKeys" property is "null" or not specified.

Things to know:
  • The "ids" property is mutually exclusive with the "primaryKeys" property meaning it is required when "primaryKeys" is omitted or an error is returned if both have values.

  • It is typically an array of integers ("ids": [1,3,5]).

  • It can be an array of an array of strings ("ids": ["9555444333222111","9555444333222112", "9555444333222113"]).

    • A string "id" supports numbers larger than 9,007,199,254,740,991.

    • This is the largest number supported by many programming languages and JSON parser implementations that use IEEE double-precision floats to hold numbers.

  • It can be the primary key value of another field in the table making it useful when your table is created by another API, such as SQL, that allows any field in the table to be the primary key.

    If your table does not have an "id" field but uses a "vin" field as the primary key, you can use vin values to look up records ("ids": [ "4Y1SL65848Z411439", "1HGBH41JXMN109186" ]).

  • If your table uses more than one field as the primary key, you must use the "primaryKeys" property to look up records.

    Tip

    The "getRecordsByIds'' action uses a primary key index to look up records. A primary key index must be a unique, non-null index without conditional filtering. For best performance and maximum simplicity, create tables using the JSON DB API because it automatically creates an auto increment "id" field that is indexed as a primary key.

The "ownerName" property is an optional string from 1 to 64 bytes that specifies the account that owns an object.

Things to know:
  • The "ownerName" property is optional and has a dynamic default value.

  • If the "ownerName" property is omitted or set to null, the server uses the value of the "defaultOwnerName" property supplied during the "createSession" action.

  • If the "defaultOwnerName" property is not defined, the server uses the "admin" as the owner name.

  • The owner of an object has administrative rights over that object.

  • The "ownerName" property is a namespace for an object. You can think of it as a container of objects.

    The "ownerName" allows users to use any name for the objects they create — for example, a QA engineer may copy tables into their owner space to run a set of tests.

    It is common for a user to create their own copies of objects from other accounts for testing, troubleshooting, and fixing data. The copied objects can retain the same name because the "ownerName" distinguishes between them.

  • The fully qualified name of an object is the "databaseName", "ownerName", and the object's name, such as "tableName" meaning a FairCom server may contain many tables with the name "mytable" as long as each one is in a different database or in a different owner space.

    For example, an organization often creates different databases for different phases of the development lifecycle, such as dev, test, stage, ua, and prod. Each of these databases contains the same set of objects with the same names. Applications leave the "databaseName" out of their JSON actions and use the "defaultDatabaseName" property to specify the target database.

  • Queries and scripts are often written without specifying "databaseName" and/or "ownerName", allowing queries and scripts to work properly when run in different databases or in different schemas.

The "primaryKeys" property is an array of arrays that contain key values used by the "getRecordsByIds" action to find and return one or more records. The default value is "null" but it is required if the "ids" property is omitted.

Things to know:
  • "primaryKeys" is best used if tables were created with primary keys composed of multiple fields. If primary keys are composed of a single field, it is best to use "ids".

    Note

    Tables created using JSON DB API actions cannot create primary keys composed of multiple fields.

  • A table must have a primary key defined in order to use "primaryKeys"

  • The "primaryKeys" property is mutually exclusive with the "ids" property meaning it is required when "ids" is omitted or an error is returned if both have values.

  • The  "primaryKeys" property is an array of arrays

    • The outer array contains one or more primary key definitions which allow the server to retrieve multiple records at a time.

    • Each inner array is a primary key definition that specifies the values the server needs to retrieve one matching record.

    • A primary key definition consists of one or more objects where each object is a field-value pair that uses the following structure ({ "fieldName": "someField","value": "someValue" }).

Example

If your table uses the "first_name" and "last_name" fields as the primary key, the following "primaryKeys" property will retrieve two records.

Note

If your table does not have a primary key, its records cannot be retrieved, updated or deleted using the "getRecordsByIds", "updateRecords" and "deleteRecords" actions. Other getRecords actions can query its records.

   "primaryKeys": 
    [ 
      [
        { "fieldName": "first_name", "value": "Sam" },
        { "fieldName": "last_name",  "value": "I-am" }
      ],
      [
        { "fieldName": "first_name", "value": "The Cat" },
        { "fieldName": "last_name",  "value": "in the Hat" }
      ]
    ]

The "tableName" property is an optional string that contains the name of an integration table or MQTT topic that holds the topic's messages. It defaults to an empty string.

Things to know:
  • You can use a topic name for an MQTT table because FairCom automatically generates a table name for each topic.

  • A "tableName" cannot begin with a number.

  • It refers to the name of the integration table that stores a topic’s messages and is used to rename that table or assign a new topic to an existing integration table.

  • MQTT automatically creates an integration table for each new topic it receives. Thus, when a message is sent to a topic, FairCom Edge automatically creates a table to hold it.

  • As you refine your integration processes, you may want to rename an integration table to better label the data it holds. You can use the "tableName" property of the "configureTopic" action to rename an integration table.

  • The "alterIntegrationTable" action can also be used to rename an integration table, but it is less convenient because you must know the original name of the integration table.

"result"

Property summary

Table 2. "result" property summaries

Property

Description

Type

Limits (inclusive)

"binaryFormat"

designates how binary values are returned

string

"base64"
"hex"

"data"

contains an array or object that the server returns, such as records returned by a query

Note

It is an empty array when there are no results available.

array

Its contents are determined by the action

"dataFormat"

defines the format of the data in the "data" property

string

"autoDetect"
"arrays"
"objects"

"fields"

shows an array of objects set by the server where each object is the definition of a field in a table defining the details of each field returned by a query

array

"totalRecordCount"

contains an integer, the server sets its value to the number of records returned by a query

integer

-1 - 99,999,999,999,999,999,999,999,999,999,999