diff --git a/CHANGELOG.md b/CHANGELOG.md index e507ec05..14509c49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Add common Array methods to List and Results * Accept constructor in create() and objects() methods * Support relative paths when opening realms +* Support for indexed bool, string, date, and int properties ### Bugfixes * Fix for crash on Android when initializing the Realm module diff --git a/scripts/download-core.sh b/scripts/download-core.sh index 5d9587f5..9f520f6b 100755 --- a/scripts/download-core.sh +++ b/scripts/download-core.sh @@ -3,7 +3,7 @@ set -e 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. cd "$(dirname "$0")/.." diff --git a/src/js_schema.cpp b/src/js_schema.cpp index 3bd4dfe5..1bbc83da 100644 --- a/src/js_schema.cpp +++ b/src/js_schema.cpp @@ -47,6 +47,7 @@ JSObjectRef RJSSchemaCreate(JSContextRef ctx, Schema &schema) { static inline Property RJSParseProperty(JSContextRef ctx, JSValueRef propertyAttributes, std::string propertyName, ObjectDefaults &objectDefaults) { static JSStringRef defaultString = JSStringCreateWithUTF8CString("default"); + static JSStringRef indexedString = JSStringCreateWithUTF8CString("indexed"); static JSStringRef typeString = JSStringCreateWithUTF8CString("type"); static JSStringRef objectTypeString = JSStringCreateWithUTF8CString("objectType"); static JSStringRef optionalString = JSStringCreateWithUTF8CString("optional"); @@ -123,6 +124,11 @@ static inline Property RJSParseProperty(JSContextRef ctx, JSValueRef propertyAtt JSValueProtect(ctx, defaultValue); objectDefaults.emplace(prop.name, defaultValue); } + + JSValueRef indexedValue = RJSValidatedPropertyValue(ctx, propertyObject, indexedString); + if (!JSValueIsUndefined(ctx, indexedValue)) { + prop.is_indexed = JSValueToBoolean(ctx, indexedValue); + } } return prop; diff --git a/tests/js/realm-tests.js b/tests/js/realm-tests.js index 99da3b86..00e980f6 100644 --- a/tests/js/realm-tests.js +++ b/tests/js/realm-tests.js @@ -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() { var realm = new Realm({schema: [schemas.DefaultValues, schemas.TestObject]});