diff --git a/README.md b/README.md index 7b94200b3..33bf94237 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,9 @@ It's possible to add other parameters to work with your instance of Parse Server clientKey: keyParseClientKey, // Required for some setups debug: true, // When enabled, prints logs to console liveQueryUrl: keyLiveQueryUrl, // Required if using LiveQuery - autoSendSessionId: true, // Some confurations require this to be true + autoSendSessionId: true, // Required for authentication and ACL securityContext: securityContext, // Again, required for some setups - coreStore: await CoreStoreSharedPrefsImp.getInstance()); // Will use SharedPreferences instead of Sembast as an internal DB + coreStore: await CoreStoreSharedPrefsImp.getInstance()); // Local data storage method. Will use SharedPreferences instead of Sembast as an internal DB ``` ## Objects @@ -133,6 +133,17 @@ and to retrieve it var dietPlan = DietPlan().fromPin('OBJECT ID OF OBJECT'); ``` +## Storage +We now have 2 types of storage, secure and unsecure. We currently rely on 2 third party options: + +- SharedPreferences +- Sembast +Sembast offers secured storage, whilst SharePreferences wraps NSUserDefaults (on iOS) and SharedPreferences (on Android). + +The storage method is defined in the parameter __coreStore__ in Parse().initialize + +Check sample code for options + ## Increment Counter values in objects Retrieve it, call @@ -578,6 +589,40 @@ final Map params = {'plan': 'paid'}; function.execute(parameters: params); ``` +## Relation + +The SDK supports Relation. + +To add relation to object: + +```dart +dietPlan.addRelation('fruits', [ParseObject("Fruits")..set("objectId", "XGadzYxnac")]); +``` + +To remove relation to object: + +```dart +dietPlan.removeRelation('fruits', [ParseObject("Fruits")..set("objectId", "XGadzYxnac")]); +``` + +To Retrive a relation instance for user, call: +```dart +final relation = dietPlan.getRelation('fruits'); +``` + +and then you can add a relation to the passed in object: +``` +relation.add(dietPlan); +final result = await user.save(); +``` + +To retrieve objects that are members of Relation field of a parent object: +```dart +QueryBuilder query = + QueryBuilder(ParseObject('Fruits')) + ..whereRelatedTo('fruits', 'DietPlan', DietPlan.objectId); +``` + ## Other Features of this library Main: * Installation (View the example application) diff --git a/lib/src/network/parse_live_query.dart b/lib/src/network/parse_live_query.dart index b870d1fdc..3ef3785d2 100644 --- a/lib/src/network/parse_live_query.dart +++ b/lib/src/network/parse_live_query.dart @@ -49,7 +49,7 @@ class LiveQuery { } final String _className = query.object.parseClassName; - final keysToReturn = query.limiters['keys']?.split(','); + final List keysToReturn = query.limiters['keys']?.split(','); query.limiters.clear(); //Remove limits in LiveQuery final String _where = query._buildQuery().replaceAll('where=', ''); @@ -139,7 +139,7 @@ class LiveQuery { 'query': { 'className': _className, 'where': _whereMap, - if (keysToReturn != null && keysToReturn.length > 0) + if (keysToReturn != null && keysToReturn.isNotEmpty) 'fields': keysToReturn } }; diff --git a/lib/src/network/parse_query.dart b/lib/src/network/parse_query.dart index 4c8b06266..86f3599e1 100644 --- a/lib/src/network/parse_query.dart +++ b/lib/src/network/parse_query.dart @@ -32,7 +32,11 @@ class QueryBuilder { /// [String] order will be the column of the table that the results are /// ordered by void orderByAscending(String order) { - limiters['order'] = order; + if (limiters.isEmpty) { + limiters['order'] = order; + } else { + limiters['order'] = limiters['order'] + ',' + order; + } } /// Sorts the results descending order. @@ -40,7 +44,11 @@ class QueryBuilder { /// [String] order will be the column of the table that the results are /// ordered by void orderByDescending(String order) { - limiters['order'] = '-$order'; + if (limiters.isEmpty) { + limiters['order'] = '-$order'; + } else { + limiters['order'] = limiters['order'] + ',' + '-$order'; + } } /// Define which keys in an object to return. @@ -271,7 +279,7 @@ class QueryBuilder { } Future distinct(String className) async { - String queryString = "distinct=$className"; + final String queryString = 'distinct=$className'; return object.distinct(queryString); }