The add command adds a new record to the specified table. Column values of the existing record are updated by given values, if the table has a primary key and there is existing record with the specified key.
(Document Root)/droonga/addPOSTNot supported.
type of the requestaddbody of the requesttype of the responseadd.resultIf the table has a primary key column:
{
"table" : "<Name of the table>",
"key" : "<The primary key of the record>",
"values" : {
"<Name of the column 1>" : <value 1>,
"<Name of the column 2>" : <value 2>,
...
}
}
If the table has no primary key column:
{
"table" : "<Name of the table>",
"values" : {
"<Name of the column 1>" : <value 1>,
"<Name of the column 2>" : <value 2>,
...
}
}
This section describes how to use the add command, via a typical usage with following two tables:
Person table (without primary key):
| name | job (referring the Job table) |
| Alice Arnold | announcer |
| Alice Cooper | musician |
Job table (with primary key)
| _key | label |
| announcer | announcer |
| musician | musician |
Specify only table and values, without key, if the table has no primary key.
{
"type" : "add",
"body" : {
"table" : "Person",
"values" : {
"name" : "Bob Dylan",
"job" : "musician"
}
}
}
=> {
"type" : "add.result",
"body" : true
}
The add command works recursively. If there is no existing record with the key in the referred table, then it is also automatically added silently so you’ll see no error response. For example this will add a new Person record with a new Job record named doctor.
{
"type" : "add",
"body" : {
"table" : "Person",
"values" : {
"name" : "Alice Miller",
"job" : "doctor"
}
}
}
=> {
"type" : "add.result",
"body" : true
}
By the command above, a new record will be automatically added to the Job table like;
| _key | label |
| announcer | announcer |
| musician | musician |
| doctor | (blank) |
Specify all parameters table, values and key, if the table has a primary key column.
{
"type" : "add",
"body" : {
"table" : "Job",
"key" : "writer",
"values" : {
"label" : "writer"
}
}
}
=> {
"type" : "add.result",
"body" : true
}
This command works as “updating” operation, if the table has a primary key column and there is an existing record for the specified key.
{
"type" : "add",
"body" : {
"table" : "Job",
"key" : "doctor",
"values" : {
"label" : "doctor"
}
}
}
=> {
"type" : "add.result",
"body" : true
}
You cannot update column values of existing records, if the table has no primary key column. Then this command will always work as “adding” operation for the table.
tablekeyExisting column values will be updated, if there is an existing record for the key.
This parameter will be ignored if the table has no primary key column.
valuesnullValue of unspecified columns will not be changed.
This returns a boolean value true like following as the response’s body, with 200 as its statusCode, if a record is successfully added or updated.
true
This command reports errors not only general errors but also followings.
MissingTableParameterMeans you’ve forgotten to specify the table parameter. The status code is 400.
MissingPrimaryKeyParameterMeans you’ve forgotten to specify the key parameter, for a table with the primary key column. The status code is 400.
InvalidValueMeans you’ve specified an invalid value for a column. For example, a string for a geolocation column, a string for an integer column, etc. The status code is 400.
UnknownTableMeans you’ve specified a table which is not existing in the specified dataset. The status code is 404.
UnknownColumnMeans you’ve specified any column which is not existing in the specified table. The status code is 404.