@rugo-vn/driver

1.0.1 • Public • Published

Rugo Model

Rugo Drivers for contact with databases, filesystems.

Requirements

You must have MongoDB Tools installed to use import/export with mongo driver.

Usage

Create Drivers

Independent

import { createMongoDriver, createMemDriver, createFsDriver } from 'rugo-driver';

const mongoDriver = await createMongoDriver({ uri: '/the/connection/uri', cache: true });
const memDriver = await createMemDriver({ root: '/the/root/directory', cache: true });
const fsDriver = await createFsDriver({ root: '/the/root/directory', cache: true });

Plugin

import DriverPlugin from 'rugo-driver/plugin';

context = await DriverPlugin(context, { 
  uri: '/the/connection/uri', 
  root: '/the/root/directory',
  cache: true
});

console.log(context);
/*
{
  ...
  driver: { mongo, mem, fs }
  ...
}
*/

Basic Operation

const collection = await driver.getCollection('collection-name');

await collection.id(id);
await collection.get(id);
await collection.count(query);
await collection.list(query, controls);
await collection.create(doc);
await collection.patch(query, controls);
await collection.remove(query);

await collection.close();

Concept

Structure

Driver -> Collection -> Document

Caching

In MongoDB, when cache enabled, the entry point of driver and collections of its will be save to the cache memory.

API

Visit API documentation.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @rugo-vn/driver

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

68.1 kB

Total Files

18

Last publish

Collaborators

  • haova