View Source Sanity.Sync (sanity_sync v0.5.2)

For syncing content from Sanity CMS to Ecto.

suggested-strategy-for-syncing

Suggested strategy for syncing

  • Call sync/2 when a webhook is called to immediately create, update, or delete the document.
  • Use sync_all/1 for the inital import of documents and to reconcile created/updates webhooks that were missed.
  • Use reconcile_deleted/1 to reconcile any deleted webhooks that were missed.

Link to this section Summary

Functions

Gets a single document. Returns nil if document does not exist.

Gets a single document. Raises Ecto.NoResultsError if document does not exist.

Deletes any Sanity.Sync.Doc records in Ecto that correspond with documents that no longer exist in Sanity CMS.

Fetches a single document from Sanity. If the document exists then upsert_sanity_doc!/2 will be called. If the document doesn't exist, then the Sanity.Sync.Doc for that document will be deleted.

Fetches all documents from Sanity and calls upsert_sanity_doc!/2.

Upserts a sanity document.

Link to this section Functions

Gets a single document. Returns nil if document does not exist.

Gets a single document. Raises Ecto.NoResultsError if document does not exist.

Deletes any Sanity.Sync.Doc records in Ecto that correspond with documents that no longer exist in Sanity CMS.

options

Options

Fetches a single document from Sanity. If the document exists then upsert_sanity_doc!/2 will be called. If the document doesn't exist, then the Sanity.Sync.Doc for that document will be deleted.

options

Options

  • :callback (function of arity 1) - Callback function that will be called after the document is upserted. It will be passed a map like %{doc: doc, repo: repo}. This callback is not called when the record is deleted.

  • :request_opts (keyword/0) - Required. Options to be passed to Sanity.request/2.

Fetches all documents from Sanity and calls upsert_sanity_doc!/2.

options

Options

  • :callback (function of arity 1) - Callback function that will be called after the document is upserted. It will be passed a map like %{doc: doc, repo: repo}. This callback is not called when the record is deleted.

  • :request_opts (keyword/0) - Required. Options to be passed to Sanity.request/2.

  • :types (list of String.t/0) - Required. List of types to sync.

Link to this function

upsert_sanity_doc!(doc, opts \\ [])

View Source

Upserts a sanity document.

options

Options

  • :callback (function of arity 1) - Callback function that will be called after the document is upserted. It will be passed a map like %{doc: doc, repo: repo}. This callback is not called when the record is deleted.