No commit activity in last 3 years
No release in over 3 years
Simple stocker general log for mysql2 gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0

Runtime

>= 0
 Project Readme

Mysql2::Client::GeneralLog

Build Status

A monkey patch for Mysql2. Stock all general logs.

#! /usr/bin/env ruby

require "mysql2/client/general_log"

client = Mysql2::Client.new(config)
client.query("SELECT * FROM users LIMIT 1")

p client.general_log #=>
# [
#   #<struct Mysql2::Client::GeneralLog::Log
#     sql="SELECT * FROM users LIMIT 1",
#     backtrace=["script.rb:6:in `<main>'"],
#     time=0.0909838349907659>
# ]

Examples

sinatra

helpers do
  def db
    Thread.current[:db] ||= Mysql2::Client.new(config)
  end
end

get '/' do
  # ...
end

after do
  puts db.general_log.map(&:sql)
  puts "path:#{request.path}\tsql:#{db.general_log.length}"
  db.general_log.clear
end

Installation

Add this line to your application's Gemfile:

gem 'mysql2-client-general_log'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mysql2-client-general_log

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mysql2-client-general_log. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.