sync
connector.sync(fn)
Used to define what happens when data initially syncs from your data source into a Netlify Connect data layer, and what happens on subsequent syncs to update the data.
Takes a function with an object as a parameter. The object contains the following properties:
Parameter | Description |
---|---|
models | Object that contains all defined document models, and the insert and delete methods for each one. |
cache | Helper for storing and accessing non-node data (like CMS sync tokens). |
isInitialSync | Boolean that will be true on initial data syncs and false on subsequent data syncs. |
options | Object that contains the configuration values set for options defined using defineOptions() . |
state | Object that includes data stored during init() . |
webhookBody | Object that contains the information sent through a webhook body. |
Learn more about specifying how to create and update data.
models
Object that contains each document model you define with define.document()
. Use this object to insert and delete data when there is a sync event.
Property | Description |
---|---|
{model_name} | The name of each defined document model is a property on the models object. Contains the insert and delete methods for each one. |
concurrent() | Method used to fetch multiple data types from your data source concurrently. |
model name
models.{model_name}
Object that represents a defined document model. The object contains the following methods:
Method | Description |
---|---|
insert() | Used to insert data for this model type. Takes an object reperesenting the data to insert. |
delete() | Used to delete data for this model type. Takes a String value representing the node’s ID. |
For example, if you define a Post
document model, you can use models.Post.insert()
and models.Post.delete()
.
Usage example
concurrent
models.concurrent()
Method to fetch multiple data types from your data source concurrently.
Parameter | Description |
---|---|
count | Number of models to fetch concurrently. |
callback() | Function to run in parallel. |
Usage example
cache
Helper for storing and accessing non-node data (like CMS sync tokens). Contains the following methods:
Method | Description |
---|---|
set() | Pass in a key and value to store or update. Returns a promise. |
get() | Pass in a key to retrieve the stored value. Returns a promise. |
delete() | Pass in a key to delete the stored value. Returns a promise. |
Learn more about the cache
helper.