Skip to content

api API

phoenixide edited this page Apr 2, 2023 · 8 revisions

hello

It makes a GET request to the root of the API

Returns any A function that returns a promise.

createTable

It takes a table name as a parameter and returns a promise that resolves to the response from the server

Parameters

  • tableName The name of the table you want to create.

Returns any A promise

createDb

It creates a database with the name provided in the databaseName parameter

Parameters

  • databaseName string The name of the database you want to create.

Returns Promise<boolean> A promise

deleteDb

It deletes the database with the given name

Parameters

  • databaseName string The name of the database to be deleted.

Returns Promise<boolean> A promise.

put

It takes a table name and a document as input and returns a promise

Parameters

  • tableName The name of the table you want to put the document in.
  • document The document to be inserted.

Returns any A promise

deleteDocument

It deletes a document from a table

Parameters

  • tableName The name of the table you want to delete the document from.
  • documentId The documentId of the document you want to delete.
  • condition string? Optional coco query condition of the form "$.cost<35" that must be satisfied for delete to happen. See query API for more details on how to write coco query strings.

Returns any A promise

deleteDocuments

This function deletes all documents satisfying query condition from a table

Parameters

  • tableName string The name of the table in which the key is to be deleted.
  • queryString string The cocDB query string.
  • useIndexForFields (optional, default [])

Returns Promise A promise.

deleteTable

It deletes a table from the database

Parameters

  • tableName The name of the table to be deleted.

Returns any A function that takes a tableName as an argument and returns a promise.

createIndex

Create an index on a table

Parameters

  • tableName The name of the table you want to create an index on.
  • jsonField The name of the field in the JSON object that you want to index.
  • dataType The data type of the field.
  • isUnique If true, the index will enforce that the column or columns do not contain any duplicate values.
  • isNotNull If true, the column will not allow null values.

Returns any A promise

update

It updates a document in a table

Parameters

  • tableName The name of the table in which the document is to be updated.
  • documentId The id of the document to be updated.
  • document The document to be updated.
  • condition string? Optional coco query condition of the form "$.cost<35" that must be satisfied for update to happen. See query API for more details on how to write coco query strings.

Returns any A promise

getFromNonIndex

It gets the document after scanning table

Parameters

  • tableName The name of the table you want to query.

  • queryObject This is the object that you want to query. (optional, default {})

  • options Object Optional parameter to add pagination. (optional, default {})

    • options.pageOffset number specify which row to start retrieving documents from. Eg: to get 10 documents from the 100'th document, you should specify pageOffset = 100 and pageLimit = 10
    • options.pageLimit number specify number of documents to retrieve. Eg: to get 10 documents from the 100'th document, you should specify pageOffset = 100 and pageLimit = 10

Returns any A promise

getFromIndex

This function will return a promise that will resolve to an array of objects that match the queryObject

Parameters

  • tableName The name of the table you want to query.

  • queryObject This is the object that you want to query on.

  • options Object Optional parameter to add pagination. (optional, default {})

    • options.pageOffset number specify which row to start retrieving documents from. Eg: to get 10 documents from the 100'th document, you should specify pageOffset = 100 and pageLimit = 10
    • options.pageLimit number specify number of documents to retrieve. Eg: to get 10 documents from the 100'th document, you should specify pageOffset = 100 and pageLimit = 10

Returns any A promise

get

It takes a table name and a document id and returns the document

Parameters

  • tableName The name of the table in which the document is stored.
  • documentId The id of the document you want to get.

Returns any A promise

MathAddResponse

MathAddResponse

Type: object

Properties

  • isSuccess boolean true is api is executed successfully false otherwise.
  • errorMessage string? This property detailed explanation of why call failed.

mathAdd

This function will add the values of the fields in the jsonFieldsIncrements object to the corresponding fields in the document with the given documentId in the given table

Parameters

  • tableName string The name of the table in which the document is present.
  • documentId string The document id of the document you want to update.
  • jsonFieldsIncrements Object This is a JSON object that contains the fields and their increments.

Returns Promise<MathAddResponse> A promise

query

query is a function that takes in a table name, a query string, and an optional useIndexForFields parameter, and returns a promise that resolves to the result of the query

Parameters

  • tableName string The name of the table you want to query.

  • queryString string This is the query string that you want to execute.

  • useIndexForFields Array<string> This is an array of fields that you want to use the index for. (optional, default null)

  • options Object Optional parameter to add pagination. (optional, default {})

    • options.pageOffset number specify which row to start retrieving documents from. Eg: to get 10 documents from the 100'th document, you should specify pageOffset = 100 and pageLimit = 10
    • options.pageLimit number specify number of documents to retrieve. Eg: to get 10 documents from the 100'th document, you should specify pageOffset = 100 and pageLimit = 10

Returns any A promise