turbo_mysql 0.0.2 copy "turbo_mysql: ^0.0.2" to clipboard
turbo_mysql: ^0.0.2 copied to clipboard

A high-performance MySQL client powered by Rust FFI.

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 #

  • ✅ Connection pooling
  • ✅ Simple text queries (queryRaw)
  • ✅ Parameterized queries with automatic type binding (query)
  • ✅ Prepared statements (prepare)
  • ✅ Statement Caching (stmtCacheSize)
  • ✅ Batch inserts (insertBatch)
  • ✅ Batch upserts / ON DUPLICATE KEY UPDATE (upsertBatch)
  • ✅ Transactions (beginTransaction, commit, rollback)
  • ✅ Extensive Data Type Support (JSON, BLOB, ENUM, SET, DateTime, etc.)
  • ✅ SSL/TLS Support (requireSsl, verifyCa, verifyIdentity)
  • ✅ Connection Lifecycle Management (TTL, Absolute TTL with Jitter)
  • ✅ Network & Protocol Tuning (TCP Keepalive, Nodelay, Compression, Max Allowed Packet)
  • ✅ Pre/Post Connection Hooks (init and setup queries)
  • ✅ Unix Domain Sockets (preferSocket, socket)
  • ✅ Secure Auth & Cleartext Plugin support
  • ✅ Native 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();
}

2
likes
150
points
132
downloads

Publisher

unverified uploader

Weekly Downloads

A high-performance MySQL client powered by Rust FFI.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

code_assets, ffi, hooks

More

Packages that depend on turbo_mysql