From 9ccdc7a4a9a9579a4d4a3ea499faaf005ee18272 Mon Sep 17 00:00:00 2001 From: Logan Anderson Date: Mon, 24 Jul 2023 11:18:06 -0400 Subject: [PATCH] add database docs --- .../database-adapter/make-your-own.md | 9 +++++- .../self-hosted/database-adapter/mongodb.md | 31 +++++++++++++++++- .../self-hosted/database-adapter/overview.md | 19 +++++++++-- .../self-hosted/database-adapter/vercel-kv.md | 32 ++++++++++++++++++- 4 files changed, 85 insertions(+), 6 deletions(-) diff --git a/content/docs/self-hosted/database-adapter/make-your-own.md b/content/docs/self-hosted/database-adapter/make-your-own.md index a34fde8a4..c68639a90 100644 --- a/content/docs/self-hosted/database-adapter/make-your-own.md +++ b/content/docs/self-hosted/database-adapter/make-your-own.md @@ -5,4 +5,11 @@ prev: '/docs/self-hosted/database-adapter/mongodb' next: null --- -TODO: +The database adapter uses the [abstract level]() interface. To implement your own database adapter you will need to follow that interface. + +Here is some example of the ones we have built: + +- [upstash-redis-level](https://github.com/tinacms/upstash-redis-level) +- [mongodb-level](https://github.com/tinacms/mongodb-level) + +TODO: add more details here diff --git a/content/docs/self-hosted/database-adapter/mongodb.md b/content/docs/self-hosted/database-adapter/mongodb.md index 652a41d3c..210172363 100644 --- a/content/docs/self-hosted/database-adapter/mongodb.md +++ b/content/docs/self-hosted/database-adapter/mongodb.md @@ -5,4 +5,33 @@ prev: '/docs/self-hosted/database-adapter/vercel-kv' next: '/docs/self-hosted/database-adapter/make-your-own' --- -TODO: +The MongoDB database adapter allows you to store your data in a [MongoDB](https://www.mongodb.com/) database. This adapter uses the [mongodb](https://www.npmjs.com/package/mongodb) so it will work on any MongoDB database. + +To get started you will need to add the following environment variables to your project: + +```env +MONGODB_URI=*** +``` + +## Create the database adapter + +```ts +import { MongodbLevel } from 'mongodb-level' +//... + +export default isLocal + ? createLocalDatabase() + : createDatabase({ + // ... + databaseAdapter: new MongodbLevel>({ + // If you wanted to use a different collection for each branch the branch name could be used as the collection name + collectionName: 'tinacms', + dbName: 'tinacms', + mongoUri: process.env.MONGODB_URI as string, + }), + }) +``` + +``` + +``` diff --git a/content/docs/self-hosted/database-adapter/overview.md b/content/docs/self-hosted/database-adapter/overview.md index 673fdbada..84b8ce22b 100644 --- a/content/docs/self-hosted/database-adapter/overview.md +++ b/content/docs/self-hosted/database-adapter/overview.md @@ -5,7 +5,20 @@ prev: null next: /docs/self-hosted/database-adapter/vercel-kv --- -The database adapter is a wrapper around an existing data storage and handles indexing, listing and managing content. We provide a two database adaptors out of the box: +A database adapter is a module that allows you to store your data in a database of your choice. The database adapter is responsible for storing, retrieving and indexing data from and to the database. We currently have support for the following database adapters: -* Vercel KV -* MongoDB +- [Vercel KV](/docs/self-hosted/database-adapter/vercel-kv) +- [MongoDB](/docs/self-hosted/database-adapter/mongodb) + +With plans on supporting more in the future. + +Adding a database adapter can be done in the `database.{ts,js}` file by passing it to the `createDatabase` function. + +```ts +// ... + +export isLocal ? createLocalDatabase() : createDatabase({ + // ... + databaseAdapter: new DatabaseAdapter() +}) +``` diff --git a/content/docs/self-hosted/database-adapter/vercel-kv.md b/content/docs/self-hosted/database-adapter/vercel-kv.md index b0a34cdd5..309170ebb 100644 --- a/content/docs/self-hosted/database-adapter/vercel-kv.md +++ b/content/docs/self-hosted/database-adapter/vercel-kv.md @@ -5,4 +5,34 @@ prev: '/docs/self-hosted/database-adapter/overview' next: '/docs/self-hosted/database-adapter/mongodb' --- -TODO: +The vercel KV database adapter allows you to store your data in the [Vercel KV](https://vercel.com/docs/concepts/projects#environment-variables). This adapter uses the [upstash redis client](https://www.npmjs.com/package/@upstash/redis) so will work on [upstash redis](https://docs.upstash.com/redis) as well. + +To get started you will need to add the following environment variables to your project: + +```env +KV_REST_API_URL=*** +KV_REST_API_TOKEN=*** +``` + +## Create the database adapter + +```ts +//... +import { RedisLevel } from 'upstash-redis-level' +import { Redis } from '@upstash/redis' + +export default isLocal + ? createLocalDatabase() + : createDatabase({ + // ... + + databaseAdapter: new RedisLevel({ + namespace: branch, + redis: new Redis({ + url: process.env.KV_REST_API_URL || 'http://localhost:8079', + token: process.env.KV_REST_API_TOKEN || 'example_token', + }), + debug: process.env.DEBUG === 'true' || false, + }), + }) +```