Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/winebarrel/spring_onion
Log MySQL queries with EXPLAIN that may be slow.'
https://github.com/winebarrel/spring_onion
activerecord mysql rails ruby
Last synced: 30 days ago
JSON representation
Log MySQL queries with EXPLAIN that may be slow.'
- Host: GitHub
- URL: https://github.com/winebarrel/spring_onion
- Owner: winebarrel
- License: mit
- Created: 2020-07-17T17:03:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-08-24T02:43:45.000Z (about 1 year ago)
- Last Synced: 2024-10-08T10:17:36.528Z (about 1 month ago)
- Topics: activerecord, mysql, rails, ruby
- Language: Ruby
- Homepage:
- Size: 60.5 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# SpringOnion
Log MySQL queries with EXPLAIN that may be slow.
Inspired by [MySQLCasualLog.pm](https://gist.github.com/kamipo/839e8a5b6d12bddba539).
[![Build Status](https://travis-ci.org/winebarrel/spring_onion.svg?branch=master)](https://travis-ci.org/winebarrel/spring_onion)
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'spring_onion'
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install spring_onion
## Usage
```ruby
#!/usr/bin/env ruby
require 'active_record'
require 'spring_onion'ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
username: 'root',
database: 'employees'
)SpringOnion.enabled = true # or `SPRING_ONION_ENABLED=1`
# `SPRING_ONION_DATABASE_URL=mysql2://...`
# default: SpringOnion.connection = ActiveRecord::Base.connection.raw_connection
SpringOnion.source_filter_re = //class Employee < ActiveRecord::Base; end
p Employee.all.to_a.count
#=> SpringOnion INFO 2020-07-18 01:53:27 +0900 {"sql":"SELECT `employees`.* FROM `employees`","explain":[{"line":1,"select_type":"SIMPLE","table":"employees","partitions":null,"type":"ALL","possible_keys":null,"key":null,"key_len":null,"ref":null,"rows":298936,"filtered":100.0,"Extra":null}],"warnings":{"line 1":["slow_type"]},"backtrace":["/foo/bar/zoo/baz.rb:18:in `\u003ctop (required)\u003e'"]}
#=> 300024
```## Log Output
```json
{
"sql": "SELECT `employees`.* FROM `employees`",
"explain": [
{
"line": 1,
"select_type": "SIMPLE",
"table": "employees",
"partitions": null,
"type": "ALL",
"possible_keys": null,
"key": null,
"key_len": null,
"ref": null,
"rows":298936,
"filtered": 100.0,
"Extra": null
}
],
"warnings": {
"line 1": [
"slow_type"
]
},
"backtrace": [
"/foo/bar/zoo/baz.rb:18:in `\u003ctop (required)\u003e'"
]
}
```## Test
```sh
docker-compose build
docker-compose run client bundle exec appraisal ar60 rake
```