rails_sql_views 0.4.0 → 0.5.0

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/CHANGELOG CHANGED
@@ -1,2 +1,6 @@
1
- 0.1.0 -
2
- * Initial release
1
+ 0.1.0 - Released Dec 27, 2006
2
+ * Initial release
3
+
4
+ 0.5.0 - Released Dec 29, 2006
5
+ * Added support for PostgreSQL
6
+ * Fixed the schema dumper
data/README CHANGED
@@ -1,6 +1,6 @@
1
1
  == Rails SQL Views
2
2
 
3
- Library which adds SQL Views to Rails. Adds create_view and drop_view to the ActiveRecord::ConnectionAdapters::AbstractAdapter.
3
+ Library which adds SQL Views to Rails. Adds create_view and drop_view to the ActiveRecord::ConnectionAdapters::AbstractAdapter (which makes them available to migrations) and adds support for dumping views in the ActiveRecord::SchemaDumper.
4
4
 
5
5
  == Installation
6
6
 
@@ -31,11 +31,16 @@ You can then use create_view and drop_view in your migrations. For example:
31
31
  end
32
32
  end
33
33
 
34
- This extension also adds support for views in the ActiveRecord::SchemaDumper class, however currently only MySQL is supported.
34
+ This extension also adds support for views in the ActiveRecord::SchemaDumper class.
35
+
36
+ The following drivers are supported:
37
+
38
+ MySQL
39
+ PostgreSQL (Native and Pure Ruby)
35
40
 
36
41
  == Known Issues
37
42
 
38
- * None
43
+ * Drivers not mentioned above are not supported.
39
44
 
40
45
  If you find any issues please send an email to anthonyeden@gmail.com .
41
46
 
@@ -39,6 +39,7 @@ require 'core_ext/module'
39
39
  require 'rails_sql_views/connection_adapters/abstract/schema_definitions'
40
40
  require 'rails_sql_views/connection_adapters/abstract/schema_statements'
41
41
  require 'rails_sql_views/connection_adapters/mysql_adapter'
42
+ require 'rails_sql_views/connection_adapters/postgresql_adapter'
42
43
  require 'rails_sql_views/schema_dumper'
43
44
 
44
45
  class ActiveRecord::ConnectionAdapters::AbstractAdapter
@@ -7,9 +7,14 @@ module ActiveRecord
7
7
  end
8
8
 
9
9
  # Get a list of all views for the current database
10
- def views(name = nil) #:nodoc:
10
+ def views(name = nil)
11
11
  raise NotImplementedError, "views is an abstract method"
12
12
  end
13
+
14
+ # Get the select statement for the specified view
15
+ def view_select_statement(view, name=nil)
16
+ raise NotImplementedError, "view_select_statement is an abstract method"
17
+ end
13
18
  end
14
19
  end
15
20
  end
@@ -0,0 +1,39 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ class PostgreSQLAdapter
4
+ # Returns true as this adapter supports views.
5
+ def supports_views?
6
+ true
7
+ end
8
+
9
+ def views(name = nil) #:nodoc:
10
+ q = <<-SQL
11
+ SELECT table_name, table_type
12
+ FROM information_schema.tables
13
+ WHERE table_schema IN (#{schemas})
14
+ AND table_type = 'VIEW'
15
+ SQL
16
+
17
+ query(q, name).map { |row| row[0] }
18
+ end
19
+
20
+ def view_select_statement(view, name = nil)
21
+ q = <<-SQL
22
+ SELECT view_definition
23
+ FROM information_schema.views
24
+ WHERE table_catalog = (SELECT catalog_name FROM information_schema.information_schema_catalog_name)
25
+ AND table_schema IN (#{schemas})
26
+ AND table_name = '#{view}'
27
+ SQL
28
+
29
+ select_value(q, name) or raise "No view called #{view} found"
30
+ end
31
+
32
+ private
33
+
34
+ def schemas
35
+ schema_search_path.split(/,/).map { |p| quote(p) }.join(',')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -15,8 +15,12 @@ module ActiveRecord
15
15
  # Add views to the end of the dump stream
16
16
  def dump_with_views(stream)
17
17
  dump_without_views(stream)
18
- if @connection.supports_views?
19
- views(stream)
18
+ begin
19
+ if @connection.supports_views?
20
+ views(stream)
21
+ end
22
+ rescue => e
23
+ ActiveRecord::Base.logger.error "Unable to dump views: #{e}"
20
24
  end
21
25
  trailer_without_views(stream)
22
26
  stream
@@ -1,7 +1,7 @@
1
1
  module RailsSqlViews
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 4
4
+ MINOR = 5
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rails_sql_views
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.0
7
- date: 2006-12-28 00:00:00 -05:00
6
+ version: 0.5.0
7
+ date: 2006-12-29 00:00:00 -05:00
8
8
  summary: Adds SQL Views to Rails.
9
9
  require_paths:
10
10
  - lib
@@ -42,6 +42,7 @@ files:
42
42
  - lib/rails_sql_views/connection_adapters/abstract
43
43
  - lib/rails_sql_views/connection_adapters/abstract_adapter.rb
44
44
  - lib/rails_sql_views/connection_adapters/mysql_adapter.rb
45
+ - lib/rails_sql_views/connection_adapters/postgresql_adapter.rb
45
46
  - lib/rails_sql_views/connection_adapters/abstract/schema_definitions.rb
46
47
  - lib/rails_sql_views/connection_adapters/abstract/schema_statements.rb
47
48
  test_files: []