0.3.19 • Published 3 years ago

class-mongo v0.3.19

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

Lightweight but powerful MongoDB ORM on top of class entities.

with TypeScript support

  • class-json is used as a Serialization and Validation 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


:copyright: MIT - Atma.js

0.3.17

3 years ago

0.3.15

3 years ago

0.3.14

3 years ago

0.3.19

3 years ago

0.3.18

3 years ago

0.3.13

3 years ago

0.3.12

3 years ago

0.3.11

3 years ago

0.3.10

3 years ago

0.3.9

3 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.3.6

3 years ago

0.3.4

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.99

3 years ago

0.2.98

3 years ago

0.2.97

4 years ago

0.2.95

4 years ago

0.2.94

4 years ago

0.2.93

4 years ago

0.2.92

4 years ago

0.2.91

4 years ago

0.2.90

4 years ago

0.2.89

4 years ago

0.2.88

4 years ago

0.2.87

4 years ago

0.2.86

4 years ago

0.2.85

4 years ago

0.2.84

4 years ago

0.2.83

4 years ago

0.2.81

4 years ago

0.2.80

4 years ago

0.2.78

4 years ago

0.2.77

4 years ago

0.2.76

4 years ago

0.2.73

4 years ago

0.2.72

4 years ago

0.2.71

4 years ago

0.2.69

4 years ago

0.2.68

4 years ago

0.2.67

4 years ago