Commit acb08131 authored by Administrator's avatar Administrator
Browse files

lapTaggings, activityTaggings sqfentity models

parent 33c7586e
......@@ -338,6 +338,45 @@ const tableTag = SqfEntityTable(
],
);
const tableLapTagging = SqfEntityTable(
tableName: 'lapTaggings',
primaryKeyName: 'id',
primaryKeyType: PrimaryKeyType.integer_auto_incremental,
useSoftDeleting: false,
modelName: 'DbLapTagging',
fields: [
SqfEntityField('system', DbType.bool),
SqfEntityFieldRelationship(
parentTable: tableTag,
deleteRule: DeleteRule.CASCADE,
defaultValue: 0),
SqfEntityFieldRelationship(
parentTable: tableLap,
deleteRule: DeleteRule.CASCADE,
defaultValue: 0),
],
);
const tableActivityTagging = SqfEntityTable(
tableName: 'activityTaggings',
primaryKeyName: 'id',
primaryKeyType: PrimaryKeyType.integer_auto_incremental,
useSoftDeleting: false,
modelName: 'DbActivityTagging',
fields: [
SqfEntityField('system', DbType.bool),
SqfEntityFieldRelationship(
parentTable: tableTag,
deleteRule: DeleteRule.CASCADE,
defaultValue: 0),
SqfEntityFieldRelationship(
parentTable: tableActivity,
deleteRule: DeleteRule.CASCADE,
defaultValue: 0),
],
);
@SqfEntityBuilder(encrateia)
const encrateia = SqfEntityModel(
modelName: 'DbEncrateia', // optional
......@@ -354,6 +393,8 @@ const encrateia = SqfEntityModel(
tablePowerZone,
tableTag,
tableTagGroup,
tableLapTagging,
tableActivityTagging,
],
sequences: [],
bundledDatabasePath: null,
......
......@@ -450,6 +450,59 @@ class TableDbTagGroup extends SqfEntityTableBase {
return _instance = _instance ?? TableDbTagGroup();
}
}
// DbLapTagging TABLE
class TableDbLapTagging extends SqfEntityTableBase {
TableDbLapTagging() {
// declare properties of EntityTable
tableName = 'lapTaggings';
primaryKeyName = 'id';
primaryKeyType = PrimaryKeyType.integer_auto_incremental;
useSoftDeleting = false;
// when useSoftDeleting is true, creates a field named 'isDeleted' on the table, and set to '1' this field when item deleted (does not hard delete)
// declare fields
fields = [
SqfEntityFieldBase('system', DbType.bool),
SqfEntityFieldRelationshipBase(TableDbTag.getInstance, DeleteRule.CASCADE,
defaultValue: 0, fieldName: 'tagsId'),
SqfEntityFieldRelationshipBase(TableDbLap.getInstance, DeleteRule.CASCADE,
defaultValue: 0, fieldName: 'lapsId'),
];
super.init();
}
static SqfEntityTableBase _instance;
static SqfEntityTableBase get getInstance {
return _instance = _instance ?? TableDbLapTagging();
}
}
// DbActivityTagging TABLE
class TableDbActivityTagging extends SqfEntityTableBase {
TableDbActivityTagging() {
// declare properties of EntityTable
tableName = 'activityTaggings';
primaryKeyName = 'id';
primaryKeyType = PrimaryKeyType.integer_auto_incremental;
useSoftDeleting = false;
// when useSoftDeleting is true, creates a field named 'isDeleted' on the table, and set to '1' this field when item deleted (does not hard delete)
// declare fields
fields = [
SqfEntityFieldBase('system', DbType.bool),
SqfEntityFieldRelationshipBase(TableDbTag.getInstance, DeleteRule.CASCADE,
defaultValue: 0, fieldName: 'tagsId'),
SqfEntityFieldRelationshipBase(
TableDbActivity.getInstance, DeleteRule.CASCADE,
defaultValue: 0, fieldName: 'activitiesId'),
];
super.init();
}
static SqfEntityTableBase _instance;
static SqfEntityTableBase get getInstance {
return _instance = _instance ?? TableDbActivityTagging();
}
}
// END TABLES
// BEGIN SEQUENCES
......@@ -471,6 +524,8 @@ class DbEncrateia extends SqfEntityModelProvider {
TableDbPowerZone.getInstance,
TableDbTag.getInstance,
TableDbTagGroup.getInstance,
TableDbLapTagging.getInstance,
TableDbActivityTagging.getInstance,
];
bundledDatabasePath = encrateia
......@@ -2294,6 +2349,19 @@ class DbActivity {
.equals(id)
.and;
}
/// to load children of items to this field, use preload parameter ex: toList(preload:true) or toSingle(preload:true)
List<DbActivityTagging> plDbActivityTaggings;
/// get DbActivityTagging(s) filtered by activitiesId=id
DbActivityTaggingFilterBuilder getDbActivityTaggings(
{List<String> columnsToSelect, bool getIsDeleted}) {
return DbActivityTagging()
.select(columnsToSelect: columnsToSelect, getIsDeleted: getIsDeleted)
.activitiesId
.equals(id)
.and;
}
// END COLLECTIONS & VIRTUALS (DbActivity)
static const bool _softDeleteActivated = false;
......@@ -2885,6 +2953,9 @@ class DbActivity {
if (!forQuery) {
map['DbLaps'] = await getDbLaps().toMapList();
}
if (!forQuery) {
map['DbActivityTaggings'] = await getDbActivityTaggings().toMapList();
}
// END COLLECTIONS (DbActivity)
return map;
......@@ -3022,6 +3093,11 @@ class DbActivity {
if (preloadFields == null || preloadFields.contains('plDbLaps')) {
obj.plDbLaps = obj.plDbLaps ?? await obj.getDbLaps().toList();
}
if (preloadFields == null ||
preloadFields.contains('plDbActivityTaggings')) {
obj.plDbActivityTaggings = obj.plDbActivityTaggings ??
await obj.getDbActivityTaggings().toList();
}
} // END RELATIONSHIPS PRELOAD
// RELATIONSHIPS PRELOAD
......@@ -3214,6 +3290,16 @@ class DbActivity {
if (!result.success) {
return result;
}
{
result = await DbActivityTagging()
.select()
.activitiesId
.equals(id)
.delete(hardDelete);
}
if (!result.success) {
return result;
}
if (!_softDeleteActivated || hardDelete) {
return _mnDbActivity
.delete(QueryParams(whereString: 'id=?', whereArguments: [id]));
......@@ -4129,6 +4215,11 @@ class DbActivityFilterBuilder extends SearchCriteria {
if (preloadFields == null || preloadFields.contains('plDbLaps')) {
obj.plDbLaps = obj.plDbLaps ?? await obj.getDbLaps().toList();
}
if (preloadFields == null ||
preloadFields.contains('plDbActivityTaggings')) {
obj.plDbActivityTaggings = obj.plDbActivityTaggings ??
await obj.getDbActivityTaggings().toList();
}
} // END RELATIONSHIPS PRELOAD
// RELATIONSHIPS PRELOAD
......@@ -6660,6 +6751,19 @@ class DbLap {
.equals(id)
.and;
}
/// to load children of items to this field, use preload parameter ex: toList(preload:true) or toSingle(preload:true)
List<DbLapTagging> plDbLapTaggings;
/// get DbLapTagging(s) filtered by lapsId=id
DbLapTaggingFilterBuilder getDbLapTaggings(
{List<String> columnsToSelect, bool getIsDeleted}) {
return DbLapTagging()
.select(columnsToSelect: columnsToSelect, getIsDeleted: getIsDeleted)
.lapsId
.equals(id)
.and;
}
// END COLLECTIONS & VIRTUALS (DbLap)
static const bool _softDeleteActivated = false;
......@@ -7080,6 +7184,9 @@ class DbLap {
if (!forQuery) {
map['DbEvents'] = await getDbEvents().toMapList();
}
if (!forQuery) {
map['DbLapTaggings'] = await getDbLapTaggings().toMapList();
}
// END COLLECTIONS (DbLap)
return map;
......@@ -7191,6 +7298,11 @@ class DbLap {
if (preloadFields == null || preloadFields.contains('plDbEvents')) {
obj.plDbEvents = obj.plDbEvents ?? await obj.getDbEvents().toList();
}
if (preloadFields == null ||
preloadFields.contains('plDbLapTaggings')) {
obj.plDbLapTaggings =
obj.plDbLapTaggings ?? await obj.getDbLapTaggings().toList();
}
} // END RELATIONSHIPS PRELOAD
// RELATIONSHIPS PRELOAD
......@@ -7352,6 +7464,13 @@ class DbLap {
if (!result.success) {
return result;
}
{
result =
await DbLapTagging().select().lapsId.equals(id).delete(hardDelete);
}
if (!result.success) {
return result;
}
if (!_softDeleteActivated || hardDelete) {
return _mnDbLap
.delete(QueryParams(whereString: 'id=?', whereArguments: [id]));
......@@ -8155,6 +8274,11 @@ class DbLapFilterBuilder extends SearchCriteria {
if (preloadFields == null || preloadFields.contains('plDbEvents')) {
obj.plDbEvents = obj.plDbEvents ?? await obj.getDbEvents().toList();
}
if (preloadFields == null ||
preloadFields.contains('plDbLapTaggings')) {
obj.plDbLapTaggings =
obj.plDbLapTaggings ?? await obj.getDbLapTaggings().toList();
}
} // END RELATIONSHIPS PRELOAD
// RELATIONSHIPS PRELOAD
......@@ -14383,6 +14507,34 @@ class DbTag {
}
// END RELATIONSHIPS (DbTag)
// COLLECTIONS & VIRTUALS (DbTag)
/// to load children of items to this field, use preload parameter ex: toList(preload:true) or toSingle(preload:true)
List<DbLapTagging> plDbLapTaggings;
/// get DbLapTagging(s) filtered by tagsId=id
DbLapTaggingFilterBuilder getDbLapTaggings(
{List<String> columnsToSelect, bool getIsDeleted}) {
return DbLapTagging()
.select(columnsToSelect: columnsToSelect, getIsDeleted: getIsDeleted)
.tagsId
.equals(id)
.and;
}
/// to load children of items to this field, use preload parameter ex: toList(preload:true) or toSingle(preload:true)
List<DbActivityTagging> plDbActivityTaggings;
/// get DbActivityTagging(s) filtered by tagsId=id
DbActivityTaggingFilterBuilder getDbActivityTaggings(
{List<String> columnsToSelect, bool getIsDeleted}) {
return DbActivityTagging()
.select(columnsToSelect: columnsToSelect, getIsDeleted: getIsDeleted)
.tagsId
.equals(id)
.and;
}
// END COLLECTIONS & VIRTUALS (DbTag)
static const bool _softDeleteActivated = false;
DbTagManager __mnDbTag;
......@@ -14437,6 +14589,15 @@ class DbTag {
map['tagGroupsId'] = tagGroupsId;
}
// COLLECTIONS (DbTag)
if (!forQuery) {
map['DbLapTaggings'] = await getDbLapTaggings().toMapList();
}
if (!forQuery) {
map['DbActivityTaggings'] = await getDbActivityTaggings().toMapList();
}
// END COLLECTIONS (DbTag)
return map;
}
......@@ -14491,6 +14652,20 @@ class DbTag {
for (final map in data) {
final obj = DbTag.fromMap(map as Map<String, dynamic>);
// RELATIONSHIPS PRELOAD
if (preload) {
if (preloadFields == null ||
preloadFields.contains('plDbLapTaggings')) {
obj.plDbLapTaggings =
obj.plDbLapTaggings ?? await obj.getDbLapTaggings().toList();
}
if (preloadFields == null ||
preloadFields.contains('plDbActivityTaggings')) {
obj.plDbActivityTaggings = obj.plDbActivityTaggings ??
await obj.getDbActivityTaggings().toList();
}
} // END RELATIONSHIPS PRELOAD
// RELATIONSHIPS PRELOAD
if (preload) {
if (preloadFields == null || preloadFields.contains('plDbTagGroup')) {
......@@ -14593,6 +14768,24 @@ class DbTag {
/// <returns>BoolResult res.success=Deleted, not res.success=Can not deleted
Future<BoolResult> delete([bool hardDelete = false]) async {
print('SQFENTITIY: delete DbTag invoked (id=$id)');
var result = BoolResult();
{
result =
await DbLapTagging().select().tagsId.equals(id).delete(hardDelete);
}
if (!result.success) {
return result;
}
{
result = await DbActivityTagging()
.select()
.tagsId
.equals(id)
.delete(hardDelete);
}
if (!result.success) {
return result;
}
if (!_softDeleteActivated || hardDelete) {
return _mnDbTag
.delete(QueryParams(whereString: 'id=?', whereArguments: [id]));
......@@ -15140,6 +15333,20 @@ class DbTagFilterBuilder extends SearchCriteria {
if (data.isNotEmpty) {
obj = DbTag.fromMap(data[0] as Map<String, dynamic>);
// RELATIONSHIPS PRELOAD
if (preload) {
if (preloadFields == null ||
preloadFields.contains('plDbLapTaggings')) {
obj.plDbLapTaggings =
obj.plDbLapTaggings ?? await obj.getDbLapTaggings().toList();
}
if (preloadFields == null ||
preloadFields.contains('plDbActivityTaggings')) {
obj.plDbActivityTaggings = obj.plDbActivityTaggings ??
await obj.getDbActivityTaggings().toList();
}
} // END RELATIONSHIPS PRELOAD
// RELATIONSHIPS PRELOAD
if (preload) {
if (preloadFields == null || preloadFields.contains('plDbTagGroup')) {
......@@ -16444,6 +16651,2134 @@ class DbTagGroupManager extends SqfEntityProvider {
}
//endregion DbTagGroupManager
// region DbLapTagging
class DbLapTagging {
DbLapTagging({this.id, this.system, this.tagsId, this.lapsId}) {
_setDefaultValues();
}
DbLapTagging.withFields(this.system, this.tagsId, this.lapsId) {
_setDefaultValues();
}
DbLapTagging.withId(this.id, this.system, this.tagsId, this.lapsId) {
_setDefaultValues();
}
DbLapTagging.fromMap(Map<String, dynamic> o) {
_setDefaultValues();
id = o['id'] as int;
if (o['system'] != null) system = o['system'] == 1 || o['system'] == true;
tagsId = o['tagsId'] as int;
lapsId = o['lapsId'] as int;
// RELATIONSHIPS FromMAP
plDbTag = o['DbTag'] != null
? DbTag.fromMap(o['DbTag'] as Map<String, dynamic>)
: null;
plDbLap = o['DbLap'] != null
? DbLap.fromMap(o['DbLap'] as Map<String, dynamic>)
: null;
// END RELATIONSHIPS FromMAP
}
// FIELDS (DbLapTagging)
int id;
bool system;
int tagsId;
int lapsId;
BoolResult saveResult;
// end FIELDS (DbLapTagging)
// RELATIONSHIPS (DbLapTagging)
/// to load parent of items to this field, use preload parameter ex: toList(preload:true) or toSingle(preload:true)
DbTag plDbTag;
/// get DbTag By TagsId
Future<DbTag> getDbTag() async {
final _obj = await DbTag().getById(tagsId);
return _obj;
}
/// to load parent of items to this field, use preload parameter ex: toList(preload:true) or toSingle(preload:true)
DbLap plDbLap;
/// get DbLap By LapsId
Future<DbLap> getDbLap() async {
final _obj = await DbLap().getById(lapsId);
return _obj;
}
// END RELATIONSHIPS (DbLapTagging)
static const bool _softDeleteActivated = false;
DbLapTaggingManager __mnDbLapTagging;
DbLapTaggingManager get _mnDbLapTagging {
return __mnDbLapTagging = __mnDbLapTagging ?? DbLapTaggingManager();
}
// METHODS
Map<String, dynamic> toMap({bool forQuery = false, bool forJson = false}) {
final map = <String, dynamic>{};
if (id != null) {
map['id'] = id;
}
if (system != null) {
map['system'] = forQuery ? (system ? 1 : 0) : system;
}
if (tagsId != null) {
map['tagsId'] = tagsId;
}
if (lapsId != null) {
map['lapsId'] = lapsId;
}
return map;
}
Future<Map<String, dynamic>> toMapWithChilds(
[bool forQuery = false, bool forJson = false]) async {
final map = <String, dynamic>{};
if (id != null) {
map['id'] = id;
}
if (system != null) {
map['system'] = forQuery ? (system ? 1 : 0) : system;
}
if (tagsId != null) {
map['tagsId'] = tagsId;
}
if (lapsId != null) {
map['lapsId'] = lapsId;
}
return map;
}
/// This method always returns Json String
String toJson() {
return json.encode(toMap(forJson: true));
}
/// This method always returns Json String
Future<String> toJsonWithChilds() async {
return json.encode(await toMapWithChilds(false, true));
}
List<dynamic> toArgs() {
return [id, system, tagsId, lapsId];
}
static Future<List<DbLapTagging>> fromWebUrl(String url) async {
try {
final response = await http.get(url);
return await fromJson(response.body);
} catch (e) {
print(
'SQFENTITY ERROR DbLapTagging.fromWebUrl: ErrorMessage: ${e.toString()}');
return null;
}
}
static Future<List<DbLapTagging>> fromJson(String jsonBody) async {
final Iterable list = await json.decode(jsonBody) as Iterable;
var objList = <DbLapTagging>[];
try {
objList = list
.map((dblaptagging) =>
DbLapTagging.fromMap(dblaptagging as Map<String, dynamic>))
.toList();
} catch (e) {
print(
'SQFENTITY ERROR DbLapTagging.fromJson: ErrorMessage: ${e.toString()}');
}
return objList;
}
/*
/// REMOVED AFTER v1.2.1+14
static Future<List<DbLapTagging>> fromObjectList(Future<List<dynamic>> o) async {
final data = await o;
return await DbLapTagging.fromMapList(data);
}
*/
static Future<List<DbLapTagging>> fromMapList(List<dynamic> data,
{bool preload = false, List<String> preloadFields}) async {
final List<DbLapTagging> objList = <DbLapTagging>[];
for (final map in data) {
final obj = DbLapTagging.fromMap(map as Map<String, dynamic>);
// RELATIONSHIPS PRELOAD
if (preload) {
if (preloadFields == null || preloadFields.contains('plDbTag')) {
obj.plDbTag = obj.plDbTag ?? await obj.getDbTag();
}
if (preloadFields == null || preloadFields.contains('plDbLap')) {
obj.plDbLap = obj.plDbLap ?? await obj.getDbLap();
}
} // END RELATIONSHIPS PRELOAD
objList.add(obj);
}
return objList;
}
/// returns DbLapTagging by ID if exist, otherwise returns null
/// <param name='id'>Primary Key Value</param>
/// <returns>returns DbLapTagging if exist, otherwise returns null
Future<DbLapTagging> getById(int id) async {
if (id == null) {
return null;
}
DbLapTagging obj;
final data = await _mnDbLapTagging.getById(id);
if (data.length != 0) {
obj = DbLapTagging.fromMap(data[0] as Map<String, dynamic>);
} else {
obj = null;
}
return obj;
}
/// Saves the (DbLapTagging) object. If the id field is null, saves as a new record and returns new id, if id is not null then updates record
/// <returns>Returns id
Future<int> save() async {
if (id == null || id == 0) {
id = await _mnDbLapTagging.insert(this);
} else {
id = await _upsert();
}
return id;
}
/// saveAs DbLapTagging. Returns a new Primary Key value of DbLapTagging
/// <returns>Returns a new Primary Key value of DbLapTagging
Future<int> saveAs() async {
id = null;
return save();
}
/// saveAll method saves the sent List<DbLapTagging> as a bulk in one transaction
///
/// Returns a <List<BoolResult>>
Future<List<BoolResult>> saveAll(List<DbLapTagging> dblaptaggings) async {
final results = _mnDbLapTagging.saveAll(
'INSERT OR REPLACE INTO lapTaggings (id, system, tagsId, lapsId) VALUES (?,?,?,?)',
dblaptaggings);
return results;
}
/// Updates if the record exists, otherwise adds a new row
/// <returns>Returns id
Future<int> _upsert() async {
try {
if (await _mnDbLapTagging.rawInsert(
'INSERT OR REPLACE INTO lapTaggings (id, system, tagsId, lapsId) VALUES (?,?,?,?)',
[id, system, tagsId, lapsId]) ==
1) {
saveResult = BoolResult(
success: true,
successMessage: 'DbLapTagging id=$id updated successfuly');
} else {
saveResult = BoolResult(
success: false, errorMessage: 'DbLapTagging id=$id did not update');
}
return id;
} catch (e) {
saveResult = BoolResult(
success: false,
errorMessage: 'DbLapTagging Save failed. Error: ${e.toString()}');
return 0;
}
}
/// inserts or replaces the sent List<<DbLapTagging>> as a bulk in one transaction.
///
/// upsertAll() method is faster then saveAll() method. upsertAll() should be used when you are sure that the primary key is greater than zero
///
/// Returns a <List<BoolResult>>
Future<List<BoolResult>> upsertAll(List<DbLapTagging> dblaptaggings) async {
final results = await _mnDbLapTagging.rawInsertAll(
'INSERT OR REPLACE INTO lapTaggings (id, system, tagsId, lapsId) VALUES (?,?,?,?)',
dblaptaggings);
return results;
}
/// Deletes DbLapTagging
/// <returns>BoolResult res.success=Deleted, not res.success=Can not deleted
Future<BoolResult> delete([bool hardDelete = false]) async {
print('SQFENTITIY: delete DbLapTagging invoked (id=$id)');
if (!_softDeleteActivated || hardDelete) {
return _mnDbLapTagging
.delete(QueryParams(whereString: 'id=?', whereArguments: [id]));
} else {
return _mnDbLapTagging.updateBatch(
QueryParams(whereString: 'id=?', whereArguments: [id]),
{'isDeleted': 1});
}
}
//private DbLapTaggingFilterBuilder _Select;
DbLapTaggingFilterBuilder select(
{List<String> columnsToSelect, bool getIsDeleted}) {
return DbLapTaggingFilterBuilder(this)