0.3.2 • Published 5 years ago

base-schema v0.3.2

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

base-schema

Build Status

NPM

base-schema

:smile: mongoose base schema simply

functions

  • give schema append created_at updated_at and manage them
  • delete _id __v fields from output json
  • add the page method for paging

install

npm i base-schema -S

usage

const Schema = require('base-schema')
const Foo = Schema('Foo', {
    name: String
})
await Foo.create({ name: 'foo' })
await Foo.find({}).page(1, 10)

attribute

namerefdescription
Schema.ObjectIdmongoose.Schema.Types.ObjectIdA ref to mongoose.Schema.Types.ObjectId
Schema.Int32mongoose.Schema.Types.Int32A ref to mongoose-int32 module
Schema.Decimal128mongoose.Schema.Types.Decimal128A ref to mongoose.Schema.Types.Decimal128
Schema.Doublemongoose.Schema.Types.DoubleA ref to @mongoosejs/double module

default field

namerefdescription
phoneSchema.Field.phoneadd the phone and used_phones fields to Shema
passwordSchema.Field.passwordadd the password field and the compwd method to Shema
const { phone, password } = Schema.Field
const User = Schema('User', { phone: phone, password: password })
const user = await User.create({
    phone: '13812345678',
    password: '@lili520'
})
// user.phone = '13812345678'
// user.used_phones = ['13812345678']
// user.password = hash
// await user.compwd('@lili520') is true
// await User.findOne().select('+password +used_phones') 
// password and used_phones default no select

ObjectId used in the aggregation

const A = Schema('A', {
    name: String
})

const B = Schema('B', {
    name: String,
    a: {
        type: Schema.ObjectId,
        ref: 'A'
    }
})
// origin {a: new mongoose.Types.Object('5cf8e018e5fd67512487be2e')}
await B.aggregate().match({ a: Schema.Id('5cf8e018e5fd67512487be2e') })

test

npm test
0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.10

5 years ago

0.1.0

5 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago