Skip to content

Commit

Permalink
add database docs
Browse files Browse the repository at this point in the history
  • Loading branch information
logan-anderson committed Jul 24, 2023
1 parent 3b54b7a commit 9ccdc7a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
9 changes: 8 additions & 1 deletion content/docs/self-hosted/database-adapter/make-your-own.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 30 additions & 1 deletion content/docs/self-hosted/database-adapter/mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Record<string, any>>({
// 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,
}),
})
```

```
```
19 changes: 16 additions & 3 deletions content/docs/self-hosted/database-adapter/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
```
32 changes: 31 additions & 1 deletion content/docs/self-hosted/database-adapter/vercel-kv.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
})
```

0 comments on commit 9ccdc7a

Please sign in to comment.