mysql_utils는 Flutter 애플리케이션에서 MySQL 데이터베이스 상호작용을 단순화하는 mysql_client_plus의 보조 라이브러리입니다. 최소한의 반복 코드로 MySQL 데이터베이스에 연결하고 쿼리를 실행하며 결과를 처리하는 간편한 메서드를 제공합니다. 개발자 생산성을 향상시키기 위해 설계되었으며, Android, iOS, macOS, Windows, Linux 등 여러 플랫폼과의 호환성을 유지하면서 일반적인 작업을 추상화합니다. 복잡한 설정 없이 신뢰할 수 있고 간단한 MySQL 통합이 필요한 프로젝트에 이상적입니다.
사용 사례
간단한 MySQL 쿼리 실행
데이터베이스 연결 관리
크로스플랫폼 데이터베이스 액세스
간소화된 CRUD 작업
mysql_client_plus와의 통합
주요 기능
사용하기 쉬운 쿼리 인터페이스
mysql_client_plus 기반
모든 주요 데스크톱 및 모바일 플랫폼을 지원합니다
반복 코드를 줄입니다
자동 결과 분석
적합한 대상
MySQL 연결이 필요한 Flutter 앱
간단한 데이터베이스 도우미를 찾는 개발자
mysql_client_plus를 사용하는 프로젝트
MySQL 데이터베이스를 갖춘 백엔드 서비스
데이터베이스를 활용한 빠른 프로토타이핑
고려 사항
mysql_client_plus를 종속성으로 필요로 합니다
MySQL 데이터베이스에 한정
복잡한 SQL 트랜잭션에 적합하지 않습니다
내장된 마이그레이션 지원 없음
외부 MySQL 서버 가용성에 따라 다름
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
mysql_utils
Flutter mysql plugin helps extend classes.
mysql_client has been abandoned and is now maintained by the author of this library. The new library is mysql_client_plus。
Updated settings from Map to MysqlUtilsSettings ⚠️⚠️⚠️
Added support for BLOB and JSON types
Added support for SSL certificates
Added support for calling stored procedures
Added support for sha256_password authentication
Added global debug option
Added tests
APIs
Initialization connection
Use the singleton mode, and call close() after use to close the database connection.
var db = MysqlUtils(
// ⚠️⚠️⚠️ settings from `Map` to `MysqlUtilsSettings`
settings: MysqlUtilsSettings(
// The hostname of the MySQL server, defaults to localhost.
host: '127.0.0.1',
// The port number to connect to, defaults to 3306.
port: 3306,
// The username to connect as, defaults to root.
user: 'your_user_sha256',
// The password to connect with, defaults to empty string.
password: 'your_password_sha256',
// The database to use, defaults to empty string.
db: 'testdb',
// Whether to use SSL, defaults to false.
secure: true,
// The prefix to use for table names, defaults to empty string.
prefix: '',
// The maximum number of connections to keep open, defaults to 1000.
maxConnections: 1000,
// The timeout in milliseconds for each connection, defaults to 10000.
timeoutMs: 10000,
// Whether to escape all queries, defaults to true.
sqlEscape: true,
// Whether to use a connection pool, defaults to false.
pool: true,
// The collation to use for all queries, defaults to utf8mb4_general_ci.
collation: 'utf8mb4_general_ci',
// Whether to use SSL, defaults to false.
debug: true,
// The SSL options to use for all queries, defaults to null.// securityContext: SecurityContext(),// sslMode: SslMode.require,// onBadCertificate: (certificate) => true,
),
errorLog: (error) {
print(error);
},
sqlLog: (sql) {
print(sql);
},
connectInit: (db1) async {
print('whenComplete');
}
);
query
Native query
//var row = await db.query('select id from test_data2 where id=? or string_column like ?', whereValues: [1, '%串%'], isStmt: true);var row = await db.query("select id from test_data2 where id=1 or string_column like '%mysql%'");
print(row.toMap());
print(row.toMap());
//// print(row.rowsAssoc.first.assoc());// for (var item in row.rowsAssoc) {// print(item.assoc());// }// for (final row in row.rowsAssoc) {// print(row.colAt(0));// print(row.colByName("nickname"));// print(row.assoc());// }// db.close();
Multi table query
Query Multi data , multi-table query
var res = await db.getAll(
table: 'user tb1,upload tb2',
fields: 'tb2.fileSize',
where: 'tb2.id>0 and tb2.uid=tb1.id',
debug: true,
);
print(res);
getOne
Query one data
var row = await db.getOne(
table: 'table',
fields: '*',
//excludeFields: 'telphone,image',//group: 'name',//having: 'name',//order: 'id desc',//limit: 10,//10 or '10 ,100'// where: {// 'email': 'xxx@google.com',// 'id': ['between', '1,4'],// 'email2': ['=', 'sss@google.com'],// 'news_title': ['like', '%name%'],// 'user_id': ['>', 1],// 'user_id': ['<', 1],// 'user_id': ['<>', 1],// 'user_id': ['=', 1],// 'email3': ['!=', 'sss@google.com'],// '_SQL': '(`isNet`=1 OR `isNet`=2)',// },//where:'`id`=1 AND name like "%jame%"',
);
print(row);
getAll
Query multiple data
var row = await db.getAll(
table: 'table',
fields: '*',
//excludeFields: 'telphone,image',//group: 'name',//having: 'name',//order: 'id desc',//limit: 10,//10 or '10 ,100'// 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%"',
);
print(row);