1.2.0 • Published 7 years ago

teo-db-adapter-mongoose v1.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

teo-db-adapter-mongoose

Mongoose adapter for Teo.JS.

Installation

npm i -S teo-db-adapter-mongoose

Usage Example

const MongooseAdapter = require("teo-db-adapter-mongoose");
const adapter = new MongooseAdapter({
  // this config is usually set in Teo.JS configuration file
  host: "localhost",
  dbName: "test"
});

Example of the real model, which can be created in Teo.JS application.

const identity = "test";
const Schema = require('mongoose').Schema;

const schema = new Schema({
    title:  String,
    author: String,
    body:   String,
    comments: [{ body: String, date: Date }],
    date: { type: Date, default: Date.now },
    hidden: Boolean,
    meta: {
        votes: Number,
        favs:  Number
    }
});

module.exports = {identity, schema};

Each model should have identity, and schema properties. To add a model directly via this API, call adapter.addModel({idenity: 'users', schema: new Mongoose.Schema({/**/})}).

API

addModel(shemaObject{})

connect() generator function

Connects ORM. All models should be loaded before the connection to DB.

disconnect() generator function

Disconnects ORM.

isConnected()

Returns boolean to detect if connection is set.

1.2.0

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago