Skip to content
New issue

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

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

Already on GitHub? # to your account

Develop #41

Merged
merged 3 commits into from
Jan 20, 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
241 changes: 114 additions & 127 deletions .idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.0.8
Fixed some queries

## 1.0.7

Some items now return a response rather than a ParseObject
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Want to get involved? Join our Slack channel and help out! (http://flutter-parse
To install, either add to your pubspec.yaml
```
dependencies:
parse_server_sdk: ^1.0.7
parse_server_sdk: ^1.0.8
```
or clone this repository and add to your project. As this is an early development with multiple contributors, it is probably best to download/clone and keep updating as an when a new feature is added.

Expand Down
16 changes: 8 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class _MyAppState extends State<MyApp> {
}

runTestQueries() {
createItem();
getAllItems();
getAllItemsByName();
getSingleItem();
//createItem();
//getAllItems();
//getAllItemsByName();
//getSingleItem();
query();
function();
initUser();
//function();
//initUser();
}

void createItem() async {
Expand Down Expand Up @@ -112,7 +112,6 @@ class _MyAppState extends State<MyApp> {

// shows example of retrieving a pin
var newDietPlanFromPin = DietPlan().fromPin('R5EonpUDWy');

if (newDietPlanFromPin != null) print('Retreiving from pin worked!');

} else {
Expand All @@ -122,7 +121,8 @@ class _MyAppState extends State<MyApp> {

void query() async {
var queryBuilder = QueryBuilder<DietPlan>(DietPlan())
..whereContains(DietPlan.keyName, "eto");
..whereContains(DietPlan.keyName, "iet")
..keysToReturn([DietPlan.keyName]);

var apiResponse = await queryBuilder.query();

Expand Down
27 changes: 20 additions & 7 deletions lib/src/network/parse_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class QueryBuilder<T extends ParseObject> {
/// [String] keys will only return the columns of a result you want the data for,
/// this is useful for large objects
void keysToReturn(List<String> keys){
limiters["keys"] = keys.toString();
limiters["keys"] = concatArray(keys);
}

/// Includes other ParseObjects stored as a Pointer
void includeObject(String objectType){
limiters["include"] = objectType;
void includeObject(List<String> objectTypes){
limiters["include"] = concatArray(objectTypes);
}

/// Returns an object where the [String] column starts with [value]
Expand Down Expand Up @@ -148,15 +148,15 @@ class QueryBuilder<T extends ParseObject> {
/// Performs a search to see if [String] contains other string
void whereContains(String column, String value, {bool caseSensitive: false}) {
if (caseSensitive) {
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"$query\"}'));
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"$value\"}'));
} else {
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"$query\", \"\$options\": \"i\"}'));
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"$value\", \"\$options\": \"i\"}'));
}
}

/// Powerful search for containing whole words. This search is much quicker than regex and can search for whole words including wether they are case sensitive or not.
/// This search can also order by the score of the search
void textContainsWholeWord(String column, String query, {bool caseSensitive: false, bool orderByScore: true}){
void whereContainsWholeWord(String column, String query, {bool caseSensitive: false, bool orderByScore: true}){
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$text\":{\"\$search\":{\"\$term\": \"$query\", \"\$caseSensitive\": $caseSensitive }}}'));
if (orderByScore) orderByDescending('score');
}
Expand All @@ -177,7 +177,6 @@ class QueryBuilder<T extends ParseObject> {

/// Runs through all queries and adds them to a query string
String buildQueries(List<MapEntry> queries) {

String queryBuilder = "";

for (var item in queries) {
Expand All @@ -191,6 +190,20 @@ class QueryBuilder<T extends ParseObject> {
return queryBuilder;
}

String concatArray(List<String> queries) {
String queryBuilder = "";

for (var item in queries) {
if (item == queries.first) {
queryBuilder += item;
} else {
queryBuilder += ",$item";
}
}

return queryBuilder;
}

/// Creates a query param using the column, the value and the queryOperator
/// that the column and value are being queried against
MapEntry _buildQueryWithColumnValueAndOperator(MapEntry columnAndValue, String queryOperator) {
Expand Down
12 changes: 10 additions & 2 deletions lib/src/objects/parse_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,16 @@ class ParseObject extends ParseBase implements ParseCloneable {
/// Can be used to create custom queries
Future<ParseResponse> query(String query) async {
try {
var uri = "${ParseCoreData().serverUrl}$_path?$query";
var result = await _client.get(uri);

Uri tempUri = Uri.parse(ParseCoreData().serverUrl);

Uri url = Uri(
scheme: tempUri.scheme,
host: tempUri.host,
path: "${tempUri.path}$_path",
query: query);

var result = await _client.get(url);
return handleResponse(result, ParseApiRQ.query);
} on Exception catch (e) {
return handleException(e, ParseApiRQ.query);
Expand Down
3 changes: 1 addition & 2 deletions lib/src/objects/parse_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ class ParseUser extends ParseObject implements ParseCloneable {
host: tempUri.host,
path: "${tempUri.path}$keyEndPointUserName");

final response = await _client
.get(uri, headers: {keyHeaderSessionToken: _client.data.sessionId});
final response = await _client.get(uri, headers: {keyHeaderSessionToken: _client.data.sessionId});
return _handleResponse(response, ParseApiRQ.currentUser);
} on Exception catch (e) {
return _handleException(e, ParseApiRQ.currentUser);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: parse_server_sdk
description: Flutter plugin for Parse Server, (https://parseplatform.org), (https://back4app.com)
version: 1.0.7
version: 1.0.8
homepage: https://github.com/phillwiggins/flutter_parse_sdk
author: PhillWiggins <phill.wiggins@gmail.com>

Expand Down