Using Yaml - nsc-de/js-database GitHub Wiki

If you want to use yaml instead of json, it's quite simple. You just need to replace the json-adapter with a yaml-adapter and install the js-yaml api

General

Installing js-yaml

install js-yaml using npm

npm i js-yaml

install js-yaml using yarn

yarn add nscdb

Async Yaml Adapter

Importing

(You can remove the import of the json adapter and replace it with this one)

Import using Typescript

import { YamlFileAdapter } from 'nscdb/yaml_adapter';

Import using Javascript

const { YamlFileAdapter } = require('nscdb/yaml_adapter');

Database Creation

When creating a database you have to use the YamlFileAdapter instead of the JsonFileAdapter.

let database = await createDatabase(new YamlFileAdapter ("./database.yml"));

From here it is the same as with the json adapter. The database should act exactly the same.

Sync Yaml Adapter

Importing

(You can remove the import of the json adapter and replace it with this one)

Import using Typescript

import { SyncYamlFileAdapter } from 'nscdb/yaml_adapter';

Import using Javascript

const { SyncYamlFileAdapter } = require('nscdb/yaml_adapter');

Database Creation

When creating a database you have to use the SyncYamlFileAdapter instead of the SyncJsonFileAdapter.

let database = createDatabase(new SyncYamlFileAdapter ("./database.yml"));

From here it is the same as with the json adapter. The database should act exactly the same.

⚠️ **GitHub.com Fallback** ⚠️