Skip to content

Commit 73bc9d5

Browse files
committed
Preparing new approach for ServerTimeStamp
1 parent ac478cf commit 73bc9d5

14 files changed

Lines changed: 530 additions & 56 deletions

File tree

Samples/Flutter/client_app/lib/src/data/database.g.dart

Lines changed: 124 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Samples/Flutter/client_app/lib/src/data/departments.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import 'package:netcoresync_moor/netcoresync_moor.dart';
77
class Departments extends Table {
88
TextColumn get id => text().clientDefault(() => Uuid().v4())();
99

10+
TextColumn get syncId =>
11+
text().withLength(max: 255).withDefault(Constant(""))();
12+
1013
TextColumn get name => text().withLength(max: 255).nullable()();
1114

1215
IntColumn get timeStamp => integer().withDefault(const Constant(0))();

Samples/Flutter/client_app/lib/src/data/employees.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import 'package:netcoresync_moor/netcoresync_moor.dart';
77
class Employees extends Table {
88
TextColumn get id => text().clientDefault(() => Uuid().v4())();
99

10+
TextColumn get syncId =>
11+
text().withLength(max: 255).withDefault(Constant(""))();
12+
1013
TextColumn get name => text().withLength(max: 255).nullable()();
1114

1215
DateTimeColumn get birthday =>

netcoresync_moor/lib/src/data_access.dart

Lines changed: 184 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,24 @@ class _NetCoreSyncKnowledgesCompanion
102102
final Value<String> id;
103103
final Value<bool> local;
104104
final Value<int> maxTimeStamp;
105+
final Value<String> syncId;
105106
const _NetCoreSyncKnowledgesCompanion({
106107
this.id = const Value.absent(),
107108
this.local = const Value.absent(),
108109
this.maxTimeStamp = const Value.absent(),
110+
this.syncId = const Value.absent(),
109111
});
110112

111113
_NetCoreSyncKnowledgesCompanion copyWith(
112-
{Value<String>? id, Value<bool>? local, Value<int>? maxTimeStamp}) {
114+
{Value<String>? id,
115+
Value<bool>? local,
116+
Value<int>? maxTimeStamp,
117+
Value<String>? syncId}) {
113118
return _NetCoreSyncKnowledgesCompanion(
114119
id: id ?? this.id,
115120
local: local ?? this.local,
116121
maxTimeStamp: maxTimeStamp ?? this.maxTimeStamp,
122+
syncId: syncId ?? this.syncId,
117123
);
118124
}
119125

@@ -129,15 +135,19 @@ class _NetCoreSyncKnowledgesCompanion
129135
if (maxTimeStamp.present) {
130136
map['max_time_stamp'] = Variable<int>(maxTimeStamp.value);
131137
}
138+
if (syncId.present) {
139+
map['sync_id'] = Variable<String>(syncId.value);
140+
}
132141
return map;
133142
}
134143

135144
@override
136145
String toString() {
137-
return (StringBuffer('_NetCoreSyncKnowledgesCompanion(')
146+
return (StringBuffer('NetCoreSyncKnowledgesCompanion(')
138147
..write('id: $id, ')
139148
..write('local: $local, ')
140-
..write('maxTimeStamp: $maxTimeStamp')
149+
..write('maxTimeStamp: $maxTimeStamp, ')
150+
..write('syncId: $syncId')
141151
..write(')'))
142152
.toString();
143153
}
@@ -168,8 +178,15 @@ class _NetCoreSyncKnowledgesTable extends NetCoreSyncKnowledges
168178
late final GeneratedColumn<int?> maxTimeStamp = GeneratedColumn<int?>(
169179
'max_time_stamp', aliasedName, false,
170180
typeName: 'INTEGER', requiredDuringInsert: true);
181+
final VerificationMeta _syncIdMeta = const VerificationMeta('syncId');
182+
@override
183+
late final GeneratedColumn<String?> syncId = GeneratedColumn<String?>(
184+
'sync_id', aliasedName, false,
185+
additionalChecks: GeneratedColumn.checkTextLength(maxTextLength: 255),
186+
typeName: 'TEXT',
187+
requiredDuringInsert: true);
171188
@override
172-
List<GeneratedColumn> get $columns => [id, local, maxTimeStamp];
189+
List<GeneratedColumn> get $columns => [id, local, maxTimeStamp, syncId];
173190
@override
174191
String get aliasedName => _alias ?? 'netcoresync_knowledges';
175192
@override
@@ -199,6 +216,12 @@ class _NetCoreSyncKnowledgesTable extends NetCoreSyncKnowledges
199216
} else if (isInserting) {
200217
context.missing(_maxTimeStampMeta);
201218
}
219+
if (data.containsKey('sync_id')) {
220+
context.handle(_syncIdMeta,
221+
syncId.isAcceptableOrUnknown(data['sync_id']!, _syncIdMeta));
222+
} else if (isInserting) {
223+
context.missing(_syncIdMeta);
224+
}
202225
return context;
203226
}
204227

