activerecord-pickin 0.0.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -2
- data/activerecord-pickin.gemspec +1 -0
- data/lib/activerecord-pickin/relation.rb +38 -6
- data/lib/activerecord-pickin/version.rb +1 -1
- metadata +14 -3
data/README.md
CHANGED
@@ -22,9 +22,32 @@ FromClass.relation.pickin(IntoClass, {column: value or column})
|
|
22
22
|
|
23
23
|
Example:
|
24
24
|
|
25
|
-
|
25
|
+
### for over version 0.9.0
|
26
26
|
|
27
|
-
|
27
|
+
Map.where(stage_id: 1).pickin(GameMap, {game_stage_id: 24}, [:id])
|
28
|
+
|
29
|
+
INSERT INTO 'game_maps' ("id", "game_stage_id", "type", "x", "y", "created_at", "updated_at") SELECT NULL, '24', "type", "x", "y", "created_at", "updated_at" FROM "maps" WHERE "maps"."stage_id" = 1
|
30
|
+
|
31
|
+
Map.where(stage_id: 1).select([:type]).pickin(GameMap, {game_stage_id: 24}, [:id])
|
32
|
+
|
33
|
+
INSERT INTO 'game_maps' ("type") SELECT "type" FROM "maps" WHERE "maps"."stage_id" = 1
|
34
|
+
|
35
|
+
### for only version 0.0.1
|
36
|
+
|
37
|
+
Map.where(stage_id: 1).pickin(GameMap, {game_stage_id: 24, type: :type, x: :x, y: :y, created_at: :created_at, updated_at: :updated_at})
|
38
|
+
|
39
|
+
INSERT INTO 'game_maps' ("game_stage_id", "type", "x", "y", "created_at", "updated_at") SELECT 24, type, x, y, created_at, updated_at FROM "maps" WHERE "maps"."stage_id" = 1
|
40
|
+
|
41
|
+
## Change log
|
42
|
+
|
43
|
+
### version 0.9.0
|
44
|
+
|
45
|
+
* Release beta
|
46
|
+
* Specification was changed. The specified column was targeted. but now used to override the value of a column in the SELECT for.
|
47
|
+
|
48
|
+
### version 0.0.1
|
49
|
+
|
50
|
+
* Release alpha
|
28
51
|
|
29
52
|
## Contributing
|
30
53
|
|
data/activerecord-pickin.gemspec
CHANGED
@@ -2,18 +2,50 @@ require 'active_record/relation'
|
|
2
2
|
module ActiveRecord
|
3
3
|
module Pickin
|
4
4
|
module Relation
|
5
|
-
def pickin into_class,
|
5
|
+
def pickin into_class, override = {}, ignore = []
|
6
6
|
insert_arel = Arel::InsertManager.new(arel.engine)
|
7
7
|
insert_arel.into into_class.table_name
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
if self.select_values.empty?
|
10
|
+
columns = into_class.columns
|
10
11
|
else
|
11
|
-
|
12
|
+
columns = self.select_values
|
12
13
|
end
|
13
|
-
|
14
|
-
|
14
|
+
|
15
|
+
insert_arel.ast.columns = columns.map do |c|
|
16
|
+
unless c.class == Symbol
|
17
|
+
c = c.name
|
18
|
+
end
|
19
|
+
Arel::Attributes::Attribute.new(insert_arel, c)
|
20
|
+
end
|
21
|
+
|
22
|
+
select_column = self.get_select_column columns, override, ignore
|
23
|
+
self.select_values = []
|
24
|
+
select_arel = self.select(select_column)
|
15
25
|
@klass.connection.execute "#{insert_arel.to_sql} #{select_arel.to_sql}"
|
16
26
|
end
|
27
|
+
|
28
|
+
def get_select_column target, override, ignore
|
29
|
+
target.map do |c|
|
30
|
+
unless c.class == Symbol
|
31
|
+
c = c.name.to_sym
|
32
|
+
end
|
33
|
+
convert_element(c, override) unless ignore.include? c
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def convert_element column, override
|
38
|
+
if override.keys.include?(column)
|
39
|
+
if override[column].class == Symbol
|
40
|
+
@klass.connection.quote_column_name override[column]
|
41
|
+
else
|
42
|
+
"'#{override[column]}'"
|
43
|
+
end
|
44
|
+
else
|
45
|
+
@klass.connection.quote_column_name column.to_s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
17
49
|
end
|
18
50
|
end
|
19
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-pickin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: &70262068386340 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70262068386340
|
14
25
|
description: INSERT SELECT Query For ActiveRecord
|
15
26
|
email:
|
16
27
|
- info@miio.info
|