-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.ts
85 lines (75 loc) · 1.88 KB
/
example.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { Collection, IDBConfig } from '../src/index'
interface Book {
title: string
author: string
isbn?: string
objectId?: string
createdAt?: Date
updatedAt?: Date
}
const dbConfig: IDBConfig = {
appId: '',
appKey: '',
serverURLs: ''
}
const bookApi = new Collection<Book>(dbConfig, 'Book')
bookApi.findAll({
where: {
"createdAt":{"$gte":{"__type":"Date","iso":"2015-06-29T00:00:00.000Z"},"$lt":{"__type":"Date","iso":"2015-06-30T00:00:00.000Z"}},
updatedAt: {
$gte: { "__type": "Date", "iso": "2015-06-29T00:00:00.000Z"},
$lt: {}
},
"upvotes":{"$in":[1,3,5,7,9]},
"pubUser":{"$nin":["官方客服"]},
"upvots":{"$exists":true},
"user":{
"__type": "Pointer",
"className": "_User",
"objectId": "55a39634e4b0ed48f0c1845c"
},
"title":{"$regex":"^WTO.*","$options":"i"},
"arrayKey":{"$all":[2,3,4]},
arrayKey2: { $size: 3 },
post: { __type: 'Pointer', className: 'Post', objectId: '558e20cbe4b060308e3eb36c' },
post2: { $inQuery: { where: { image: { $exists: true}}, className: 'Post' }},
$or: [{"pubUserCertificate": {$gt: 2}}, {"pubUserCertificate": {$lt: 3}}],
},
order: '-createdAt',
limit: 200,
skip: 400,
keys: '-author, name',
count: 10,
include: 'post.author',
}).then(books => {
books
}).catch(reason => {
console.error('bookApi.findAll Error', reason)
})
bookApi.findAndCount({}).then(({ results, count }) => {
results
count
})
bookApi.create({
title: 'javascript'
}).then(res => {
res.createdAt
res.objectId
})
bookApi.update({
objectId: '1',
title: 'javascript-1'
}, '1').then(res => {
res.updatedAt
})
bookApi.batch([]).then(arr => {
arr.map(i => {
if (i.success) {
i.success.aaa
i.success.updatedAt
}
})
})
bookApi.batchCreate([
{ title: 'javascript-2' },
])