1

Step-by-Step Guide on How to Use External Database Collections for Better Wix We...

 3 years ago
source link: https://hackernoon.com/step-by-step-guide-on-how-to-use-external-database-collections-for-better-wix-website-performance-d51o33cu
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Step-by-Step Guide on How to Use External Database Collections for Better Wix Website Performance

@veloVelo by Wix

Velo is a full-stack development platform that empowers you to rapidly build, manage and deploy professional web apps.

Integrate your external databases into your Wix sites. Learn more.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Guides (Additional information about this section)

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Provisioning

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Request Context

0 reactions
heart.png
light.png
money.png
thumbs-down.png
  • OBJECT Request Context Object : The Request Context object is sent with every request. It contains information about who made the request, and which site and which external collection ...

Schema

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Data

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Introduction

Integrate your external database into your Wix site using external collections and building an external database collection adapter.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The External Database Collections SPI describes the API requests your
adapter needs to expect from your Wix site, and the responses your Wix
site expects in return. The SPI takes the request from your Wix site and converts it into a request that your external database can receive. It also takes the response from the external database and converts it into a JSON response that your Wix site can receive.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

You can learn more about working with External Databases on your Wix site here.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Mandatory Endpoints

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The following endpoints are mandatory and must be implemented in your adapter. All other endpoints are optional.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The implemented endpoints must be exposed via the schema object in the

allowedOperations
list.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

For example:

0 reactions
heart.png
light.png
money.png
thumbs-down.png
"schema":
      {
          "displayName": "myCollection",
          "id": "myCollection",
          "allowedOperations": [
              "get",
              "find",
              "count",
              "update",
              "insert",
              "remove"
          ],
          "maxPageSize": 50,
          "ttl": 3600,
          "fields": { "..."}
      }

Data Structures

0 reactions
heart.png
light.png
money.png
thumbs-down.png

_id

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Each table or collection must contain an

_id
column or attribute of type string.If you create new data outside of your Wix site, or you are importing
new data for use with your site, you must populate this field with a unique value. If you create new data in your site, the Wix Data backend will generate a unique 36-character UUID for each item created.The
_id
attribute can be any length but if items are created by your Wix site, it must be at least 36 characters long.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

_owner (optional)

0 reactions
heart.png
light.png
money.png
thumbs-down.png

For data created by your Wix site, Wix Data backend will populate the

_owner
attribute with a 36-character UUID identifying the user who created the data. If the visitor is not a logged-in member, the
_owner
attribute is based on a browser cookie and is therefore consistent between sessions. The
_owner
attribute will be null if the new data was created by a backend process.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

Dates

0 reactions
heart.png
light.png
money.png
thumbs-down.png

All dates must be an ISO string encapsulated in an object. For example: "myDate" :{“$date”:”2001-02-11T00:00:00.000Z”}

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Authentication

The External Database Collections SPI uses the request context object to manage authentication and authorization. HTTP authentication is not implemented. The

settings
object within the request context object can contain a key for authentication purposes. In the prototype and examples, the
secretKey
property is used. This key is configured in the Wix Editor when adding the external collection and sent by the Wix Data backend in every request.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

In addition to the settings object, the request context object contains the

instanceId
,
installationId
,
memberId
, and
memberRole
. Each of these properties can be used to implement a permissions model controlling access to operations and data. Permissions can be implemented based on the site making the request, the external collection within the site, the visitor's member ID, and the member's role.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

Errors

Each SPI call returns a response including an HTTP status code. If an error
response is required, the response must include an error status code and a message that describes the type of error that occurred.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The error message should be in the following format:

0 reactions
heart.png
light.png
money.png
thumbs-down.png
{
  "message": "..."
}

Use the following HTTP Status/Error codes:

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Note

4XX statuses will appear in the error produced by the Wix Data function call.

Example Data

The examples in this reference are based on the Adapter for MySQL databases prototype deployed to Google AppEngine.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The prototype is connected to a database with the following tables and data:

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Car Table

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Car Table Data

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Manufacturer Table

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Manufacturer Table Data

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Provisioning Overview

