mysql MySQL standard library

mysql MySQL standard library

mysql MySQL standard library

Function

mysql(dsn) creates a MySQL query builder that supports SQL settings, normal binding, batch binding, batch execution, querying multiple rows, querying a single row, writing execution and SQL preview.

API List

APIDescription
mysql.querySet the SQL text of the current MySQL object.
mysql.bindAppend a set of common binding parameters.
mysql.bindsAppend multiple rows of batch binding parameters.
mysql.batchSet the number of rows per batch for batch exec.
mysql.workersSet the number of concurrent jobs for batch exec.
mysql.beginStart a MySQL transaction and return the transaction handle.
MysqlTransactionTransaction handle, supports query/bind/all/one/exec/commit/rollback/close within the transaction.
mysql.allExecute a query and return multiple rows of results.
mysql.oneExecute the query and return a single row of results.
mysql.execExecute SQL that does not require returning a result set. Ordinary binding is executed once; binds batch configuration will be executed by batch/workers.
mysql.sqlReturns the debugging text of the current SQL.

Examples

Notes

  • all/one/exec will reuse the process-level I/O runtime and wait for database results synchronously.
  • MySQL common query connection pool is enabled by default and multiplexed by DSN group; the pool status can be viewed through BT.stats().mysql, and statistics will not reveal the DSN password.
  • begin will open a transaction and exclusively own a connection; commit, rollback, or close must be explicitly called after the transaction is completed.
  • binds().exec() batch execution still creates a temporary connection pool according to this workers() to avoid the global pool from changing the batch concurrency boundary.
  • all/one will reject binds, batch, and workers to prevent batch configuration from being silently misused.

MySQL common query connection pool default configuration:

Environment variableDefault valueDescription
BT_MYSQL_POOLtrueWhether to enable the common query global connection pool.
BT_MYSQL_POOL_LIMIT16, maximum 256Maximum number of DSN packets to retain.
BT_MYSQL_POOL_MIN_CONNECTIONS0Minimum number of connections per connection pool.
BT_MYSQL_POOL_MAX_CONNECTIONS8, maximum 1024Maximum number of connections per connection pool.
BT_MYSQL_POOL_IDLE_TTL_MS300000Connection pool idle retention time, in milliseconds; 0 means no elimination based on idle time.
BT_MYSQL_CONNECT_TIMEOUT_MS5000Get the connection timeout, in milliseconds.
BT_MYSQL_QUERY_TIMEOUT_MS30000Synchronization wait timeout for a single SQL call, in milliseconds.
BT_MYSQL_SLOW_MS0Slow MySQL call log threshold, in milliseconds; 0 means closed.