directdb

Turn a directory into a database using Markdown, YAML, and JSON.

Usage no npm install needed!

<script type="module">
  import directdb from 'https://cdn.skypack.dev/directdb';
</script>

README

🗂️ DirectDB

NPM GitHub Workflow Status Node.js Versions

Turn a directory into a database. Store data in folders and human-readable files like YAML, Markdown, and JSON.

Still in development. Expect breaking changes.

Install

npm i directdb
# or
yarn add directdb

Getting Started

import directdb from 'directdb'

const rootDir = '.' // Relative or absolute path to a directory
const db = await directdb(rootDir)

// $ is an alias for the root directory
await db.cache.dir['

] // get details about the root directory
await db.cache.file['$/some/file.json'] // get file details w/ parsed content

// CRUD methods; they update the caches too
await db.createFile('$/foo.yaml', ['some', 'data'])
await db.readFile('$/foo.txt') // reads file cache
await db.updateFile('$/foo.yaml', ['updated', 'data'])
await db.removeFile('$/foo.md')

await db.createDir('$/some/dir')
await db.readDir('$/some/dir') // reads dir cache
await db.removeDir('$/some/dir')

// search caches w/ plain JS
const results = Object.values(db.files).filter((fileDetails) =>
  fileDetails.contents.contains('Some Search String')
)

JSON, YAML, and Markdown w/ YAML front matter

db.file('$/foo.json').content // { some: ['data'] }
db.file('$/foo.yaml').content // { yaml: ['data'] }
db.file('$/foo.md').content // { markdown: "# Hello!", frontMatter: {} }

Optional JSON Schema Validation

$/
├─ .schema.json   // files in the folder will be validated against this
├─ someData.json
├─ moreData.yaml
└─ fileWithYamlFrontMatter.md

Docs

See local markdown docs, including:

Examples and Cookbook

Coming soon!