The Provision SPI describes the endpoint and payload for provisioning API
requests to your external database and the payload for their success and failure responses.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Provision API requests occur when you initially connect your endpoint to your site or change its settings.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

A response status of anything other than a 200 status will result in the configuration of the external collection not being saved by the Wix Editor.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Provision

Setup initial connectivity between your adapter and the wix-data backend.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

POST: https://example.com/provision

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Body Params

0 reactions
heart.png
light.png
money.png
thumbs-down.png

https://support.wix.com/en/article/corvid-adding-and-deleting-an-external-database-collection

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Response Object

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Status/Error Codes:

401 - Not authorized.

400 - Request not valid.

Returns an empty object.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Provisioning request.

0 reactions
heart.png
light.png
money.png
thumbs-down.png
curl -X POST 'https://mysql-adaptor.com/provision' \
--header 'Content-Type: application/json' \
--data-raw '{
    "requestContext": {
        "settings": {
            "secretKey": "myBigSecret"
        },
        "installationId": "987fe654-3d21-4def-ab5c-6d78e90f123a",
    }
}'
{}

Request Context Object

The Request Context object is sent with every request. It contains information about who made the request, and which site and which external collection configuration made the request. Use the

member_id
in the request context object to implement permissions in your adapter.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

Settings

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The contents of the

settings
object are static and set in the Configuration section when setting up the external collection. Use the settings object to carry any static data you want to send to the adapter from your site.
The prototype adaptor uses the settings object to receive the
secretKey
for authentication. Add attributes to the settings object to support any functionality you want to implement in your adapter.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

instance_id

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The

instance_id
is a UUID that uniquely identifies the Wix site that is making the request. You can create an external database collection in more than one Wix site that points to the same adaptor and external database. Use the instance_id to control access to your date on a per-site basis.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

installation_id

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The

installation_id
is a UUID that uniquely identifies the external collection configuration within your site. You can create more than one external collection in the same site that points to the same adaptor and external database. Each of these external collections will be identified by its own UUID, allowing you to implement different functionality and
permissions for each one.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

member_id

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The

member_id
identifies the site visitor making the request. When creating new items, the Wix data backend populates the
_owner
attribute with the member_id. If the visitor is not a logged-in member, the member_id is based on a browser cookie and therefore consistent
between sessions. The member_id will be null if the code that made the request was triggered by a backend process. Use member_id to filter data by user and to implement permissions in your adapter.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

member_role

0 reactions
heart.png
light.png
money.png
thumbs-down.png

The

member_role
describes the role of the site visitor making the request. If the request is made by backend code and the
find()
function uses the
suppressAuth
option, the
member_role
will be set to
BACKEND_CODE
and the
member_id
will be
null
. In all other cases where backend code makes the request, the
member_role
will be set to
VISITOR
and the
member_id
will be
null
.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

Attributes

0 reactions
heart.png
light.png
money.png
thumbs-down.png

https://support.wix.com/en/article/corvid-adding-and-deleting-an-external-database-collection

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Request Context

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Example request context object.

0 reactions
heart.png
light.png
money.png
thumbs-down.png
{"requestContext": {

  "settings": {"secretKey": "mySecureSecret"},

  "instanceId": "12a345b6-7890-98d7-65e4-f321abc1de23",

  "installationId": "987fe654-3d21-4def-ab5c-6d78e90f123a",

  "memberId": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",

  "role": "OWNER"

}}

Schema Overview

The Schema SPI describes the endpoints and payloads for schema API requests to your external database and the payloads for their success and
failure responses. Schema API requests may occur whenever your site
needs to interact with the data in your external collection. The schema
may be cached for at most the amount of time indicated in the

ttl
field of the
schema
object.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

Schema Object

Metadata describing collection or table.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Attributes

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Schema

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Example schema object.

