Module: Sequel::SqlRecorder
- Defined in:
- lib/sequel/extensions/sql_recorder.rb
Overview
Extension module that adds SQL recording capabilities to Sequel databases. When included, it provides a sql_recorder method that returns an array of all SQL statements executed against the database.
Instance Attribute Summary collapse
-
#sql_recorder ⇒ Array<String>
readonly
Returns the array of recorded SQL statements.
Class Method Summary collapse
-
.extended(db) ⇒ Object
Initializes the SQL recording infrastructure when the extension is loaded.
Instance Method Summary collapse
-
#log_connection_yield(sql, conn, args = nil) ⇒ Object
Intercepts SQL execution to record statements.
Instance Attribute Details
#sql_recorder ⇒ Array<String> (readonly)
Returns the array of recorded SQL statements.
The array accumulates all SQL statements sent to the database since the extension was loaded or since the last time clear was called on the array.
51 52 53 |
# File 'lib/sequel/extensions/sql_recorder.rb', line 51 def sql_recorder @sql_recorder end |
Class Method Details
.extended(db) ⇒ Object
Initializes the SQL recording infrastructure when the extension is loaded.
Sets up the mutex for thread-safe access and initializes the SQL recording array. This method is automatically called when the extension is loaded via DB.extension :sql_recorder.
74 75 76 77 78 79 |
# File 'lib/sequel/extensions/sql_recorder.rb', line 74 def self.extended(db) db.instance_exec do @sql_recorder_mutex ||= Mutex.new @sql_recorder ||= [] end end |
Instance Method Details
#log_connection_yield(sql, conn, args = nil) ⇒ Object
Intercepts SQL execution to record statements.
This method overrides Sequel’s log_connection_yield to capture each SQL statement in a thread-safe manner before delegating to the parent implementation.
62 63 64 65 |
# File 'lib/sequel/extensions/sql_recorder.rb', line 62 def log_connection_yield(sql, conn, args = nil) @sql_recorder_mutex.synchronize { sql_recorder.push(sql) } super end |