deno.land / x / mongoose@6.7.5 / benchmarks / validate.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
const mongoose = require('../../mongoose');const Benchmark = require('benchmark');
const Schema = mongoose.Schema;const breakfastSchema = new Schema({ eggs: { type: Number, min: [6, 'Too few eggs'], max: 12 }, bacon: { type: Number, required: [true, 'Why no bacon?'] }, drink: { type: String, enum: ['Coffee', 'Tea'], required: function() { return this.bacon > 3; } }});const Breakfast = mongoose.model('Breakfast', breakfastSchema);
const badBreakfast = new Breakfast({ eggs: 2, bacon: 0, drink: 'Milk'});
const goodBreakfast = new Breakfast({ eggs: 6, bacon: 1, drink: 'Tea'});
const suite = new Benchmark.Suite();suite .add('invalid async', { defer: true, fn: function(deferred) { // avoid test inlining suite.name; badBreakfast.validate().catch(() => deferred.resolve()); } }) .add('valid async', { defer: true, fn: function(deferred) { // avoid test inlining suite.name; goodBreakfast.validate().then(() => deferred.resolve()); } }) .add('invalid sync', function() { badBreakfast.validateSync(); }) .add('valid sync', function() { goodBreakfast.validateSync(); }) .on('cycle', function(evt) { if (process.env.MONGOOSE_DEV || process.env.PULL_REQUEST) { console.log(String(evt.target)); } }) .run();
mongoose

Version Info

Tagged at
a year ago