# db8 Data Types

Data Type | Description | Ref'd by | Wrapper APIs | Service APIs
--- | --- | --- | --- | ---
BatchOperation | Method and parameters for operation in batch. |  |  | batch
BatchResponse | Response to batch API call. |  |  | batch
CountResponse | Number of objects affected by operation. |  | del merge | del merge
ErrResponse | Standard error response, containing operation success or failure flag, error code and error message. |  | del delKind find get merge put putKind reserveIds | batch del delKind find get merge put putKind reserveIds search watch
FindResponse | Response to find operation. |  | find | find search
GetResponse | Parameters for get objects operation response. |  | get | get
IndexClause | Used for creating indexes for kind object. |  | putKind | putKind
IndexPropClause | Defines index property. | IndexClause |  |
NotificationResponse | Notifies caller of change in query results. |  | find | find search watch
PutResponse | Indicates success of operation and returns `id` and `rev` fields for each object. |  | del merge put | del merge put
PutResult | Contains `id` and `rev` field for JSON data object stored in put operation. | PutResponse |  |
Query | Defines db8 query. |  | del merge find | del merge find watch
ReserveIdsResponse | Contains operation success or failure flag and array of reserved db8 IDs. |  | reserveIds | reserveIds
RevSetClause | Defines a revision set for a kind. See Using Revision Sets for more information. |  |  | putKind
RevSetPropClause | Defines a property in a revision set. | RevSetClause |  |
SuccessResponse | Indicates operation success or failure. |  | delKind putKind | delKind putKind watch
WhereClause | Defines SQL-like JSON where clause for query. | Query |  |

## BatchOperation

Method and params for batch operation.

### Schema

    {
       "method" : string,
       "params" : any
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
method | Yes | string | Operation to perform. Possible values: "del", "find", "get", "merge", or "put".
params | Yes | any | Method parameters.

## BatchResponse

Response to batch operation.

### Schema

    {
       "returnValue" : boolean,
       "responses"   : any array
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
returnValue | Yes | boolean | Success (true) or Failure (false).
responses | Yes | any array | Array of responses for each of the operations in the batch.

## CountResponse

Number of objects affected by operation.

### Schema

    {
       "returnValue" : boolean,
       "count"       : int
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
returnValue | Yes | boolean | `true` (success) or `false` (failure).
count | Yes | int | Number of objects affected by operation.

## ErrResponse

Standard error response, containing operation success or failure flag, error code and error message.

### Schema

    {
       "returnValue" : boolean,
       "errorCode"   : int,
       "errorText"   : string
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
returnValue | Yes | boolean | `true` (success) or `false` (failure).
errorCode | Yes | int | Numeric error code.
errorText | Yes | string | Error message.

## FindResponse

Response to a find objects operation.

### Schema

    {
       "returnValue" : boolean,
       "results"     : any,
       "count"       : int,
       "next"        : string
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
returnValue | Yes | boolean | `true` (success) or `false` (failure).
results | Yes | any | Array of db8 kind data objects. What is returned depends on the query and what is stored.
count | No | int | Number of results that would have been returned if a limit had not been specified.
next | No | string | Key to pass as query's `"page"` property when retrieving next page of results.

## GetResponse

Parameters for get objects operation response.

### Schema

    {
          "returnValue" : boolean,
          "results"     : any
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
returnValue | Yes | boolean | `true` (success) or `false` (failure).
result | Yes | any object array | Returns array of stored db8 data objects.

## IndexClause

Used in the `putKind` call for creating kind object indexes. Note that indexes determine the type of queries your app can make. See Queries and Indexing for more information.

Set the `"incDel"` flag to `true` if you want future queries to return marked as deleted objects. Objects are not completely deleted until an administrative purge operation takes place.

### Schema

    {
       "name"    : string,
       "props"   : IndexPropClause,
       "incDel"  : boolean
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
name | Yes | string | Index name
props | Yes | IndexPropClause | Array of properties to index together.
incDel | No | boolean | Include deleted objects flag. Default is `false`.

Example

    {
       "name"   : "state",
       "props"  : [{"name": "state"}],
       "incDel" : false
    }

## IndexPropClause

Defines index property for IndexClause

### Schema

    {
       "name"     : string,
       "collate"  : string,
       "default"  : any,
       "tokenize" : string,
       "type"     : string
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
name | Yes | string | Name of property being indexed.
collate | No | string | Indicates the string comparison routine used to order the index. Must be one of the following: default—Does binary comparison. primary—Compares base characters (for example, "a" < "b") without considering accents, case, or tone marks. secondary—Accents in the characters are considered secondary differences (for example, "as" < "às" < "at"). Other differences between letters can also be considered secondary differences, depending on the language. A secondary difference is ignored when there is a primary difference anywhere in the strings. tertiary—Upper and lower case differences in characters are distinguished at the tertiary level (for example, "ao" < "Ao" < "aò"). In addition, a variant of a letter differs from the base form on the tertiary level (such as "A" and "?"). A tertiary difference is ignored when there is a primary or secondary difference anywhere in the strings.
default | No | any | Default value to set for this property at insertion time, if not present.
tokenize | No | string | Indicates if words in strings should be broken up, i.e., should "Hello World" become "Hello" and "World" for purposes of indexing. Must be one of the following: none—Does not tokenize. default—Use the default for the locale (which may strip stop-words). Stop-words are common words that are stripped for purposes of indexing, i.e., "the", "a", "an", "is", etc. all—Tokenizes all words.
type | Yes | string | "single" or "multi". Single property or multiple properties.

## NotificationResponse

Notifies caller of change in query results returned from a "find" call.

### Schema

    {
       "returnValue" : boolean,
       "fired"       : boolean
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
returnValue | No | boolean | `true` (success) or `false` (failure).
fired | Yes | boolean | Change notification flag.

## PutResponse

Indicates success of operation and returns id and rev fields for each object.

### Schema

    {
       "returnValue" : boolean,
       "results"     : PutResult
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
returnValue | Yes | boolean | `true` (success) or `false` (failure).
results | Yes | PutResult | Array of objects containing the id and rev of each object that was put.

## PutResult

Contains "id" and "rev" fields in PutResponse for JSON data object.

### Schema

    {
       "id"    : any,
       "rev"   : any
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
id | Yes | any | ID of the object that was put.
rev | Yes | any | Object's revision ID. Every db8 object has this ID field. db8 maintains a global rev id counter that is incremented every time a db8 object is created or updated.

## Query

Defines a db8 query.

### Schema

    {
       "select"  : string array,
       "from"    : string,
       "where"   : WhereClause array,
       "orderBy" : string,
       "desc"    : boolean,
       "incDel"  : boolean,
       "limit"   : int,
       "page"    : string
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
select | No | string array | Array of property names to return.
from | Yes | string | Name of kind to retrieve results from.
where | No | WhereClause array | Array of clauses to test.
orderBy | No | string | Order results on this property.
desc | No | boolean | Return results in descending order.
incDel | No | boolean | Include deleted objects. Deleted objects have _del=true. Note: You can only request this if the "incDel" field was true when you created your indexes during a "putKind" operation. Otherwise, the query fails with a "no index for this query" message.
limit | No | int | Specifies maximum number of results to return (0-500). Default is 500.
page | No | string | Page key returned by previous query.

Example

    {
       "select"  : ["displayName", "state"],
       "from"    : "com.mystuff.contacts:1",
       "where"   : [{"prop":"state","op":"=","val":"CA"}],
       "orderBy" : "displayName",
       "desc"    : true
    }

## ReserveIdsResponse

Contains operation success or failure flag and array of reserved db8 IDs returned from `"reserveIds"` call.

### Schema

    {
       "returnValue" : boolean,
       "ids"         : string array
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
returnValue | Yes | boolean | `true` (success) or `false` (failure).
ids | No | string array | Array of reserved IDs.

## RevSetClause

Defines a revision set—subset of an object's properties that your app can be notified about when one of the properties is modified. See Using Revision Sets for more information.

### Schema

    {
       "name"  : string,
       "props" : RevSetPropClause array
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
name | Yes | string | Name of the revision set (unique to this kind).
props | Yes | RevSetPropClause array | Array of properties to include in revision set.

## RevSetPropClause

A property in a RevSetClause.

### Schema

    {
       "name"  : string,
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
name | Yes | string | Name of property to include in revision set.

## SuccessResponse

Indicates operation success or failure.

### Schema

    {
       "name"  : string,
    }

### Elements

Element | Type | Description
--- | --- | ---
returnValue | boolean | `true` (success) or `false` (failure).

Example

    {
       "returnValue": false
    }

## WhereClause

Defines a SQL-like JSON where clause for a db8 Query.

### Schema

    {
       "prop"    : string,
       "op"      : string,
       "val"     : any,
       "collate" : string
    }

### Elements

Element | Required | Type | Description
--- | --- | --- | ---
prop | Yes | string | Name of property to test.
op | Yes | string | Test operator. Must be one of the following: "<", "<=", "=", ">=", ">", "!=", "%", "?" (less than, less than or equal, equals, greater than or equal, greater than, not equal, wildcard, and full-text) The "%" operator (aka - the prefix operator) will return all matches beginning with the value specified.
val | Yes | any | Value to test against.
collate | No | any | Indicates the string comparison routine used to order the results. See the collate field in the IndexPropClause data structure for more information.

Example

    {
       "prop" : "state",
       "op"   : "=",
       "val"  : "CA"
    }