Giter Club home page Giter Club logo

threequel's Introduction

Threequel

Code Climate Build Status

Modules

Commandant

Objectify your SQL scripts. Take blocks of SQL from an .sql script and turn them into class methods on your models/classes.

include Threequel::Commandant

Servant

Run a series of co-dependant .sql scripts to perform tasks.

Classes

SQL::CommandHash

A Hash subclass that maps to Commandant SQL class methods. Keys are the SQL class method names and Values are SQL::Command objects.

SQL::Command

A class that can execute a series of SQL blocks on a specified connection.

sql = <<-"SQL"
 CREATE TABLE dbo.foo (bar varchar(20) NOT NULL);
 GO

 DROP TABLE dbo.foo;
 GO
SQL

connection = ActiveRecord::Base.connection

cmd = Threequel::SQL::Command.new(sql, "My Command")
cmd.execute_on connection

# SQL (23.6ms)  CREATE TABLE dbo.foo (bar varchar(20) NOT NULL);
# SQL (37.1ms)  DROP TABLE dbo.foo;
# => {:message=>"Command executed successfully", :status=>:success} 

# or
Threequel::SQL::Command.new(sql, "My Command") do |cmd|
  cmd.execute_on connection
end

# SQL (23.6ms)  CREATE TABLE dbo.foo (bar varchar(20) NOT NULL);
# SQL (37.1ms)  DROP TABLE dbo.foo;
# => {:message=>"Command executed successfully", :status=>:success} 

Logging

Adds logging to any instance method.

sql = <<-"SQL"
 CREATE TABLE dbo.foo (bar varchar(20) NOT NULL);
 GO

 DROP TABLE dbo.foo;
 GO
SQL

connection = ActiveRecord::Base.connection

Threequel::SQL::Command.new(sql, "My Command") do |cmd|
  cmd.extend Threequel::Logging
  cmd.add_logging_to :execute_on, :console
  cmd.execute_on connection
end
# -- Starting execution of My Command at 2012-07-25 17:13:43 -0400
# SQL (23.6ms)  CREATE TABLE dbo.foo (bar varchar(20) NOT NULL);
# SQL (37.1ms)  DROP TABLE dbo.foo;
# -- Finishing execution of My Command at 2012-07-25 17:13:43 -0400 in 0.006583 seconds
# => [#<Threequel::ConsoleLogger:0x007ffc47f95240 @attributes={:sql=>"CREATE TABLE dbo.foo (bar varchar(20) NOT NULL);\nGO\n\nDROP TABLE dbo.foo;\nGO\n", :command=>"My Command", :statement=>nil, :name=>"My Command", :started_at=>2012-07-25 17:13:43 -0400, :finished_at=>2012-07-25 17:13:43 -0400, :duration=>0.006583, :stage=>:finished, :message=>"Command executed successfully", :status=>:success}>]

LoggingHandler

ConsoleLogger

DBLogger

DBLoggerStorage

Timer

Wrap code in a Timer.clock block and get timing information about your code block.

threequel's People

Contributors

jackross avatar blankenshipz avatar

Watchers

Kevin Falank avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.