class-mongo v0.3.19
Lightweight but powerful MongoDB ORM on top of class entities.
with TypeScript support
class-json is used as a
Serialization
andValidation
library.this is loosely coupled and can be replaced with any other
Can be decoupled from base classes:
you may want to share same models in nodejs and browser environments
Short example to get the feeling.
import { Serializable, Json, Rule } from 'class-json'
export class User extends Serializable<User> {
_id: string
@Rule.required()
name: string
@Rule.pattern(/@/)
email: string
@Json.type(Date)
createdAt = new Date()
@Json.type(BigInt)
amount: bigint
}
import { User } from './User'
import { MongoEntityFor, table, index, dbType } from 'class-mongo'
@table('users')
export class UserDb extends MongoEntityFor(User) {
@index({ unique: true })
email: string
/*(MongoType, JsType)*/
@dbType('decimal', BigInt)
amount: bigint
}
// e.g
let user = new UserDb({
name: 'Smith',
email: 'foo@bar.fake'
});
await user.upsert();
console.log(user._id);
Same as a single class:
import { Serializable, Json, Rule } from 'class-json'
import { MongoEntity, table, index } from 'class-mongo'
@table('users')
export class User extends MongoEntity<User> {
_id: string
@index({ unique: true })
@Rule.required()
name: string
@Rule.pattern(/@/)
email: string
@Json.type(Date)
createdAt: Date
}
☰ API
1
class MongoEntity -1.01
static fetch -1.02
static fetchMany1.03
static count1.04
static upsert1.05
static upsertMany1.06
static upsertManyBy1.07
static patch1.08
static del1.09
static delMany1.10
static getCollection1.11
static getDb1.12
.upsert1.13
.patch1.14
.del
2.1
define2.2
interface IMongoSettings2.2.1
connection2.2.2
db2.2.3
ip2.2.4
port2.2.5
name
3.1
ensureAll
:copyright: MIT - Atma.js
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago