Skip to content

Fix OrderBy multiple columns #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -578,6 +589,40 @@ final Map<String, String> params = <String, String>{'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<ParseObject> query =
QueryBuilder<ParseObject>(ParseObject('Fruits'))
..whereRelatedTo('fruits', 'DietPlan', DietPlan.objectId);
```

## Other Features of this library
Main:
* Installation (View the example application)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/network/parse_live_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class LiveQuery {
}

final String _className = query.object.parseClassName;
final keysToReturn = query.limiters['keys']?.split(',');
final List<String> keysToReturn = query.limiters['keys']?.split(',');
query.limiters.clear(); //Remove limits in LiveQuery
final String _where = query._buildQuery().replaceAll('where=', '');

Expand Down Expand Up @@ -139,7 +139,7 @@ class LiveQuery {
'query': <String, dynamic>{
'className': _className,
'where': _whereMap,
if (keysToReturn != null && keysToReturn.length > 0)
if (keysToReturn != null && keysToReturn.isNotEmpty)
'fields': keysToReturn
}
};
Expand Down
14 changes: 11 additions & 3 deletions lib/src/network/parse_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@ class QueryBuilder<T extends ParseObject> {
/// [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.
///
/// [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.
Expand Down Expand Up @@ -271,7 +279,7 @@ class QueryBuilder<T extends ParseObject> {
}

Future<ParseResponse> distinct(String className) async {
String queryString = "distinct=$className";
final String queryString = 'distinct=$className';
return object.distinct(queryString);
}

Expand Down