sequel-fusiontables 0.0.1

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.
@@ -0,0 +1,31 @@
1
+ Fusion Tables adapter for Sequel
2
+ ================================
3
+
4
+ Experimental adapter to use Fusion Tables in [Sequel](http://sequel.rubyforge.org).
5
+
6
+ Usage
7
+ -----
8
+
9
+ require "sequel"
10
+
11
+ db = Sequel.connect("fusiontables:///")
12
+
13
+ # In Fusion, table IDs are numbers.
14
+ table = db[579353]
15
+
16
+ puts table.select("Country", "Name").where("Active Reactors" => 0).all
17
+
18
+ # {"Country"=>"BELGIUM", "Name"=>"BR"}
19
+ # {"Country"=>"CANADA", "Name"=>"DOUGLAS POINT"}
20
+ # {"Country"=>"CANADA", "Name"=>"NPD"}
21
+ # {"Country"=>"CHINA", "Name"=>"LINGAO"}
22
+ # ...
23
+
24
+
25
+ Known issues
26
+ ------------
27
+
28
+ I just started experimenting with this so there are a few features missing:
29
+
30
+ * `CREATE TABLE`, `INSERT`, `UPDATE`, `DELETE` aren't implemented yet. Soon though.
31
+ * Typecasting.
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
@@ -0,0 +1,74 @@
1
+ require "sequel"
2
+ require "csv"
3
+ require "net/http/persistent"
4
+ require "ft"
5
+
6
+ module Sequel
7
+ module FusionTables
8
+ class Database < ::Sequel::Database
9
+ set_adapter_scheme :fusiontables
10
+
11
+ def dataset(opts = nil)
12
+ FusionTables::Dataset.new(self, opts)
13
+ end
14
+
15
+ def execute(sql, opts={}, &block)
16
+ _execute(:select, sql, opts, &block)
17
+ end
18
+
19
+ def self.uri_to_options(uri)
20
+ {:database => uri.registry}
21
+ end
22
+
23
+ def connect(server)
24
+ ::FusionTables::Connection.new
25
+ end
26
+
27
+ protected
28
+
29
+ def _execute(type, sql, opts, &block)
30
+ begin
31
+ synchronize do |conn|
32
+ log_args = opts[:arguments]
33
+ args = opts.fetch(:arguments, [])
34
+ case type
35
+ when :select
36
+ log_yield(sql, log_args) { yield(conn.query(sql)) }
37
+ end
38
+ end
39
+ rescue ::FusionTables::Error => e
40
+ raise_error(e)
41
+ end
42
+ end
43
+ end
44
+
45
+ class Dataset < ::Sequel::Dataset
46
+ def complex_expression_sql(op, args)
47
+ case op
48
+ when *TWO_ARITY_OPERATORS
49
+ "#{literal(args.at(0))} #{op} #{literal(args.at(1))}"
50
+ when *N_ARITY_OPERATORS
51
+ "#{args.collect{|a| literal(a)}.join(" #{op} ")}"
52
+ else
53
+ super
54
+ end
55
+ end
56
+
57
+ def fetch_rows(sql)
58
+ execute(sql) do |result|
59
+ @columns = result.shift
60
+
61
+ result.each do |values|
62
+ row = {}
63
+
64
+ @columns.each_with_index do |col, i|
65
+ row[col] = values[i]
66
+ end
67
+
68
+ yield(row)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "sequel-fusiontables"
3
+ s.version = "0.0.1"
4
+ s.summary = "Fusion Tables adapter for Sequel"
5
+ s.authors = ["Damian Janowski"]
6
+ s.email = ["djanowski@dimaion.com"]
7
+ s.homepage = "http://github.com/djanowski/sequel-fusiontables"
8
+
9
+ s.add_dependency("ft")
10
+
11
+ s.files = Dir[
12
+ "*.gemspec",
13
+ "*LICENSE",
14
+ "README*",
15
+ "Rakefile",
16
+ "bin/*",
17
+ "lib/**/*",
18
+ "test/**/*",
19
+ ]
20
+ end
@@ -0,0 +1,34 @@
1
+ require "cutest"
2
+ require "./lib/sequel/adapters/fusion_tables"
3
+
4
+ setup do
5
+ Sequel.connect("fusiontables:///")[1310767]
6
+ end
7
+
8
+ test "simple SELECT" do |db|
9
+ ds = db.select("Name", "Order").all
10
+
11
+ assert_equal ds[0]["Name"], "rake"
12
+ assert_equal ds[0]["Order"], "1"
13
+
14
+ assert_equal ds[1]["Name"], "rack"
15
+ assert_equal ds[1]["Order"], "2"
16
+ end
17
+
18
+ test "simple WHERE" do |db|
19
+ sql = db.select("Name", "Order").where("Name" => "rake").sql
20
+
21
+ assert_equal sql, "SELECT 'Name', 'Order' FROM 1310767 WHERE 'Name' = 'rake'"
22
+ end
23
+
24
+ test "complex WHERE" do |db|
25
+ sql = db.select("Name", "Order").where("Name" => "rake", "Order" => "1").sql
26
+
27
+ assert_equal sql, "SELECT 'Name', 'Order' FROM 1310767 WHERE 'Name' = 'rake' AND 'Order' = '1'"
28
+ end
29
+
30
+ test "Fusion Tables errors" do |db|
31
+ assert_raise(Sequel::DatabaseError) do
32
+ db.select("Foo").all
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-fusiontables
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Damian Janowski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-18 00:00:00 -03:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: ft
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description:
28
+ email:
29
+ - djanowski@dimaion.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - sequel-fusiontables.gemspec
38
+ - UNLICENSE
39
+ - README.md
40
+ - lib/sequel/adapters/fusiontables.rb
41
+ - test/sequel/adapters/fusiontables.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/djanowski/sequel-fusiontables
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.6.2
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Fusion Tables adapter for Sequel
70
+ test_files: []
71
+