MysqlUtils class

mysql helper

Constructors

MysqlUtils({required Map settings, Function? errorLog, Function? sqlLog, Function? connectInit})
factory

Properties

connectInit Function?
final
errorLog Function?
sql error log
final
hashCode int
The hash code for this object.
no setterinherited
poolConn Future<MySQLConnectionPool>
pool connect
getter/setter pair
queryTimes int
query Times
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
singleConn Future<MySQLConnection>
single connect
getter/setter pair
sqlEscape bool
sqlEscape
getter/setter pair
sqlLog Function?
show sql log
final
transTimes int
transaction start
getter/setter pair

Methods

avg({required String table, String fields = '', dynamic where = const {}, String group = '', String having = '', bool debug = false}) Future<double>
await db.avg( table: 'table', fields: '*', group: 'name', having: 'name', debug: false, where:{ 'id':['>',1], } );
close() Future<void>
close
commit() Future<void>
db.commit();
count({required String table, String fields = '*', dynamic where = const {}, String group = '', String having = '', bool debug = false}) Future<int>
await db.count( table: 'table', fields: '*', group: 'name', having: 'name', debug: false, where:{ 'id':['>',1], } );
createConnectionPool(Map settings) Future<MySQLConnectionPool>
create pool connection
createConnectionSingle(Map settings) Future<MySQLConnection>
create single connection
delete({required String table, required dynamic where, bool debug = false}) Future<int>
await db.delete( table:'table', where: {'id':1} );
errorRollback() Future<void>
errorRack
getAll({required String table, String fields = '*', dynamic where = const {}, String order = '', dynamic limit = '', String group = '', String having = '', bool debug = false}) Future<List>
await db.getAll( table: 'table', fields: '*', group: 'name', having: 'name', order: 'id desc', limit: 10,//10 or '10 ,100' debug: false, where: { 'email': 'xxx@google.com', 'id': ['between', '1,4'], 'email2': ['=', 'sss@google.com'], 'news_title': ['like', '%name%'], 'user_id': ['>', 1], '_SQL': '(`isNet`=1 OR `isNet`=2)', }, //where:'`id`=1 AND name like "%jame%"', );
getOne({required String table, String fields = '*', dynamic where = const {}, String group = '', String having = '', String order = '', bool debug = false}) Future<Map>
await db.getOne( table: 'table', fields: '*', group: 'name', having: 'name', order: 'id desc', debug: false, where: { 'email': 'xxx@google.com', 'id': ['between', '1,4'], 'email2': ['=', 'sss@google.com'], 'news_title': ['like', '%name%'], 'user_id': ['>', 1], '_SQL': '(`isNet`=1 OR `isNet`=2)', }, //where:'`id`=1 AND name like "%jame%"', );
insert({required String table, required Map<String, dynamic> insertData, dynamic replace = false, dynamic debug = false}) Future<int>
return lastInsertID await db.insert( table: 'table', insertData: { 'telphone': '+113888888888', 'create_time': 1620577162252, 'update_time': 1620577162252, }, );
insertAll({required String table, required List<Map<String, dynamic>> insertData, dynamic replace = false, dynamic debug = false}) Future<int>
return affectedRows
isConnectionAlive() Future<bool>
isConnectionAlive
max({required String table, String fields = '', dynamic where = const {}, String group = '', String having = '', bool debug = false}) Future<double>
await db.max( table: 'table', fields: '*', group: 'name', having: 'name', debug: false, where:{ 'id':['>',1], } );
min({required String table, String fields = '', dynamic where = const {}, String group = '', String having = '', bool debug = false}) Future<double>
await db.min( table: 'table', fields: '*', group: 'name', having: 'name', debug: false, where:{ 'id':['>',1], } );
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
query(String sql, {Map<String, dynamic> values = const {}, dynamic debug = false}) Future<ResultFormat>
query
queryMulti(String sql, Iterable<List<Object?>> values, {dynamic debug = false}) Future<List<int>>
query multi
rollback() Future<void>
db.rollback();
sqlEscapeString(String sqlString) String
SQL-escape a string.
startTrans() Future<void>
await db.startTrans();
toString() String
A string representation of this object.
inherited
update({required String table, required Map<String, dynamic> updateData, required dynamic where, bool debug = false}) Future<int>
await db.update( table: 'table', updateData:{ 'telphone': '1231', 'create_time': 12, 'update_time': 12121212, 'email': 'biner@dd.com' }, where:{ 'id':1, });

Operators

operator ==(Object other) bool
The equality operator.
inherited