@@ -444,3 +444,60 @@ class MySqlResult {
444444abstract class DataAssoc {
445445 Future <Map <String , Object ?>> toAssoc (Map <String , Object ?> row);
446446}
447+
448+ /// Abstract base class for MySQL table operations.
449+ abstract class MysqlTable {
450+ MySQLConnection get db;
451+
452+ String get tableName;
453+
454+ QField get qName => QField (tableName);
455+
456+ MTable get table => MTable (
457+ name: tableName,
458+ fields: [],
459+ );
460+
461+ Future <MySqlResult > deleteBy (Where where) async {
462+ var query = Sqler ()
463+ ..from (qName)
464+ ..delete ()
465+ ..where (where);
466+ return table.execute (db, query.toSQL ());
467+ }
468+
469+ Future <MySqlResult > deleteById (int id) async {
470+ return deleteBy (WhereOne (QField ('id' ), QO .EQ , QVar (id)));
471+ }
472+
473+ Future <MySqlResult > findById (int id) async {
474+ var query = Sqler ()
475+ ..from (qName)
476+ ..selects ([
477+ ...table.allSelectFields (),
478+ ])
479+ ..where (WhereOne (QField ('id' ), QO .EQ , QVar (id)));
480+ var res = await table.select (db, query);
481+ return res;
482+ }
483+
484+ Future <int > countBy (Where where) async {
485+ var query = Sqler ()
486+ ..from (qName)
487+ ..addSelect (SQL .count (QField ('id' , as : 'count_records' )))
488+ ..where (where);
489+ var result = await table.execute (db, query.toSQL ());
490+ return result.countRecords;
491+ }
492+
493+ /// All abstract methods
494+ Future <({int count, MySqlResult rows})> findAll ({
495+ String orderBy = 'id' ,
496+ bool orderReverse = true ,
497+ Map <String , dynamic > filters = const {},
498+ int ? pageSize,
499+ int ? offset,
500+ });
501+
502+ Sqler updateFilters (Sqler query, Map <String , dynamic > filter);
503+ }
0 commit comments