@react-native-agconnect/clouddb
Version:
React Native AGC CloudDB
201 lines (177 loc) • 4.94 kB
JavaScript
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
*/
import { NativeModules } from 'react-native';
const { AGCCloudDBModule } = NativeModules;
export default class AGCCloudDBQuery {
static CloudDBZoneQueryPolicy = {
POLICY_QUERY_DEFAULT: AGCCloudDBModule.CloudDBZoneQueryPolicy.POLICY_QUERY_DEFAULT,
POLICY_QUERY_FROM_CLOUD_ONLY: AGCCloudDBModule.CloudDBZoneQueryPolicy.POLICY_QUERY_FROM_CLOUD_ONLY,
POLICY_QUERY_FROM_LOCAL_ONLY: AGCCloudDBModule.CloudDBZoneQueryPolicy.POLICY_QUERY_FROM_LOCAL_ONLY,
}
constructor(className) {
this.queryMap = {
className: className,
queryElements: [],
}
}
static where(className) {
return new AGCCloudDBQuery(className);
}
equalTo(fieldName, value) {
this.queryMap.queryElements.push({
operation: this.equalTo.name,
fieldName: fieldName,
value: value,
})
return this
}
notEqualTo(fieldName, value) {
this.queryMap.queryElements.push({
operation: this.notEqualTo.name,
fieldName: fieldName,
value: value,
})
return this
}
greaterThan(fieldName, value) {
this.queryMap.queryElements.push({
operation: this.greaterThan.name,
fieldName: fieldName,
value: value,
})
return this
}
greaterThanOrEqualTo(fieldName, value) {
this.queryMap.queryElements.push({
operation: this.greaterThanOrEqualTo.name,
fieldName: fieldName,
value: value,
})
return this
}
lessThan(fieldName, value) {
this.queryMap.queryElements.push({
operation: this.lessThan.name,
fieldName: fieldName,
value: value,
})
return this
}
lessThanOrEqualTo(fieldName, value) {
this.queryMap.queryElements.push({
operation: this.lessThanOrEqualTo.name,
fieldName: fieldName,
value: value,
})
return this
}
in(fieldName, value) {
this.queryMap.queryElements.push({
operation: this.in.name,
fieldName: fieldName,
value: value,
})
return this
}
beginsWith(fieldName, value) {
this.queryMap.queryElements.push({
operation: this.beginsWith.name,
fieldName: fieldName,
value: value,
})
return this
}
endsWith(fieldName, value) {
this.queryMap.queryElements.push({
operation: this.endsWith.name,
fieldName: fieldName,
value: value,
})
return this
}
contains(fieldName, value) {
this.queryMap.queryElements.push({
operation: this.contains.name,
fieldName: fieldName,
value: value,
})
return this
}
isNull(fieldName) {
this.queryMap.queryElements.push({
operation: this.isNull.name,
fieldName: fieldName,
})
return this
}
isNotNull(fieldName) {
this.queryMap.queryElements.push({
operation: this.isNotNull.name,
fieldName: fieldName,
})
return this
}
orderByAsc(fieldName) {
this.queryMap.queryElements.push({
operation: this.orderByAsc.name,
fieldName: fieldName,
})
return this
}
orderByDesc(fieldName) {
this.queryMap.queryElements.push({
operation: this.orderByDesc.name,
fieldName: fieldName,
})
return this
}
limit(count, offset) {
if (offset) {
this.queryMap.queryElements.push({
operation: this.limit.name,
value: count,
offset: offset
})
return this
} else {
this.queryMap.queryElements.push({
operation: this.limit.name,
value: count,
})
return this
}
}
startAt(object) {
this.queryMap.queryElements.push({
operation: this.startAt.name,
value: object
})
return this
}
startAfter(object) {
this.queryMap.queryElements.push({
operation: this.startAfter.name,
value: object
})
return this
}
endAt(object) {
this.queryMap.queryElements.push({
operation: this.endAt.name,
value: object
})
return this
}
endBefore(object) {
this.queryMap.queryElements.push({
operation: this.endBefore.name,
value: object
})
return this
}
build() {
Object.freeze(this);
return this;
}
}