https://github.com/mikaelvesavuori/triplecheck-repository-cosmosdb-sql
Database utility for using CosmosDB (SQL) with TripleCheck broker.
https://github.com/mikaelvesavuori/triplecheck-repository-cosmosdb-sql
consumer-contracts consumer-driven-contracts contract-testing cosmosdb pacts sql triplecheck
Last synced: about 2 months ago
JSON representation
Database utility for using CosmosDB (SQL) with TripleCheck broker.
- Host: GitHub
- URL: https://github.com/mikaelvesavuori/triplecheck-repository-cosmosdb-sql
- Owner: mikaelvesavuori
- License: mit
- Created: 2021-04-27T13:20:10.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-22T14:51:51.000Z (about 2 years ago)
- Last Synced: 2025-01-16T16:22:23.721Z (4 months ago)
- Topics: consumer-contracts, consumer-driven-contracts, contract-testing, cosmosdb, pacts, sql, triplecheck
- Language: TypeScript
- Homepage:
- Size: 1.34 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# triplecheck-repository-cosmosdb-sql

## TripleCheck: Azure CosmosDB (SQL) database repository
Database utility for using CosmosDB (SQL) with TripleCheck broker.
## Instructions
You'll need to have a CosmosDB account up, a container (SQL) and set the Partition Key to `/id`. Also, I'd recommend maybe setting the consistency to "Strong". Consider using the serverless option for CosmosDB, since that will be a lot cheaper for smaller workloads.
## Basic implementation
In your `triplecheck-broker` implementation, do a regular import for `triplecheck-repository-cosmosdbsql` and pass the repository to the broker. In an Azure Functions context, an implementation could look like:
```TypeScript
import { TripleCheckBroker } from 'triplecheck-broker';
import { CosmosSqlRepository } from 'triplecheck-repository-cosmosdb-sql';export const config = {
endpoint: '',
key: '',
databaseId: 'triplecheck', // <--- example
containerId: 'broker_sql' // <--- example
};/**
* @description The handler.
*/
export async function handler(context: any, req: any) {
const [request, payload] = await getRequestData(req);const repository = CosmosSqlRepository(config);
const { responseData, status, headers } = await TripleCheckBroker(request, payload, repository);return {
status,
body: responseData
};
}/**
* @description Utility function to get the data we need to run the TripleCheck broker. Expects the full Azure Functions request object.
*/
async function getRequestData(req: any) {
const { body, method, url } = req;let [pathname, search] = url.split('?');
if (!pathname) pathname = url;const payload = typeof body === 'string' ? JSON.parse(body) : body;
return [
{
method,
pathname,
search
},
payload
];
}```