Skip to content

Commit 3f51b3e

Browse files
committed
Refactor ClientOfflineMixin and add offline filters
Split out offline DB related operations into separate classes.
1 parent b0ea424 commit 3f51b3e

File tree

9 files changed

+570
-388
lines changed

9 files changed

+570
-388
lines changed

lib/appwrite.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
library appwrite;
22

33
import 'dart:async';
4+
import 'dart:convert';
45
import 'dart:math';
56
import 'dart:typed_data';
7+
8+
import 'models.dart' as models;
69
import 'src/enums.dart';
7-
import 'src/service.dart';
810
import 'src/input_file.dart';
9-
import 'models.dart' as models;
11+
import 'src/service.dart';
1012
import 'src/upload_progress.dart';
1113

1214
export 'src/client.dart';

lib/query.dart

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
part of appwrite;
22

3+
// regex to extract method name and params
4+
final _methodAndParamsRegEx = RegExp(r'(\w+)\((.*)\)');
5+
36
class Query {
4-
Query._();
5-
7+
Query._(this.method, this.params);
8+
69
static equal(String attribute, dynamic value) =>
710
_addQuery(attribute, 'equal', value);
811

@@ -43,4 +46,29 @@ class Query {
4346

4447
static String parseValues(dynamic value) =>
4548
(value is String) ? '"$value"' : '$value';
49+
50+
String method;
51+
List<dynamic> params;
52+
53+
factory Query.parse(String query) {
54+
if (!query.contains('(') || !query.contains(')')) {
55+
throw Exception('Invalid query');
56+
}
57+
58+
final matches = _methodAndParamsRegEx.firstMatch(query);
59+
60+
if (matches == null || matches.groupCount < 2) {
61+
throw Exception('Invalid query');
62+
}
63+
64+
final method = matches.group(1)!;
65+
66+
try {
67+
final params = jsonDecode('[' + matches.group(2)! + ']') as List<dynamic>;
68+
69+
return Query._(method, params);
70+
} catch (e) {
71+
throw Exception('Invalid query');
72+
}
73+
}
4674
}

0 commit comments

Comments
 (0)