@@ -214,6 +237,8 @@ class _NetCoreSyncKnowledgesTable extends NetCoreSyncKnowledges
214237
.mapFromDatabaseResponse(data['${effectivePrefix}local'])!,
215238
maxTimeStamp: const IntType()
216239
.mapFromDatabaseResponse(data['${effectivePrefix}max_time_stamp'])!,
240+
syncId: const StringType()
241+
.mapFromDatabaseResponse(data['${effectivePrefix}sync_id'])!,
217242
);
218243
}
219244

@@ -222,3 +247,158 @@ class _NetCoreSyncKnowledgesTable extends NetCoreSyncKnowledges
222247
return _NetCoreSyncKnowledgesTable(_db, alias);
223248
}
224249
}
250+
251+
// class _NetCoreSyncKnowledgesCompanion
252+
// extends UpdateCompanion<NetCoreSyncKnowledge> {
253+
// final Value<String> id;
254+
// final Value<bool> local;
255+
// final Value<int> maxTimeStamp;
256+
// final Value<String> synchronizationId;
257+
// const _NetCoreSyncKnowledgesCompanion({
258+
// this.id = const Value.absent(),
259+
// this.local = const Value.absent(),
260+
// this.maxTimeStamp = const Value.absent(),
261+
// this.synchronizationId = const Value.absent(),
262+
// });
263+
264+
// _NetCoreSyncKnowledgesCompanion copyWith(
265+
// {Value<String>? id,
266+
// Value<bool>? local,
267+
// Value<int>? maxTimeStamp,
268+
// Value<String>? synchronizationId}) {
269+
// return _NetCoreSyncKnowledgesCompanion(
270+
// id: id ?? this.id,
271+
// local: local ?? this.local,
272+
// maxTimeStamp: maxTimeStamp ?? this.maxTimeStamp,
273+
// synchronizationId: synchronizationId ?? this.synchronizationId,
274+
// );
275+
// }
276+
277+
// @override
278+
// Map<String, Expression> toColumns(bool nullToAbsent) {
279+
// final map = <String, Expression>{};
280+
// if (id.present) {
281+
// map['id'] = Variable<String>(id.value);
282+
// }
283+
// if (local.present) {
284+
// map['local'] = Variable<bool>(local.value);
285+
// }
286+
// if (maxTimeStamp.present) {
287+
// map['max_time_stamp'] = Variable<int>(maxTimeStamp.value);
288+
// }
289+
// if (synchronizationId.present) {
290+
// map['synchronization_id'] = Variable<String>(synchronizationId.value);
291+
// }
292+
// return map;
293+
// }
294+
295+
// @override
296+
// String toString() {
297+
// return (StringBuffer('NetCoreSyncKnowledgesCompanion(')
298+
// ..write('id: $id, ')
299+
// ..write('local: $local, ')
300+
// ..write('maxTimeStamp: $maxTimeStamp, ')
301+
// ..write('synchronizationId: $synchronizationId')
302+
// ..write(')'))
303+
// .toString();
304+
// }
305+
// }
306+
307+
// class _NetCoreSyncKnowledgesTable extends NetCoreSyncKnowledges
308+
// with TableInfo<_NetCoreSyncKnowledgesTable, NetCoreSyncKnowledge> {
309+
// final GeneratedDatabase _db;
310+
// final String? _alias;
311+
// _NetCoreSyncKnowledgesTable(this._db, [this._alias]);
312+
// final VerificationMeta _idMeta = const VerificationMeta('id');
313+
// @override
314+
// late final GeneratedColumn<String?> id = GeneratedColumn<String?>(
315+
// 'id', aliasedName, false,
316+
// additionalChecks: GeneratedColumn.checkTextLength(maxTextLength: 36),
317+
// typeName: 'TEXT',
318+
// requiredDuringInsert: true);
319+
// final VerificationMeta _localMeta = const VerificationMeta('local');
320+
// @override
321+
// late final GeneratedColumn<bool?> local = GeneratedColumn<bool?>(
322+
// 'local', aliasedName, false,
323+
// typeName: 'INTEGER',
324+
// requiredDuringInsert: true,
325+
// defaultConstraints: 'CHECK (local IN (0, 1))');
326+
// final VerificationMeta _maxTimeStampMeta =
327+
// const VerificationMeta('maxTimeStamp');
328+
// @override
329+
// late final GeneratedColumn<int?> maxTimeStamp = GeneratedColumn<int?>(
330+
// 'max_time_stamp', aliasedName, false,
331+
// typeName: 'INTEGER', requiredDuringInsert: true);
332+
// final VerificationMeta _synchronizationIdMeta =
333+
// const VerificationMeta('synchronizationId');
334+
// @override
335+
// late final GeneratedColumn<String?> synchronizationId =
336+
// GeneratedColumn<String?>('synchronization_id', aliasedName, false,
337+
// additionalChecks: GeneratedColumn.checkTextLength(maxTextLength: 255),
338+
// typeName: 'TEXT',
339+
// requiredDuringInsert: true);
340+
// @override
341+
// List<GeneratedColumn> get $columns =>
342+
// [id, local, maxTimeStamp, synchronizationId];
343+
// @override
344+
// String get aliasedName => _alias ?? 'netcoresync_knowledges';
345+
// @override
346+
// String get actualTableName => 'netcoresync_knowledges';
347+
// @override
348+
// VerificationContext validateIntegrity(
349+
// Insertable<NetCoreSyncKnowledge> instance,
350+
// {bool isInserting = false}) {
351+
// final context = VerificationContext();
352+
// final data = instance.toColumns(true);
353+
// if (data.containsKey('id')) {
354+
// context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta));
355+
// } else if (isInserting) {
356+
// context.missing(_idMeta);
357+
// }
358+
// if (data.containsKey('local')) {
359+
// context.handle(
360+
// _localMeta, local.isAcceptableOrUnknown(data['local']!, _localMeta));
361+
// } else if (isInserting) {
362+
// context.missing(_localMeta);
363+
// }
364+
// if (data.containsKey('max_time_stamp')) {
365+
// context.handle(
366+
// _maxTimeStampMeta,
367+
// maxTimeStamp.isAcceptableOrUnknown(
368+
// data['max_time_stamp']!, _maxTimeStampMeta));
369+
// } else if (isInserting) {
370+
// context.missing(_maxTimeStampMeta);
371+
// }
372+
// if (data.containsKey('synchronization_id')) {
373+
// context.handle(
374+
// _synchronizationIdMeta,
375+
// synchronizationId.isAcceptableOrUnknown(
376+
// data['synchronization_id']!, _synchronizationIdMeta));
377+
// } else if (isInserting) {
378+
// context.missing(_synchronizationIdMeta);
379+
// }
380+
// return context;
381+
// }
382+
383+
// @override
384+
// Set<GeneratedColumn> get $primaryKey => {id};
385+
// @override
386+
// NetCoreSyncKnowledge map(Map<String, dynamic> data, {String? tablePrefix}) {
387+
// final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
388+
// return NetCoreSyncKnowledge.fromDb(
389+
// id: const StringType()
390+
// .mapFromDatabaseResponse(data['${effectivePrefix}id'])!,
391+
// local: const BoolType()
392+
// .mapFromDatabaseResponse(data['${effectivePrefix}local'])!,
393+
// maxTimeStamp: const IntType()
394+
// .mapFromDatabaseResponse(data['${effectivePrefix}max_time_stamp'])!,
395+
// syncId: const StringType().mapFromDatabaseResponse(
396+
// data['${effectivePrefix}synchronization_id'])!,
397+
// );
398+
// }
399+
400+
// @override
401+
// _NetCoreSyncKnowledgesTable createAlias(String alias) {
402+
// return _NetCoreSyncKnowledgesTable(_db, alias);
403+
// }
404+
// }

