This is a basic sample of a Replicache backend for .Net/C#/CosmosDB.
- Setup a CosmosDB account as documented here.
- Create a new database called
replicache-sample-todo
and a container calleditems
. Set the partion key to/accountID
. - Run the sample:
dotnet run -- --cosmosEndpoint=<database-url> --cosmosAuthKey=<database-primary-key>
. Get thedatabase-url
anddatabase-primary-key
values from the "keys" pane of your CosmosDB dashboard.
- In order to behave correctly, CosmosDB must be configured for a minimum of "Consistent Prefix" consistency.
- Additionally, the
ClientState
entities MUST be stored in the same logical partition as the relevant values that will be served in the Client View.
The sample use stored procedures written in JavaScript since that is required
for doing multikey
transactions.
This ensures that mutations always occur atomically with the update of
LastMutationID
.
You can modify the lit-redo sample in the replicache-sdk-js repo to work with this CosmosDB backend. Here is how:
git clone https://github.com/rocicorp/replicache-sdk-js.git
cd replicache-sdk-js.git
npm install
Until we have self serve for the client view you need to run the diff-server locally:
# in replicache-sdk-js/
bin/diff-server serve --client-view=https://localhost:5001/replicache-client-view --db=/tmp/diff-server
Now we need to change the sample to use our local diff server and to use the replicache-client-view
and the replicache-batch
endpoints.
Modify sample/lit-todo/main.js
to use https://localhost:5001/replicache-batch
as the
batchURL
.
and you need to update
sample/lit-todo/main.js
to use your local diff-server by changing
diffServerURL
to http://localhost:7001/pull
.
Now you need to build lit-redo and start a web server hosting it.
# in replicache-sdk-js/sample/lit-redo
npm install # first time only
npm run build
npx http-server .
Don't forget to dotnet run
as described in Run.