Skip to content

cryodex/sql-rewriter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sql-rewriter

A Ruby library for SQL query analysis, rewriting and injection. Currently supports ActiveRecord.

Features

  • Receive a callback before execution of an SQL query with a parsed AST representing the query
  • Receive a callback after execution of an SQL query

Usage

Example ActiveRecord application

config = { adapter: 'sqlite3', database: 'test.sqlite' }

ActiveRecord::Base.establish_connection(config)

class User < ActiveRecord::Base
  
  has_many :problems
  
end

class Problem < ActiveRecord::Base
  
  belongs_to :users
  
end

Example SQLRewriter configuration

SQLRewriter.inject(ActiveRecord) do
  
  before_query do |sql, binds, ast|

    # pre-process SQL query

    # AST will be nil upon parse failure
    ast ? ast.to_sql : sql

  end
  
  after_query do |result|

    # post-process retrieved data

    result

  end
  
end

###License

This software is released under the MIT license.

About

Ruby library for SQL query analysis, rewriting and injection

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages