0.5.1 ⢠Published 4 years ago
directdb v0.5.1
šļø DirectDB
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!