0 reactions
heart.png
light.png
money.png
thumbs-down.png
{"schema": {

  "displayName": "manufacturer",

  "id": "manufacturer",

  "allowedOperations":   [

    "get",

    "find",

    "count",

    "update",

    "insert",

    "remove"

  ],

  "maxPageSize": 50,

  "ttl": 3600,

  "fields":   {

    "name":     {

      "displayName": "name",

      "type": "text",

      "queryOperators":       [

        "eq",

        "lt",

        "gt",

        "hasSome",

        "and",

        "lte",

        "gte",

        "or",

        "not",

        "ne",

        "startsWith",

        "endsWith"

      ]

    },

    "country":     {

      "displayName": "country",

      "type": "text",

      "queryOperators":       [

        "eq",

        "lt",

        "gt",

        "hasSome",

        "and",

        "lte",

        "gte",

        "or",

        "not",

        "ne",

        "startsWith",

        "endsWith"

      ]

    },

    "established":     {

      "displayName": "established",

      "type": "datetime",

      "queryOperators":       [

        "eq",

        "lt",

        "gt",

        "hasSome",

        "and",

        "lte",

        "gte",

        "or",

        "not",

        "ne",

        "startsWith",

        "endsWith"

      ]

    },

    "_id":     {

      "displayName": "_id",

      "type": "text",

      "queryOperators":       [

        "eq",

        "lt",

        "gt",

        "hasSome",

        "and",

        "lte",

        "gte",

        "or",

        "not",

        "ne",

        "startsWith",

        "endsWith"

      ]

    },

    "_owner":     {

      "displayName": "_owner",

      "type": "text",

      "queryOperators":       [

        "eq",

        "lt",

        "gt",

        "hasSome",

        "and",

        "lte",

        "gte",

        "or",

        "not",

        "ne",

        "startsWith",

        "endsWith"

      ]

    },

    "share_price":     {

      "displayName": "share_price",

      "type": "number",

      "queryOperators":       [

        "eq",

        "lt",

        "gt",

        "hasSome",

        "and",

        "lte",

        "gte",

        "or",

        "not",

        "ne",

        "startsWith",

        "endsWith"

      ]

    }

  }

}}

Find Schemas

Get a list of schema objects base on a list of schema IDs.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

POST: https://example.com/schemas/find

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Body Params

0 reactions
heart.png
light.png
money.png
thumbs-down.png

https://support.wix.com/en/article/corvid-adding-and-deleting-an-external-database-collection

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Response Object

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Status/Error Codes:

404 - No schemas found

Get a list of schema objects in the list ["car","manufacturer"].

