https://github.com/antyfive/teo-db-adapter-mongoose
Mongoose adapter for Teo.JS
https://github.com/antyfive/teo-db-adapter-mongoose
Last synced: about 1 month ago
JSON representation
Mongoose adapter for Teo.JS
- Host: GitHub
- URL: https://github.com/antyfive/teo-db-adapter-mongoose
- Owner: Antyfive
- License: mit
- Created: 2016-11-16T06:45:26.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-12T18:10:54.000Z (over 9 years ago)
- Last Synced: 2025-02-17T08:46:53.370Z (over 1 year ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# teo-db-adapter-mongoose
Mongoose adapter for [Teo.JS](https://github.com/Antyfive/teo.js).
## Installation
`npm i -S teo-db-adapter-mongoose`
## Usage Example
```javascript
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.
```javascript
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.