"deleteRecords"
JSON DB "deleteRecords"
action deletes records from a table using its primary key
The "deleteRecords"
action deletes records from a database table using its primary key, such as the id field.
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
{ "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" }
Note
If the target object does not exist, the response returns success and the debug property contains a warning that the object was not found.
{ "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": "" }
The jsonAction JSON DB API "deleteRecords" action deletes records from a database table.
The "params"
property is an object that contains an action's parameters. Each action defines its own required and optional properties.
Property summary
"params"
property summariesProperty | Description | Default | Type | Limits (inclusive) |
---|---|---|---|---|
specifies the name of a database | Defaults to the | string | 1 to 64 bytes | |
specifies a unique identifier for a row in a table. It is mutually exclusive with |
It is required when | array | ||
specifies the unique name of a schema in a database |
| string | 1 to 64 bytes | |
specifies key values used by |
It is required when | array of arrays | ||
specifies the name of a table | Required - No default value | string | 1 to 64 bytes |
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.
A zero-length
"databaseName"
is invalid.Its limits are from 0 to 64 bytes.
If the
"databaseName"
property is omitted or set tonull
, 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 theservices.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.
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 than9,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.
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.
"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 arraysThe 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 a string containing the name of a table.
A table name may contain up to 64 ASCII characters and must not start with a number.
Properties summary
"result"
properties summaryProperty | Description | Type | Limits (inclusive) | |||
---|---|---|---|---|---|---|
specifies how binary values are returned | string |
| ||||
specifies an array or object that the server returns, such as records returned by a query. It is an empty array when no results are available. | array | Its contents are determined by the action | ||||
specifies the format of the data in the | string |
| ||||
specifies 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 | |||||
specifies an integer, the server sets its value to the number of records returned by a query | integer |
|