squirm 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -4
- data/lib/squirm.rb +3 -1
- data/lib/squirm/rails.rb +54 -0
- data/lib/squirm/rails/generator.rb +11 -0
- data/lib/squirm/rails/squirm.rake +8 -0
- data/lib/squirm/rails/stored_procedures.sql +11 -0
- data/lib/squirm/rails/unit_test.rb +10 -0
- data/lib/squirm/version.rb +1 -1
- metadata +11 -6
data/README.md
CHANGED
@@ -48,11 +48,16 @@ compatible ORM based on stored procedures.
|
|
48
48
|
|
49
49
|
## Using it with Rails
|
50
50
|
|
51
|
-
Squirm
|
52
|
-
to do is pass in the pool to `Squirm.connect`:
|
51
|
+
Squirm comes with built-in support to make it work seamlessly with Active Record:
|
53
52
|
|
54
|
-
|
55
|
-
|
53
|
+
class Person < ActiveRecord::Base
|
54
|
+
procedure :say_hello
|
55
|
+
end
|
56
|
+
|
57
|
+
p = Person.find(23)
|
58
|
+
p.say_hello
|
59
|
+
|
60
|
+
More documentation coming soon.
|
56
61
|
|
57
62
|
## Author
|
58
63
|
|
data/lib/squirm.rb
CHANGED
data/lib/squirm/rails.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Squirm
|
2
|
+
|
3
|
+
# Support for working with procedures inside Active Record models. This exists
|
4
|
+
# primarily to ensure that stored procedure calls are done inside the same
|
5
|
+
# connection used by the AR model, to avoid transaction opacity issues that
|
6
|
+
# could arise if AR and Squirm are used different connections.
|
7
|
+
module ActiveRecord
|
8
|
+
class Procedure < ::Squirm::Procedure
|
9
|
+
attr_accessor :connector
|
10
|
+
|
11
|
+
def call(*args, &block)
|
12
|
+
Squirm.use(connector.call) do
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.included(model_class)
|
19
|
+
model_class.extend ClassMethods
|
20
|
+
end
|
21
|
+
|
22
|
+
module ClassMethods
|
23
|
+
def procedure(name, options = {}, &block)
|
24
|
+
self.class_eval(<<-EOM, __FILE__, __LINE__ + 1)
|
25
|
+
@@__squirm ||= {}
|
26
|
+
@@__squirm[:#{name}] = Squirm::ActiveRecord::Procedure.new("#{name}")
|
27
|
+
@@__squirm[:#{name}].connector = ->{connection}
|
28
|
+
@@__squirm[:#{name}].load
|
29
|
+
def #{options[:as] or name}(options = {})
|
30
|
+
options[:id] ||= id if @@__squirm[:#{name}].arguments.hash.has_key?(:id)
|
31
|
+
@@__squirm[:#{name}].call(options)
|
32
|
+
end
|
33
|
+
EOM
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Railtie < Rails::Railtie
|
39
|
+
initializer "squirm.setup" do
|
40
|
+
Squirm.connect pool: ::ActiveRecord::Base.connection_pool
|
41
|
+
::ActiveRecord::Base.send :include, Squirm::ActiveRecord
|
42
|
+
end
|
43
|
+
|
44
|
+
rake_tasks do
|
45
|
+
load File.expand_path("../rails/squirm.rake", __FILE__)
|
46
|
+
end
|
47
|
+
|
48
|
+
generators do
|
49
|
+
require File.expand_path("../rails/generator", __FILE__)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module Squirm
|
4
|
+
class Install < ::Rails::Generators::Base
|
5
|
+
source_root File.dirname(__FILE__)
|
6
|
+
def install_functions
|
7
|
+
copy_file "stored_procedures.sql", "db/stored_procedures.sql"
|
8
|
+
copy_file "unit_test.rb", "test/unit/stored_procedures_test.rb"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/*
|
2
|
+
This is the stored_procedures.sql file used by Squirm. Define your Postgres
|
3
|
+
stored procedures in this file and they will be loaded at the end of any calls
|
4
|
+
to the db:schema:load Rake task.
|
5
|
+
*/
|
6
|
+
|
7
|
+
CREATE OR REPLACE FUNCTION hello_world() RETURNS TEXT AS $$
|
8
|
+
BEGIN
|
9
|
+
RETURN 'hello world!';
|
10
|
+
END;
|
11
|
+
$$ LANGUAGE 'PLPGSQL'
|
data/lib/squirm/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squirm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &70228168578720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70228168578720
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: pg
|
27
|
-
requirement: &
|
27
|
+
requirement: &70228168571760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 0.11.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70228168571760
|
36
36
|
description: ! '"Squirm is an anti-ORM for database-loving programmers"'
|
37
37
|
email:
|
38
38
|
- norman@njclarke.com
|
@@ -50,6 +50,11 @@ files:
|
|
50
50
|
- lib/squirm/pool.rb
|
51
51
|
- lib/squirm/procedure.rb
|
52
52
|
- lib/squirm/procedure.sql
|
53
|
+
- lib/squirm/rails.rb
|
54
|
+
- lib/squirm/rails/generator.rb
|
55
|
+
- lib/squirm/rails/squirm.rake
|
56
|
+
- lib/squirm/rails/stored_procedures.sql
|
57
|
+
- lib/squirm/rails/unit_test.rb
|
53
58
|
- lib/squirm/version.rb
|
54
59
|
- spec/core_spec.rb
|
55
60
|
- spec/helper.rb
|