Skip to content

Commit a8c315e

Browse files
committed
Version 1.0.6 - BREKAING FIX - changed query names
1 parent 9df13e1 commit a8c315e

19 files changed

+8310
-392
lines changed

.idea/libraries/Dart_Packages.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Flutter_Plugins.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+297-320
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.0.6
2+
3+
BREAK FIX - Fixed ParseUser return type so now returns ParseResponse
4+
BREAK FIX - Changed query names to make more human readable
5+
Fixed pinning and unpinning
6+
17
## 1.0.5
28

39
Corrected save. Now formatted items correctly for saving on server

example/lib/main.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ class _MyAppState extends State<MyApp> {
122122

123123
void query() async {
124124
var queryBuilder = QueryBuilder<DietPlan>(DietPlan())
125-
..greaterThan(DietPlan.keyFat, 20)
126-
..descending(DietPlan.keyFat);
125+
..whereContains(DietPlan.keyName, "eto");
127126

128127
var apiResponse = await queryBuilder.query();
129128

@@ -170,7 +169,7 @@ class _MyAppState extends State<MyApp> {
170169
if (response.success) user = response.result;
171170

172171
var queryBuilder = QueryBuilder<ParseUser>(ParseUser.forQuery())
173-
..startsWith(ParseUser.keyUsername, 'phillw');;
172+
..whereStartsWith(ParseUser.keyUsername, 'phillw');;
174173

175174
var apiResponse = await queryBuilder.query();
176175
if (apiResponse.success) user = response.result;

lib/parse.dart

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'dart:async';
44
import 'dart:convert';
55
import 'dart:io';
66

7+
import 'dart:typed_data';
8+
import 'package:path/path.dart' as path;
79
import 'package:http/http.dart';
810
import 'package:meta/meta.dart';
911
import 'package:shared_preferences/shared_preferences.dart';
@@ -37,6 +39,8 @@ part 'src/objects/parse_response.dart';
3739

3840
part 'src/objects/parse_user.dart';
3941

42+
part 'src/objects/parse_file.dart';
43+
4044
part 'src/utils/parse_decoder.dart';
4145

4246
part 'src/utils/parse_encoder.dart';
@@ -45,6 +49,8 @@ part 'src/utils/parse_logger.dart';
4549

4650
part 'src/utils/parse_utils.dart';
4751

52+
part 'src/utils/parse_file_extensions.dart';
53+
4854
class Parse {
4955
ParseCoreData data;
5056
final ParseHTTPClient client = new ParseHTTPClient();

lib/src/base/parse_constants.dart

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const String keyVarAcl = 'ACL';
2525
// Classes
2626
const String keyClassMain = 'ParseMain';
2727
const String keyClassUser = '_User';
28+
const String keyGeoPoint = 'GeoPoint';
29+
const String keyFile = 'File';
2830

2931
// Headers
3032
const String keyHeaderSessionToken = 'X-Parse-Session-Token';

lib/src/enums/parse_enum_api_rq.dart

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,13 @@ enum ParseApiRQ {
1616
requestPasswordReset,
1717
destroy,
1818
all,
19-
execute
19+
execute,
20+
upload,
21+
add,
22+
addAll,
23+
addUnique,
24+
remove,
25+
removeAll,
26+
increment,
27+
decrement
2028
}

lib/src/network/parse_query.dart

+54-39
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ part of flutter_parse_sdk;
44
class QueryBuilder<T extends ParseObject> {
55

66
static const String _NO_OPERATOR_NEEDED = "NO_OP";
7+
static const String _SINGLE_QUERY = "SINGLE_QUERY";
78

89
T object;
910
var queries = List<MapEntry>();
@@ -13,137 +14,151 @@ class QueryBuilder<T extends ParseObject> {
1314
QueryBuilder(this.object) : super();
1415

1516
/// Adds a limit to amount of results return from Parse
16-
void limit(int limit){
17+
void setLimit(int limit){
1718
limiters["limit"] = limit;
1819
}
1920

2021
/// Useful for pagination, skips [int] amount of results
21-
void skip(int skip){
22+
void setAmountToSkip(int skip){
2223
limiters["skip"] = skip;
2324
}
2425

2526
/// Creates a query based on where
26-
void where(String where){
27+
void whereEquals(String where){
2728
limiters['where'] = where;
2829
}
2930

3031
/// Orders the results ascedingly.
3132
///
3233
/// [String] order will be the column of the table that the results are
3334
/// ordered by
34-
void ascending(String order){
35+
void orderByAscending(String order){
3536
limiters["order"] = order;
3637
}
3738

3839
/// Orders the results descendingly.
3940
///
4041
/// [String] order will be the column of the table that the results are
4142
/// ordered by
42-
void descending(String order){
43+
void orderByDescending(String order){
4344
limiters["order"] = "-$order";
4445
}
4546

4647
/// Define which keys in an object to return.
4748
///
4849
/// [String] keys will only return the columns of a result you want the data for,
4950
/// this is useful for large objects
50-
void keys(String keys){
51-
limiters["keys"] = keys;
51+
void keysToReturn(List<String> keys){
52+
limiters["keys"] = keys.toString();
5253
}
5354

5455
/// Includes other ParseObjects stored as a Pointer
55-
void include(String include){
56-
limiters["include"] = include;
56+
void includeObject(String objectType){
57+
limiters["include"] = objectType;
5758
}
5859

5960
/// Returns an object where the [String] column starts with [value]
60-
void startsWith(String column, dynamic value) {
61-
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, "^$value"), "\$regex"));
61+
void whereStartsWith(String column, String query, {bool caseSensitive: false}) {
62+
if (caseSensitive) {
63+
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"^$query\"}'));
64+
} else {
65+
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"^$query\", \"\$options\": \"i\"}'));
66+
}
6267
}
6368

6469
/// Returns an object where the [String] column ends with [value]
65-
void endsWith(String column, dynamic value) {
66-
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, "$value^"), "\$regex"));
70+
void whereEndsWith(String column, String query, {bool caseSensitive: false}) {
71+
if (caseSensitive) {
72+
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"$query^\"}'));
73+
} else {
74+
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"$query^\", \"\$options\": \"i\"}'));
75+
}
6776
}
6877

6978
/// Returns an object where the [String] column equals [value]
70-
void equals(String column, dynamic value) {
79+
void whereEqualTo(String column, dynamic value) {
7180
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), _NO_OPERATOR_NEEDED));
7281
}
7382

7483
/// Returns an object where the [String] column contains a value less than
7584
/// value
76-
void lessThan(String column, dynamic value) {
85+
void whereLessThan(String column, dynamic value) {
7786
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$lt"));
7887
}
7988

8089
/// Returns an object where the [String] column contains a value less or equal
8190
/// to than value
82-
void lessThanOrEqualTo(String column, dynamic value) {
91+
void whereLessThanOrEqualTo(String column, dynamic value) {
8392
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$lte"));
8493
}
8594

8695
/// Returns an object where the [String] column contains a value greater
8796
/// than value
88-
void greaterThan(String column, dynamic value) {
97+
void whereGreaterThan(String column, dynamic value) {
8998
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$gt"));
9099
}
91100

92101
/// Returns an object where the [String] column contains a value greater
93102
/// than equal to value
94-
void greaterThanOrEqualsTo(String column, dynamic value) {
103+
void whereGreaterThanOrEqualsTo(String column, dynamic value) {
95104
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$gte"));
96105
}
97106

98107
/// Returns an object where the [String] column is not equal to value
99-
void notEqualTo(String column, dynamic value) {
108+
void whereNotEqualTo(String column, dynamic value) {
100109
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$ne"));
101110
}
102111

103-
/// Returns an object where the [String] column contains value
104-
void contains(String column, dynamic value) {
105-
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$term"));
106-
}
107-
108112
/// Returns an object where the [String] column is containedIn
109-
void containedIn(String column, dynamic value) {
113+
void whereContainedIn(String column, List value) {
110114
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$in"));
111115
}
112116

113117
/// Returns an object where the [String] column is notContainedIn
114-
void notContainedIn(String column, dynamic value) {
118+
void whereNotContainedIn(String column, List value) {
115119
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$nin"));
116120
}
117121

118-
/// Returns an object where the [String] column is exists
119-
void exists(String column, dynamic value) {
122+
/// Returns an object where the [String] column for the object has data correctley entered/saved
123+
void whereValueExists(String column, bool value) {
120124
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$exists"));
121125
}
122126

123127
/// Returns an object where the [String] column contains select
124-
void select(String column, dynamic value) {
128+
void selectKeys(String column, dynamic value) {
125129
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$select"));
126130
}
127131

128132
/// Returns an object where the [String] column doesn't select
129-
void dontSelect(String column, dynamic value) {
133+
void dontSelectKeys(String column, dynamic value) {
130134
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$dontSelect"));
131135
}
132136

133137
/// Returns an object where the [String] column contains all
134-
void all(String column, dynamic value) {
135-
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$all"));
138+
void whereArrayContainsAll(String column, List value) {
139+
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value.toString()), "\$all"));
136140
}
137141

138142
/// Returns an object where the [String] column has a regEx performed on,
139-
/// this can include ^StringsWith, or ^EndsWith
140-
void regEx(String column, dynamic value) {
143+
/// this can include ^StringsWith, or ^EndsWith. This can be manipulated to the users desire
144+
void regEx(String column, String value) {
141145
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$regex"));
142146
}
143147

144-
/// Returns an object where the [String] column contains the text
145-
void text(String column, dynamic value) {
146-
queries.add(_buildQueryWithColumnValueAndOperator(MapEntry(column, value), "\$text"));
148+
/// Performs a search to see if [String] contains other string
149+
void whereContains(String column, String value, {bool caseSensitive: false}) {
150+
if (caseSensitive) {
151+
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"$query\"}'));
152+
} else {
153+
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$regex\": \"$query\", \"\$options\": \"i\"}'));
154+
}
155+
}
156+
157+
/// 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.
158+
/// This search can also order by the score of the search
159+
void textContainsWholeWord(String column, String query, {bool caseSensitive: false, bool orderByScore: true}){
160+
queries.add(MapEntry(_SINGLE_QUERY, '\"$column\":{\"\$text\":{\"\$search\":{\"\$term\": \"$query\", \"\$caseSensitive\": $caseSensitive }}}'));
161+
if (orderByScore) orderByDescending('score');
147162
}
148163

149164
/// Finishes the query and calls the server
@@ -208,12 +223,12 @@ class QueryBuilder<T extends ParseObject> {
208223
for (var query in queries){
209224

210225
// Add queries that don't need sanitising
211-
if (query.key == _NO_OPERATOR_NEEDED) {
226+
if (query.key == _NO_OPERATOR_NEEDED || query.key == _SINGLE_QUERY) {
212227
sanitisedQueries.add(MapEntry(_NO_OPERATOR_NEEDED, query.value));
213228
}
214229

215230
// Check if query with same column name has been sanitised
216-
if (!keysAlreadyCompacted.contains(query.key) && query.key != _NO_OPERATOR_NEEDED) {
231+
if (!keysAlreadyCompacted.contains(query.key) && query.key != _NO_OPERATOR_NEEDED && query.key != _SINGLE_QUERY) {
217232

218233
// If not, check that it now has
219234
keysAlreadyCompacted.add(query.key);

lib/src/objects/parse_file.dart

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
part of flutter_parse_sdk;
2+
3+
class ParseFile extends ParseObject {
4+
5+
File _file;
6+
String _fileName;
7+
String _fileUrl;
8+
9+
@override
10+
String _path;
11+
12+
String get name => _fileName;
13+
14+
String get url => _fileUrl;
15+
16+
bool get saved => url != null;
17+
18+
@override
19+
toJson({bool forApiRQ: false}) => <String, String>{'__type': keyFile, 'name': _fileName, 'url': _fileUrl};
20+
21+
@override
22+
String toString() => json.encode(toString());
23+
24+
/// Creates a new file
25+
///
26+
/// {https://docs.parseplatform.org/rest/guide/#files/}
27+
ParseFile(this._file, {bool debug, ParseHTTPClient client}) : super (keyFile){
28+
client == null ? _client = ParseHTTPClient() : _client = client;
29+
_debug = isDebugEnabled(objectLevelDebug: debug);
30+
31+
this._fileName = path.basename(_file.path);
32+
this._path = 'files/$_fileName';
33+
}
34+
35+
/// Uploads a file to Parse Server
36+
upload() async {
37+
if (saved) {
38+
return this;
39+
}
40+
41+
final ext = path.extension(_file.path).replaceAll('.', '');
42+
final headers = <String, String>{
43+
HttpHeaders.contentTypeHeader: getContentType(ext)
44+
};
45+
46+
var uri = _client.data.serverUrl + "$_path";
47+
final body = await _file.readAsBytes();
48+
final response = await _client.post(uri, headers: headers, body: body);
49+
return super.handleResponse<ParseFile>(response, ParseApiRQ.upload);
50+
}
51+
}

0 commit comments

Comments
 (0)