Sanity.io to Builder.io Data Transfer
Ads
I am hoping to make a Sanity.io plugin for builder. In doing so I thought I would write a little conversion tool before hand to figure out all the ins and outs of Builder.io and Sanity.io, so I thought I would share some of my findings. I will keep this tutorial updated as the plugin progresses.
The repo example has three things that you might find useful.
- Deleting All Data
- Creating all new types
- Adding all new Data
Repo for conversion example https://github.com/CodingCatDev/sanity-to-builder.git
Deleting All Data
https://github.com/CodingCatDev/sanity-to-builder/blob/84d8b5d436b2d674f916670317cb48de916c8a68/src/index.ts#L175
In order to delete all the data you need to first find all the models you want to delete
Get all Models from Builder (even unpublished)
In sanity you deal with things like draft.
in documents. In Builder these items are just known to be unpublished version. So you need to have includeUnpublished=true
in your API call. I looked for a while in the sdk and have not found this option so far.
You can handle this by using the fetch command instead of the sdk.
https://github.com/CodingCatDev/sanity-to-builder/blob/84d8b5d436b2d674f916670317cb48de916c8a68/src/config.ts#L134
Creating all new types
First you need to find all the types in your sanity.io database. I find it best to use Groq. So we can find all the types in Sanity and then create those in Builder as new Models.
Adding all new Data
Long Term goal
The End goal is to build a plugin for syncing your data...
Builder content link https://github.com/BuilderIO/builder/tree/main/plugins/contentful