0 reactions
heart.png
light.png
money.png
thumbs-down.png
curl -X POST \
'https://mysql-adapter.com/schemas/find'  \
--header 'Content-Type: application/json' \
--data-raw '{
    "requestContext": {
        "settings": {
            "secretKey": "mySecureSecret"
        },
        "instanceId": "12a345b6-7890-98d7-65e4-f321abc1de23",
        "installationId": "987fe654-3d21-4def-ab5c-6d78e90f123a",
        "memberId": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",
        "role": "OWNER"
    },
    "schemaIds": [
        "car",
        "manufacturer"
    ]
}'
{"schemas": [

    {

    "displayName": "car",

    "id": "car",

    "allowedOperations":     [

      "get",

      "find",

      "count",

      "update",

      "insert",

      "remove"

    ],

    "maxPageSize": 50,

    "ttl": 3600,

    "fields":     {

      "_id":       {

        "displayName": "_id",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "_owner":       {

        "displayName": "_owner",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "make":       {

        "displayName": "make",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "model":       {

        "displayName": "model",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "year":       {

        "displayName": "year",

        "type": "number",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "date_added":       {

        "displayName": "date_added",

        "type": "datetime",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      }

    }

  },

    {

    "displayName": "manufacturer",

    "id": "manufacturer",

    "allowedOperations":     [

      "get",

      "find",

      "count",

      "update",

      "insert",

      "remove"

    ],

    "maxPageSize": 50,

    "ttl": 3600,

    "fields":     {

      "name":       {

        "displayName": "name",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "country":       {

        "displayName": "country",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "established":       {

        "displayName": "established",

        "type": "datetime",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "_id":       {

        "displayName": "_id",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "_owner":       {

        "displayName": "_owner",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "share_price":       {

        "displayName": "share_price",

        "type": "number",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      }

    }

  }

]}

List Available Schemas

Get a list of all schema objects.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

POST: https://example.com/schemas/list

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Body Params

0 reactions
heart.png
light.png
money.png
thumbs-down.png

https://support.wix.com/en/article/corvid-adding-and-deleting-an-external-database-collection

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Response Object

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Get a list of all available schemas.

0 reactions
heart.png
light.png
money.png
thumbs-down.png
curl -X POST 'https://mysql-adapter.com/schemas/list' \
--header 'Content-Type: application/json' \
--data-raw '{
    "requestContext": {
        "settings": {
            "secretKey": "mySecureSecret"
        },
        "instanceId": "12a345b6-7890-98d7-65e4-f321abc1de23",
        "installationId": "987fe654-3d21-4def-ab5c-6d78e90f123a",
        "memberId": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",
        "role": "OWNER"
    }
}'
{"schemas": [

    {

    "displayName": "car",

    "id": "car",

    "allowedOperations":     [

      "get",

      "find",

      "count",

      "update",

      "insert",

      "remove"

    ],

    "maxPageSize": 50,

    "ttl": 3600,

    "fields":     {

      "_id":       {

        "displayName": "_id",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "_owner":       {

        "displayName": "_owner",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "make":       {

        "displayName": "make",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "model":       {

        "displayName": "model",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "year":       {

        "displayName": "year",

        "type": "number",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "date_added":       {

        "displayName": "date_added",

        "type": "datetime",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      }

    }

  },

    {

    "displayName": "manufacturer",

    "id": "manufacturer",

    "allowedOperations":     [

      "get",

      "find",

      "count",

      "update",

      "insert",

      "remove"

    ],

    "maxPageSize": 50,

    "ttl": 3600,

    "fields":     {

      "name":       {

        "displayName": "name",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "country":       {

        "displayName": "country",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "established":       {

        "displayName": "established",

        "type": "datetime",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "_id":       {

        "displayName": "_id",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "_owner":       {

        "displayName": "_owner",

        "type": "text",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      },

      "share_price":       {

        "displayName": "share_price",

        "type": "number",

        "queryOperators":         [

          "eq",

          "lt",

          "gt",

          "hasSome",

          "and",

          "lte",

          "gte",

          "or",

          "not",

          "ne",

          "startsWith",

          "endsWith"

        ]

      }

    }

  }

]}

Data Overview

The Data SPI describes the endpoints and payloads for data API requests to your external database and the payloads for their success and failure
responses. Data API requests occur whenever your site needs to interact
with the data in your external collection.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Insert Item

Insert a new item into a collection.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

POST: https://example.com/data/insert

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Body Params

0 reactions
heart.png
light.png
money.png
thumbs-down.png

https://support.wix.com/en/article/corvid-adding-and-deleting-an-external-database-collection

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Response Object

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Status/Error Codes:

400 - Invalid item, Constraint violation.

409 - Item already exists.

Insert an item into a collection.

0 reactions
heart.png
light.png
money.png
thumbs-down.png
curl -X POST 'https://mysql-adapter.com/data/insert' \
--header 'Content-Type: application/json' \
--data-raw '{
    "requestContext": {
        "settings": {
            "secretKey": "mySecureSecret"
        },
        "instanceId": "12a345b6-7890-98d7-65e4-f321abc1de23",
        "installationId": "987fe654-3d21-4def-ab5c-6d78e90f123a",
        "memberId": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",
        "role": "OWNER"
    },
    "collectionName": "car",
    "item": {
        "_id": "12345678-abcd-9876-fedc-a9876543210",
        "_owner": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",
        "make": "BMW",
        "model": "i8",
        "year": 2020,
        "date_added": {
            "$date": "2020-01-01T21:00:00.000Z"
        }
    }
}'
{"item": {

  "_id": "12345678-abcd-9876-fedc-a9876543210",

  "_owner": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",

  "make": "BMW",

  "model": "i8",

  "year": 2020,

  "date_added": {"$date": "2020-01-01T21:00:00.000Z"}

}}

Get Item

Get an item based on its

itemId
.
0 reactions
heart.png
light.png
money.png
thumbs-down.png

POST: https://example.com/data/get

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Body Params

0 reactions
heart.png
light.png
money.png
thumbs-down.png

https://support.wix.com/en/article/corvid-adding-and-deleting-an-external-database-collection

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Response Object

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Status/Error Codes:

404 - Item not found.

Get an item from a collection based on the

_id
field.
0 reactions
heart.png
light.png
money.png
thumbs-down.png
curl -X POST 'https://mysql-adapter.com/data/get' \
--header 'Content-Type: application/json' \
--data-raw '{
    "requestContext": {
        "settings": {
            "secretKey": "mySecureSecret"
        },
        "instanceId": "12a345b6-7890-98d7-65e4-f321abc1de23",
        "installationId": "987fe654-3d21-4def-ab5c-6d78e90f123a",
        "memberId": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",
        "role": "OWNER"
    },
    "collectionName": "car",
    "itemId": "86cbf595-d369-48bb-8649-c6c082c003ca"
}'
{"item": {

  "_id": "86cbf595-d369-48bb-8649-c6c082c003ca",

  "_owner": "81c9168e-95b8-47fd-8e6a-ad9fdf71b38e",

  "make": "Ford",

  "model": "Mustang",

  "year": 2001,

  "date_added": {"$date": "2001-06-07T21:00:00.000Z"}

}}

Find Items

Get a list of items based on a filter.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

POST: https://example.com/data/find

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Body Params

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Response Object

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Get data matching a filter from a collection.

0 reactions
heart.png
light.png
money.png
thumbs-down.png
curl -X POST 'https://mysql-adapter.com/data/find'  \
--header 'Content-Type: application/json'  \
--data-raw '{
    "requestContext": {
        "settings": {
            "secretKey": "mySecureSecret"
        },
        "instanceId": "12a345b6-7890-98d7-65e4-f321abc1de23",
        "installationId": "987fe654-3d21-4def-ab5c-6d78e90f123a",
        "memberId": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",
        "role": "OWNER"
    },
   "collectionName": "car",
    "filter": {
        "operator": "$and",
        "value": [
            {
                "operator": "$contains",
                "fieldName": "make",
                "value": "a"
            },
            {
                "operator": "$gt",
                "fieldName": "year",
                "value": 2018
            }
        ]
    },
    "sort": [
        {
            "fieldName": "year",
            "direction": "asc"
        }
    ],
    "skip": 0,
    "limit": 10000
}'
{

  "items":   [

        {

      "_id": "95953ca3-5fe5-4ce7-9cca-9bcc1ba64ba6",

      "_owner": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",

      "make": "Toyota",

      "model": "Corolla",

      "year": 2019,

      "date_added": {"$date": "2020-09-30T21:30:00.000Z"}

    },

        {

      "_id": "20cd8f8d-1a0f-4530-91df-6d31fe9e83a5",

      "_owner": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",

      "make": "Ferrari",

      "model": "812GTS",

      "year": 2020,

      "date_added": {"$date": "2020-03-31T21:00:00.000Z"}

    }

  ],

  "totalCount": 2

}

Update Item

Update an item in a collection.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

POST: https://example.com/data/update

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Body Params

0 reactions
heart.png
light.png
money.png
thumbs-down.png

https://support.wix.com/en/article/corvid-adding-and-deleting-an-external-database-collection

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Response Object

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Status/Error Codes:

400 - Invalid item, Constraint violation.

404 - Item not found

Update an item in a collection.

0 reactions
heart.png
light.png
money.png
thumbs-down.png
curl -X POST 'https://mysql-adapter.com/data/update' \
--header 'Content-Type: application/json' \
--data-raw '{
    "requestContext": {
        "settings": {
            "secretKey": "mySecureSecret"
        },
        "instanceId": "12a345b6-7890-98d7-65e4-f321abc1de23",
        "installationId": "987fe654-3d21-4def-ab5c-6d78e90f123a",
        "memberId": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",
        "role": "OWNER"
    },
    "collectionName": "car",
    "item": {
        "_id": "86cbf595-d369-48bb-8649-c6c082c003ca",
        "_owner": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",
        "model": "Mustang GTR"
    }
}'
{"item": {

  "_id": "86cbf595-d369-48bb-8649-c6c082c003ca",

  "_owner": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",

  "model": "Mustang GTR"

}}

Remove Item

Remove an item from a collection.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

POST: https://example.com/data/remove

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Body Params

0 reactions
heart.png
light.png
money.png
thumbs-down.png

https://support.wix.com/en/article/corvid-adding-and-deleting-an-external-database-collection

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Response Object

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Status/Error Codes:

404 - Item not found

Delete an item from a collection.

0 reactions
heart.png
light.png
money.png
thumbs-down.png
curl --X POST 'https://mysql-adapter.com/data/remove' \
--header 'Content-Type: application/json' \
--data-raw '{
    "requestContext": {
        "settings": {
            "secretKey": "mySecureSecret"
        },
        "instanceId": "12a345b6-7890-98d7-65e4-f321abc1de23",
        "installationId": "987fe654-3d21-4def-ab5c-6d78e90f123a",
        "memberId": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",
        "role": "OWNER"
    "collectionName": "car",
    "itemId": "12345678-abcd-9876-fedc-a9876543210"
}'
{"item": {

  "_id": "12345678-abcd-9876-fedc-a9876543210",

  "_owner": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",

  "make": "BMW",

  "model": "i8",

  "year": 2020,

  "date_added": {"$date": "2020-01-01T21:00:00.000Z"}

}}

Count

Count the number of items that match a filter.

0 reactions
heart.png
light.png
money.png
thumbs-down.png

POST: https://example.com/data/count

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Body Params

0 reactions
heart.png
light.png
money.png
thumbs-down.png

https://support.wix.com/en/article/corvid-adding-and-deleting-an-external-database-collection

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Response Object

0 reactions
heart.png
light.png
money.png
thumbs-down.png

Status/Error Codes:

400 - Invalid query.

Count items in a collection that match a filter.

0 reactions
heart.png
light.png
money.png
thumbs-down.png
curl -X POST 'https://mysql-adapter.com/data/count' \
--header 'Content-Type: application/json' \
--data-raw '{
    "requestContext": {
        "settings": {
            "secretKey": "mySecureSecret"
        },
        "instanceId": "12a345b6-7890-98d7-65e4-f321abc1de23",
        "installationId": "987fe654-3d21-4def-ab5c-6d78e90f123a",
        "memberId": "77aa88bb-2c2c-d3d3-4e4e-ff55aa66bb77",
        "role": "OWNER"
    },
    "collectionName": "car",
    "filter": {
        "operator": "$contains",
        "fieldName": "make",
        "value": "Hyundai"
    }
}'
{"totalCount": 2}

Previously published at https://www.wix.com/velo/reference/spis/external-database-collections/external-database-collections/data/count

0 reactions
heart.png
light.png
money.png
thumbs-down.png
6
heart.pngheart.pngheart.pngheart.png
light.pnglight.pnglight.pnglight.png
boat.pngboat.pngboat.pngboat.png
money.pngmoney.pngmoney.pngmoney.png
Share this story
Join Hacker Noon

Create your free account to unlock your custom reading experience.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK