turbo_mysql
A high-performance MySQL client for Dart, powered by Rust via FFI. It provides a robust connection pool, prepared statements, and efficient batch operations.
Features
xConnection poolingxSimple text queries (queryRaw)xParameterized queries with automatic type binding (query)xPrepared statements (prepare)xStatement Caching (stmtCacheSize)xBatch inserts (insertBatch)xBatch upserts / ON DUPLICATE KEY UPDATE (upsertBatch)xTransactions (beginTransaction,commit,rollback)xExtensive Data Type Support (JSON, BLOB, ENUM, SET, DateTime, etc.)xSSL/TLS Support (requireSsl,verifyCa,verifyIdentity)xConnection Lifecycle Management (TTL, Absolute TTL with Jitter)xNetwork & Protocol Tuning (TCP Keepalive, Nodelay, Compression, Max Allowed Packet)xPre/Post Connection Hooks (initandsetupqueries)xUnix Domain Sockets (preferSocket,socket)xSecure Auth & Cleartext Plugin supportxNative Rust performance via FFI
Installation
Add turbo_mysql to your pubspec.yaml dependencies:
dependencies:
turbo_mysql: latest_version
Examples
Advanced Configuration
import 'package:turbo_mysql/turbo_mysql.dart';
final pool = MySqlPool(
MySqlConfig(
host: '127.0.0.1',
user: 'root',
pass: 'password',
dbName: 'my_database',
poolMin: 2,
poolMax: 20,
tcpKeepalive: 10000,
connTtl: 60000,
absConnTtl: 120000,
absConnTtlJitter: 5000,
stmtCacheSize: 100,
requireSsl: true,
compression: 'fast',
init: ['SET NAMES utf8mb4', 'SET time_zone = "+00:00"'],
setup: ['SET SESSION sql_mode = "STRICT_ALL_TABLES"'],
),
);
await pool.connect();
Simple and Parameterized Queries
await pool.queryRaw('SELECT id, name FROM users LIMIT 10');
await pool.query(
'SELECT * FROM users WHERE age > ? AND is_active = ?',
[18, true],
);
Prepared Statements
final stmt = await pool.prepare('INSERT INTO metrics (cpu, memory) VALUES (?, ?)');
await stmt.query([45.2, 1024]);
await stmt.query([50.1, 2048]);
await stmt.release();
Batch Inserts and Upserts
final columns = ['name', 'age'];
final rows = [
['Alice', 28],
['Bob', 34],
['Charlie', 22],
];
final insertedCount = await pool.insertBatch('users', columns, rows);
final upsertedCount = await pool.upsertBatch('users', columns, rows);
Transactions
final tx = await pool.beginTransaction();
try {
await tx.query('UPDATE accounts SET balance = balance - ? WHERE id = ?', [100, 1]);
await tx.query('UPDATE accounts SET balance = balance + ? WHERE id = ?', [100, 2]);
await tx.commit();
} catch (e) {
await tx.rollback();
}
Libraries
- turbo_mysql
- A high-performance MySQL client for Dart, powered by Rust.