support for indexed properties
This commit is contained in:
parent
b02f64e727
commit
b2e4d93732
|
@ -8,6 +8,7 @@
|
||||||
* Add common Array methods to List and Results
|
* Add common Array methods to List and Results
|
||||||
* Accept constructor in create() and objects() methods
|
* Accept constructor in create() and objects() methods
|
||||||
* Support relative paths when opening realms
|
* Support relative paths when opening realms
|
||||||
|
* Support for indexed bool, string, date, and int properties
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
* Fix for crash on Android when initializing the Realm module
|
* Fix for crash on Android when initializing the Realm module
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
set -e
|
set -e
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
: ${REALM_CORE_VERSION:=0.96.2} # set to "current" to always use the current build
|
: ${REALM_CORE_VERSION:=0.97.0} # set to "current" to always use the current build
|
||||||
|
|
||||||
# Start current working directory at the root of the project.
|
# Start current working directory at the root of the project.
|
||||||
cd "$(dirname "$0")/.."
|
cd "$(dirname "$0")/.."
|
||||||
|
|
|
@ -47,6 +47,7 @@ JSObjectRef RJSSchemaCreate(JSContextRef ctx, Schema &schema) {
|
||||||
|
|
||||||
static inline Property RJSParseProperty(JSContextRef ctx, JSValueRef propertyAttributes, std::string propertyName, ObjectDefaults &objectDefaults) {
|
static inline Property RJSParseProperty(JSContextRef ctx, JSValueRef propertyAttributes, std::string propertyName, ObjectDefaults &objectDefaults) {
|
||||||
static JSStringRef defaultString = JSStringCreateWithUTF8CString("default");
|
static JSStringRef defaultString = JSStringCreateWithUTF8CString("default");
|
||||||
|
static JSStringRef indexedString = JSStringCreateWithUTF8CString("indexed");
|
||||||
static JSStringRef typeString = JSStringCreateWithUTF8CString("type");
|
static JSStringRef typeString = JSStringCreateWithUTF8CString("type");
|
||||||
static JSStringRef objectTypeString = JSStringCreateWithUTF8CString("objectType");
|
static JSStringRef objectTypeString = JSStringCreateWithUTF8CString("objectType");
|
||||||
static JSStringRef optionalString = JSStringCreateWithUTF8CString("optional");
|
static JSStringRef optionalString = JSStringCreateWithUTF8CString("optional");
|
||||||
|
@ -123,6 +124,11 @@ static inline Property RJSParseProperty(JSContextRef ctx, JSValueRef propertyAtt
|
||||||
JSValueProtect(ctx, defaultValue);
|
JSValueProtect(ctx, defaultValue);
|
||||||
objectDefaults.emplace(prop.name, defaultValue);
|
objectDefaults.emplace(prop.name, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSValueRef indexedValue = RJSValidatedPropertyValue(ctx, propertyObject, indexedString);
|
||||||
|
if (!JSValueIsUndefined(ctx, indexedValue)) {
|
||||||
|
prop.is_indexed = JSValueToBoolean(ctx, indexedValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return prop;
|
return prop;
|
||||||
|
|
|
@ -258,6 +258,52 @@ module.exports = BaseTest.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testRealmWithIndexedProperties: function() {
|
||||||
|
var IndexedTypes = {
|
||||||
|
name: 'IndexedTypesObject',
|
||||||
|
properties: {
|
||||||
|
boolCol: {type: 'bool', indexed: true},
|
||||||
|
intCol: {type: 'int', indexed: true},
|
||||||
|
stringCol: {type: 'string', indexed: true},
|
||||||
|
dateCol: {type: 'date', indexed: true},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var realm = new Realm({schema: [IndexedTypes]});
|
||||||
|
realm.write(function() {
|
||||||
|
realm.create('IndexedTypesObject', {boolCol: true, intCol: 1, stringCol: '1', dateCol: new Date(1)});
|
||||||
|
});
|
||||||
|
|
||||||
|
var NotIndexed = {
|
||||||
|
name: 'NotIndexedObject',
|
||||||
|
properties: {
|
||||||
|
floatCol: {type: 'float', indexed: false}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
new Realm({schema: [NotIndexed], path: '1'});
|
||||||
|
|
||||||
|
TestCase.assertThrows(function() {
|
||||||
|
IndexedTypes.properties = { floatCol: {type: 'float', indexed: true} }
|
||||||
|
new Realm({schema: [IndexedTypes], path: '2'});
|
||||||
|
});
|
||||||
|
|
||||||
|
TestCase.assertThrows(function() {
|
||||||
|
IndexedTypes.properties = { doubleCol: {type: 'double', indexed: true} }
|
||||||
|
new Realm({schema: [IndexedTypes], path: '3'});
|
||||||
|
});
|
||||||
|
|
||||||
|
TestCase.assertThrows(function() {
|
||||||
|
IndexedTypes.properties = { dataCol: {type: 'data', indexed: true} }
|
||||||
|
new Realm({schema: [IndexedTypes], path: '4'});
|
||||||
|
});
|
||||||
|
|
||||||
|
// primary key
|
||||||
|
IndexedTypes.primaryKey = 'boolCol';
|
||||||
|
IndexedTypes.properties = { boolCol: {type: 'bool', indexed: true} }
|
||||||
|
new Realm({schema: [IndexedTypes], path: '5'});
|
||||||
|
},
|
||||||
|
|
||||||
testRealmCreateWithDefaults: function() {
|
testRealmCreateWithDefaults: function() {
|
||||||
var realm = new Realm({schema: [schemas.DefaultValues, schemas.TestObject]});
|
var realm = new Realm({schema: [schemas.DefaultValues, schemas.TestObject]});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue