Adapter for MySQL servers, built on the MySQLOO binary module (gmsv_mysqloo). It is used when the database settings name the 'mysqloo' or 'mysql' adapter. Queries run asynchronously unless the adapter is in sync mode, and queries with bind parameters are sent as prepared statements. Tables are created with the InnoDB engine and the encoding of the database settings ('utf8' by default), and the connection is pinged every 30 seconds to keep it alive. Unlike the other adapters, it does not run migrations in a transaction.

Summary

Methods

Sets the table options (InnoDB engine and default charset) on a query before its SQL is built.
Connects to a MySQL server through MySQLOO and pings it every 30 seconds to keep the connection alive.
Makes the column the primary key of the table when a 'primary_key' column is created.
Closes the MySQL connection, if there is one.
Escapes a string using the MySQL connection.
Converts a unix timestamp to the date-time form that MySQL takes in date-time columns.
init()shared
Loads the 'mysqloo' binary module.
Checks whether the adapter talks to a MySQL database.
Quotes an identifier such as a table or column name with backticks, doubling the backticks in it.
Runs a raw SQL query on the MySQL server.

Methods

ActiveRecord.Adapters.Mysqloo:append_query(query, _query_type, _queue)

shared packages/active_record/lib/adapters/mysqloo.lua:214

Sets the table options (InnoDB engine and default charset) on a query before its SQL is built.

Parameters

  • query ActiveRecord::Query
  • _query_type String unused
  • _queue Boolean optional, defaults to nil unused

ActiveRecord.Adapters.Mysqloo:connect(config, on_connected)

shared packages/active_record/lib/adapters/mysqloo.lua:52

Connects to a MySQL server through MySQLOO and pings it every 30 seconds to keep the connection alive. Calls #on_connection_failed if the connection fails.

Parameters

  • config Map database settings: host, user, password, database, port (3306 if omitted), socket and flags
  • on_connected Function optional, defaults to nil called with the adapter once the connection is ready

ActiveRecord.Adapters.Mysqloo:create_column(query, column, _args, _obj, type, _def)

shared packages/active_record/lib/adapters/mysqloo.lua:225

Makes the column the primary key of the table when a 'primary_key' column is created.

Parameters

  • query ActiveRecord::Query query the column was added to
  • column String column name
  • _args Map unused
  • _obj ActiveRecord::Query unused
  • type String abstract column type
  • _def String unused

ActiveRecord.Adapters.Mysqloo:disconnect()

shared packages/active_record/lib/adapters/mysqloo.lua:103

Closes the MySQL connection, if there is one.

ActiveRecord.Adapters.Mysqloo:escape(str)

shared packages/active_record/lib/adapters/mysqloo.lua:114

Escapes a string using the MySQL connection. Requires an established connection.

Parameters

  • str String

Returns

  • String

ActiveRecord.Adapters.Mysqloo:format_datetime(unix_time)

shared packages/active_record/lib/adapters/mysqloo.lua:37

Converts a unix timestamp to the date-time form that MySQL takes in date-time columns.

Parameters

  • unix_time Number

Returns

  • String e.g. '2019-03-09 12:00:00', in UTC

ActiveRecord.Adapters.Mysqloo:init()

shared packages/active_record/lib/adapters/mysqloo.lua:30

Loads the 'mysqloo' binary module.

ActiveRecord.Adapters.Mysqloo:is_mysql()

shared packages/active_record/lib/adapters/mysqloo.lua:43

Checks whether the adapter talks to a MySQL database.

Returns

  • Boolean always true

ActiveRecord.Adapters.Mysqloo:quote_name(str)

shared packages/active_record/lib/adapters/mysqloo.lua:122

Quotes an identifier such as a table or column name with backticks, doubling the backticks in it.

Parameters

  • str String

Returns

  • String

ActiveRecord.Adapters.Mysqloo:raw_query(query, callback, query_type, bindings, error_callback)

shared packages/active_record/lib/adapters/mysqloo.lua:138

Runs a raw SQL query on the MySQL server. In sync mode this blocks until the query is done; without a connection the query is put into the queue instead. A query that is given bindings is run as a prepared statement.

Parameters

  • query String SQL to run
  • callback Function optional, defaults to nil called with the result rows (a List of row Maps), the query string, the time the query took in seconds and the bindings. For 'insert' queries the result is a single row with the id of the new row instead
  • query_type String optional, defaults to nil lowercase query type, e.g. 'insert'
  • bindings List optional, defaults to nil values of the ? placeholders in the query. A query that is given bindings has to be a single statement
  • error_callback Function optional, defaults to nil called with the error text if the query fails

Returns

  • Any whatever the callback returns in sync mode, nothing otherwise

Defined in