netcoresync_moor/lib/src/netcoresync_annotations.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class NetCoreSyncTable {
22
final String mapToClassName;
33
final String idFieldName;
4+
final String syncIdFieldName;
45
final String timeStampFieldName;
56
final String deletedFieldName;
67
final String knowledgeIdFieldName;
@@ -9,6 +10,7 @@ class NetCoreSyncTable {
910
const NetCoreSyncTable({
1011
this.mapToClassName = "",
1112
this.idFieldName = "id",
13+
this.syncIdFieldName = "syncId",
1214
this.timeStampFieldName = "timeStamp",
1315
this.deletedFieldName = "deleted",
1416
this.knowledgeIdFieldName = "knowledgeId",
@@ -19,6 +21,7 @@ class NetCoreSyncTable {
1921
return NetCoreSyncTable(
2022
mapToClassName: json["mapToClassName"],
2123
idFieldName: json["idFieldName"],
24+
syncIdFieldName: json["syncIdFieldName"],
2225
timeStampFieldName: json["timeStampFieldName"],
2326
deletedFieldName: json["deletedFieldName"],
2427
knowledgeIdFieldName: json["knowledgeIdFieldName"],
@@ -30,6 +33,7 @@ class NetCoreSyncTable {
3033
return {
3134
"mapToClassName": mapToClassName,
3235
"idFieldName": idFieldName,
36+
"syncIdFieldName": syncIdFieldName,
3337
"timeStampFieldName": timeStampFieldName,
3438
"deletedFieldName": deletedFieldName,
3539
"knowledgeIdFieldName": knowledgeIdFieldName,

netcoresync_moor/lib/src/netcoresync_engine.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ class NetCoreSyncTableUser<T extends Table, D> {
2020
TableInfo<T, D> tableInfo;
2121
NetCoreSyncTable tableAnnotation;
2222
String idEscapedName;
23+
String syncIdEscapedName;
2324
String timeStampEscapedName;
2425
String deletedEscapedName;
2526
String knowledgeIdEscapedName;
2627
NetCoreSyncTableUser(
2728
this.tableInfo,
2829
this.tableAnnotation,
2930
this.idEscapedName,
31+
this.syncIdEscapedName,
3032
this.timeStampEscapedName,
3133
this.deletedEscapedName,
3234
this.knowledgeIdEscapedName,

netcoresync_moor/lib/src/netcoresync_knowledges.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class NetCoreSyncKnowledges extends Table {
66
TextColumn get id => text().withLength(max: 36)();
77
BoolColumn get local => boolean()();
88
IntColumn get maxTimeStamp => integer()();
9+
TextColumn get syncId => text().withLength(max: 255)();
910

1011
@override
1112
Set<Column> get primaryKey => {id};
@@ -18,13 +19,15 @@ class NetCoreSyncKnowledge implements Insertable<NetCoreSyncKnowledge> {
1819
String id = Uuid().v4();
1920
bool local = false;
2021
int maxTimeStamp = 0;
22+
String syncId = "";
2123

2224
NetCoreSyncKnowledge();
2325

2426
NetCoreSyncKnowledge.fromDb({
2527
required this.id,
2628
required this.local,
2729
required this.maxTimeStamp,
30+
required this.syncId,
2831
});
2932

3033
@override
@@ -33,6 +36,7 @@ class NetCoreSyncKnowledge implements Insertable<NetCoreSyncKnowledge> {
3336
map['id'] = Variable<String>(id);
3437
map['local'] = Variable<bool>(local);
3538
map['max_time_stamp'] = Variable<int>(maxTimeStamp);
39+
map['sync_id'] = Variable<String>(syncId);
3640
return map;
3741
}
3842

@@ -42,6 +46,7 @@ class NetCoreSyncKnowledge implements Insertable<NetCoreSyncKnowledge> {
4246
customObject.id = serializer.fromJson<String>(json['id']);
4347
customObject.local = serializer.fromJson<bool>(json['local']);
4448
customObject.maxTimeStamp = serializer.fromJson<int>(json['maxTimeStamp']);
49+
customObject.syncId = serializer.fromJson<String>(json['syncId']);
4550
return customObject;
4651
}
4752

@@ -51,6 +56,7 @@ class NetCoreSyncKnowledge implements Insertable<NetCoreSyncKnowledge> {
5156
'id': serializer.toJson<String>(id),
5257
'local': serializer.toJson<bool>(local),
5358
'maxTimeStamp': serializer.toJson<int>(maxTimeStamp),
59+
'syncId': serializer.toJson<String>(syncId),
5460
};
5561
}
5662
}

netcoresync_moor/lib/src/sync_handler.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:http/http.dart' as http;
66
import 'package:archive/archive.dart';
77
import 'netcoresync_client.dart';
88
import 'netcoresync_exceptions.dart';
9-
import 'netcoresync_knowledges.dart';
109
import 'data_access.dart';
1110

1211
class SyncHandler {
@@ -33,9 +32,6 @@ class SyncHandler {
3332
logs.addAll(ensureLogs);
3433
});
3534

36-
List<NetCoreSyncKnowledge> sourceKnowledges =
37-
await dataAccess.getKnowledges();
38-
3935
var httpClient = http.Client();
4036
try {
4137
Map<String, dynamic> payload = {

0 commit comments

Comments
 (0)