Skip to content

api API

phoenixide edited this page Apr 2, 2023 · 6 revisions

hello

The function hello sends a message to the background script, which in turn sends a message to the content script, which in turn sends a message to the database script, which in turn sends a message to the database, which in turn sends a message to the database script, which in turn sends a message to the content script, which in turn sends a message to the background script, which in turn sends a message to the function hello, which in turn returns the message

Returns any A promise.

get

get is a function that takes two parameters, tableName and documentId, and returns a promise that resolves to the document with the given documentId from the table with the given tableName

Parameters

  • tableName string The name of the table you want to get the document from.
  • documentId string The document id of the document you want to get.

Returns Promise<Document> A promise.

createTable

This function creates a table with the name tableName in the database

Parameters

  • tableName string The name of the table to create.

Returns Promise A promise.

createDb

It creates a database with the name dataBaseName and returns a promise

Parameters

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

Returns Promise A promise.

deleteDb

It deletes the database.

Parameters

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

Returns Promise A promise.

put

The put document to cocoDN script, which in turn sends a message to the put function, which in turn returns the message

Parameters

  • tableName string The name of the table to put the document into.
  • document Object The document to be inserted into the database.

Returns Promise A promise.

createIndex

It creates an index on a table.

Parameters

  • tableName string The name of the table to create the index on.
  • jsonField string The name of the field in the JSON object that you want to index.
  • dataType string The data type of the index. This can be one of the following:
  • isUnique boolean true/false
  • isNotNull boolean If true, the index will be created with the NOT NULL constraint.

Returns Promise A promise.

getFromIndex

It returns list of documents matching the queryObject

Parameters

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

  • queryObject Object This is the object that you want to query the table with.

  • 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 Promise

getFromNonIndex

It returns list of documents matching the queryObject after scanning the COCO DB

Parameters

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

  • queryObject Object This is the object that you want to query the table with. (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 Promise

deleteDocument

This function deletes a document from a table

Parameters

  • tableName string The name of the table you want to delete the document from.
  • documentId string The id of the document 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 Promise A promise.

deleteTable

This function deletes a table from the database

Parameters

  • tableName string The name of the table to delete.

Returns Promise A promise.

mathAdd

do mathematical addition on given json fields by given values in jsonFieldsIncrements

Parameters

  • tableName string The name of the table you want to update.
  • documentId string The document id of the document you want to update.
  • jsonFieldsIncrements Object A JSON object with the fields to increment and the amount to increment them by.

Returns Promise A promise.

update

Update a document in a table

Parameters

  • tableName string The name of the table to update the document in.
  • documentId string The id of the document to update.
  • document Object 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 Promise A promise.

query

It queries the database for a given table name and query string.

Parameters

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

  • queryString string The query string to be executed.

  • 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 Promise A promise

Clone this wiki locally