MuffinClient

MuffinClient

new MuffinClient(options)

Use the MongoDB official Driver and allows you to create pieces, which are map-like objects. (with an optional cache)

Since:
  • 1.0
Source:
Parameters:
Name Type Description
options ClientOptions

Options for the client.

Example
// Creates a MuffinClient and connects to localhost with port 27017, using "muffin" as db's name
const client = new Muffin.Client()

Extends

  • EventEmitter

Members

closed :boolean

True if the database is closed.

Since:
  • 1.0
Source:
Type:
  • boolean

dbName :string

Name of the database, Muffin by default.

Since:
  • 1.0
Source:
Type:
  • string

defer :Promise.<void>

Resolved when the database is ready.

Since:
  • 1.0
Source:
Type:
  • Promise.<void>

isReady :boolean

True when the database is ready.

Since:
  • 1.0
Source:
Type:
  • boolean

Methods

close() → {void}

Close the database.

Since:
  • 1.0
Source:
Returns:
Type:
void

Nothing

multi(names, options) → {Object.<Piece>}

Creates multiple pieces.

Since:
  • 1.0
Source:
Parameters:
Name Type Description
names Array.<string>

Names of the pieces.

options PieceOptions

Options like cache or fetchAll.

Returns:
Type:
Object.<Piece>

An object with the pieces. Destructuring can be useful !

Example
const Muffin = require("muffindb");
// MuffinOptions is a placeholder for... muffin options
const client = new Muffin.Client(MuffinOptions);

// This will returns an object with pieces inside
// Theses pieces will have a cache because we used options
// fetchAll will make the pieces fetch the whole data and caches it
// Their cache will not be synchronized with the database because autoCacheSync is set to false
const pieces = client.multi(["a_piece", "another_piece", "third_piece"], { fetchAll: true, autoCacheSync: false })

piece(name, options) → {Piece}

Creates a Piece to interact with MongoDB.

Since:
  • 1.0
Source:
Parameters:
Name Type Description
name string

The piece's name.

options PieceOptions

Options like cache or fetchAll.

Returns:
Type:
Piece

A Piece with the given name

Example
const Muffin = require("muffindb");
// MuffinOptions is a placeholder for muffin options
const client = new Muffin.Client(MuffinOptions);

// This piece will have a cache because of fetchAll a
// fetchAll will make the piece fetch the whole data and caches it
// Its cache will not be synchronized with the database because autoCacheSync is set to false
const piece = client.piece("a_piece", { fetchAll: true, autoCacheSync: false })

Events

change

Emit when a change occurs on the database.

Since:
  • 1.1
Deprecated:
  • Use Piece#change instead
Source:
Type:
  • any

close

Emitted after a socket closed against a single server or mongos proxy.

Since:
  • 1.0
Source:

reconnect

Since:
  • 1.0
Source:
Type:
  • any

timeout

Emitted after a socket timeout occurred against a single server or mongos proxy.

Since:
  • 1.0
Source:
Type: