sequel 0.5.0.2 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +18 -18
- data/Rakefile +17 -98
- data/lib/sequel.rb +2 -71
- metadata +10 -108
- data/CHANGELOG +0 -989
- data/bin/sequel +0 -41
- data/lib/sequel/adapters/adapter_skeleton.rb +0 -68
- data/lib/sequel/adapters/ado.rb +0 -100
- data/lib/sequel/adapters/db2.rb +0 -158
- data/lib/sequel/adapters/dbi.rb +0 -126
- data/lib/sequel/adapters/informix.rb +0 -87
- data/lib/sequel/adapters/jdbc.rb +0 -108
- data/lib/sequel/adapters/mysql.rb +0 -269
- data/lib/sequel/adapters/odbc.rb +0 -145
- data/lib/sequel/adapters/odbc_mssql.rb +0 -93
- data/lib/sequel/adapters/openbase.rb +0 -90
- data/lib/sequel/adapters/oracle.rb +0 -99
- data/lib/sequel/adapters/postgres.rb +0 -519
- data/lib/sequel/adapters/sqlite.rb +0 -192
- data/lib/sequel/ado.rb +0 -6
- data/lib/sequel/array_keys.rb +0 -296
- data/lib/sequel/connection_pool.rb +0 -152
- data/lib/sequel/core_ext.rb +0 -59
- data/lib/sequel/core_sql.rb +0 -191
- data/lib/sequel/database.rb +0 -433
- data/lib/sequel/dataset.rb +0 -409
- data/lib/sequel/dataset/convenience.rb +0 -321
- data/lib/sequel/dataset/sequelizer.rb +0 -354
- data/lib/sequel/dataset/sql.rb +0 -586
- data/lib/sequel/db2.rb +0 -6
- data/lib/sequel/dbi.rb +0 -6
- data/lib/sequel/exceptions.rb +0 -45
- data/lib/sequel/informix.rb +0 -6
- data/lib/sequel/migration.rb +0 -191
- data/lib/sequel/model.rb +0 -8
- data/lib/sequel/mysql.rb +0 -6
- data/lib/sequel/odbc.rb +0 -6
- data/lib/sequel/oracle.rb +0 -6
- data/lib/sequel/postgres.rb +0 -6
- data/lib/sequel/pretty_table.rb +0 -73
- data/lib/sequel/schema.rb +0 -8
- data/lib/sequel/schema/schema_generator.rb +0 -131
- data/lib/sequel/schema/schema_sql.rb +0 -131
- data/lib/sequel/sqlite.rb +0 -6
- data/lib/sequel/worker.rb +0 -58
- data/spec/adapters/informix_spec.rb +0 -139
- data/spec/adapters/mysql_spec.rb +0 -330
- data/spec/adapters/oracle_spec.rb +0 -130
- data/spec/adapters/postgres_spec.rb +0 -189
- data/spec/adapters/sqlite_spec.rb +0 -345
- data/spec/array_keys_spec.rb +0 -679
- data/spec/connection_pool_spec.rb +0 -356
- data/spec/core_ext_spec.rb +0 -67
- data/spec/core_sql_spec.rb +0 -301
- data/spec/database_spec.rb +0 -811
- data/spec/dataset_spec.rb +0 -2381
- data/spec/migration_spec.rb +0 -261
- data/spec/pretty_table_spec.rb +0 -66
- data/spec/rcov.opts +0 -4
- data/spec/schema_generator_spec.rb +0 -86
- data/spec/schema_spec.rb +0 -230
- data/spec/sequel_spec.rb +0 -10
- data/spec/sequelizer_spec.rb +0 -389
- data/spec/spec.opts +0 -5
- data/spec/spec_helper.rb +0 -44
- data/spec/worker_spec.rb +0 -96
data/bin/sequel
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'sequel'
|
5
|
-
|
6
|
-
usage = <<END
|
7
|
-
Usage: sequel <connection URI>
|
8
|
-
Sequel: Lightweight ORM library for Ruby
|
9
|
-
|
10
|
-
Examples:
|
11
|
-
sequel sqlite:///blog.db
|
12
|
-
sequel postgres://localhost/my_blog
|
13
|
-
|
14
|
-
For more information see http://code.google.com/p/ruby-sequel
|
15
|
-
END
|
16
|
-
|
17
|
-
db = ARGV.shift
|
18
|
-
|
19
|
-
if db.nil? || db.empty?
|
20
|
-
puts usage
|
21
|
-
exit
|
22
|
-
end
|
23
|
-
|
24
|
-
begin
|
25
|
-
DB = Sequel.connect db
|
26
|
-
rescue => e
|
27
|
-
puts e.message
|
28
|
-
exit
|
29
|
-
end
|
30
|
-
|
31
|
-
begin
|
32
|
-
DB.test_connection
|
33
|
-
rescue => e
|
34
|
-
puts e.message
|
35
|
-
puts e.backtrace.first
|
36
|
-
exit
|
37
|
-
end
|
38
|
-
|
39
|
-
require 'irb'
|
40
|
-
puts "Your database is stored in DB..."
|
41
|
-
IRB.start
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# require 'adapter_lib'
|
2
|
-
|
3
|
-
module Sequel
|
4
|
-
module Adapter
|
5
|
-
class Database < Sequel::Database
|
6
|
-
set_adapter_scheme :adapter
|
7
|
-
|
8
|
-
def connect
|
9
|
-
AdapterDB.new(@opts[:database], @opts[:user], @opts[:password])
|
10
|
-
end
|
11
|
-
|
12
|
-
def disconnect
|
13
|
-
@pool.disconnect {|c| c.disconnect}
|
14
|
-
end
|
15
|
-
|
16
|
-
def dataset(opts = nil)
|
17
|
-
Adapter::Dataset.new(self, opts)
|
18
|
-
end
|
19
|
-
|
20
|
-
def execute(sql)
|
21
|
-
@logger.info(sql) if @logger
|
22
|
-
@pool.hold {|conn| conn.exec(sql)}
|
23
|
-
end
|
24
|
-
|
25
|
-
alias_method :do, :execute
|
26
|
-
end
|
27
|
-
|
28
|
-
class Dataset < Sequel::Dataset
|
29
|
-
def literal(v)
|
30
|
-
case v
|
31
|
-
when Time
|
32
|
-
literal(v.iso8601)
|
33
|
-
else
|
34
|
-
super
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def fetch_rows(sql, &block)
|
39
|
-
@db.synchronize do
|
40
|
-
cursor = @db.execute sql
|
41
|
-
begin
|
42
|
-
@columns = cursor.get_col_names.map {|c| c.to_sym}
|
43
|
-
while r = cursor.fetch
|
44
|
-
row = {}
|
45
|
-
r.each_with_index {|v, i| row[@columns[i]] = v}
|
46
|
-
yield row
|
47
|
-
end
|
48
|
-
ensure
|
49
|
-
cursor.close
|
50
|
-
end
|
51
|
-
end
|
52
|
-
self
|
53
|
-
end
|
54
|
-
|
55
|
-
def insert(*values)
|
56
|
-
@db.do insert_sql(*values)
|
57
|
-
end
|
58
|
-
|
59
|
-
def update(*args, &block)
|
60
|
-
@db.do update_sql(*args, &block)
|
61
|
-
end
|
62
|
-
|
63
|
-
def delete(opts = nil)
|
64
|
-
@db.do delete_sql(opts)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
data/lib/sequel/adapters/ado.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'win32ole'
|
2
|
-
|
3
|
-
module Sequel
|
4
|
-
# The ADO adapter provides connectivity to ADO databases in Windows. ADO
|
5
|
-
# databases can be opened using a URL with the ado schema:
|
6
|
-
#
|
7
|
-
# DB = Sequel.open('ado://mydb')
|
8
|
-
#
|
9
|
-
# or using the Sequel.ado method:
|
10
|
-
#
|
11
|
-
# DB = Sequel.ado('mydb')
|
12
|
-
#
|
13
|
-
module ADO
|
14
|
-
class Database < Sequel::Database
|
15
|
-
set_adapter_scheme :ado
|
16
|
-
|
17
|
-
AUTO_INCREMENT = 'IDENTITY(1,1)'.freeze
|
18
|
-
|
19
|
-
def auto_increment_sql
|
20
|
-
AUTO_INCREMENT
|
21
|
-
end
|
22
|
-
|
23
|
-
def connect
|
24
|
-
dbname = @opts[:database]
|
25
|
-
handle = WIN32OLE.new('ADODB.Connection')
|
26
|
-
handle.Open(dbname)
|
27
|
-
handle
|
28
|
-
end
|
29
|
-
|
30
|
-
def disconnect
|
31
|
-
# how do we disconnect? couldn't find anything in the docs
|
32
|
-
end
|
33
|
-
|
34
|
-
def dataset(opts = nil)
|
35
|
-
ADO::Dataset.new(self, opts)
|
36
|
-
end
|
37
|
-
|
38
|
-
def execute(sql)
|
39
|
-
@logger.info(sql) if @logger
|
40
|
-
@pool.hold {|conn| conn.Execute(sql)}
|
41
|
-
end
|
42
|
-
|
43
|
-
alias_method :do, :execute
|
44
|
-
end
|
45
|
-
|
46
|
-
class Dataset < Sequel::Dataset
|
47
|
-
def literal(v)
|
48
|
-
case v
|
49
|
-
when Time
|
50
|
-
literal(v.iso8601)
|
51
|
-
else
|
52
|
-
super
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def fetch_rows(sql, &block)
|
57
|
-
@db.synchronize do
|
58
|
-
s = @db.execute sql
|
59
|
-
|
60
|
-
@columns = s.Fields.extend(Enumerable).map {|x| x.Name.to_sym}
|
61
|
-
|
62
|
-
s.moveFirst
|
63
|
-
s.getRows.transpose.each {|r| yield hash_row(r)}
|
64
|
-
end
|
65
|
-
self
|
66
|
-
end
|
67
|
-
|
68
|
-
def hash_row(row)
|
69
|
-
@columns.inject({}) do |m, c|
|
70
|
-
m[c] = row.shift
|
71
|
-
m
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def array_tuples_fetch_rows(sql, &block)
|
76
|
-
@db.synchronize do
|
77
|
-
s = @db.execute sql
|
78
|
-
|
79
|
-
@columns = s.Fields.extend(Enumerable).map {|x| x.Name.to_sym}
|
80
|
-
|
81
|
-
s.moveFirst
|
82
|
-
s.getRows.transpose.each {|r| r.keys = @columns; yield r}
|
83
|
-
end
|
84
|
-
self
|
85
|
-
end
|
86
|
-
|
87
|
-
def insert(*values)
|
88
|
-
@db.do insert_sql(*values)
|
89
|
-
end
|
90
|
-
|
91
|
-
def update(*args, &block)
|
92
|
-
@db.do update_sql(*args, &block)
|
93
|
-
end
|
94
|
-
|
95
|
-
def delete(opts = nil)
|
96
|
-
@db.do delete_sql(opts)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
data/lib/sequel/adapters/db2.rb
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
require 'db2/db2cli'
|
2
|
-
|
3
|
-
module Sequel
|
4
|
-
module DB2
|
5
|
-
class Database < Sequel::Database
|
6
|
-
set_adapter_scheme :db2
|
7
|
-
include DB2CLI
|
8
|
-
|
9
|
-
# AUTO_INCREMENT = 'IDENTITY(1,1)'.freeze
|
10
|
-
#
|
11
|
-
# def auto_increment_sql
|
12
|
-
# AUTO_INCREMENT
|
13
|
-
# end
|
14
|
-
|
15
|
-
def check_error(rc, msg)
|
16
|
-
case rc
|
17
|
-
when SQL_SUCCESS, SQL_SUCCESS_WITH_INFO
|
18
|
-
nil
|
19
|
-
else
|
20
|
-
raise Error, msg
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
rc, @@env = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE)
|
25
|
-
check_error(rc, "Could not allocate DB2 environment")
|
26
|
-
|
27
|
-
def connect
|
28
|
-
rc, dbc = SQLAllocHandle(SQL_HANDLE_DBC, @@env)
|
29
|
-
check_error(rc, "Could not allocate database connection")
|
30
|
-
|
31
|
-
rc = SQLConnect(dbc, @opts[:database], @opts[:user], @opts[:password])
|
32
|
-
check_error(rc, "Could not connect to database")
|
33
|
-
|
34
|
-
dbc
|
35
|
-
end
|
36
|
-
|
37
|
-
def disconnect
|
38
|
-
@pool.disconnect do |conn|
|
39
|
-
rc = SQLDisconnect(conn)
|
40
|
-
check_error(rc, "Could not disconnect from database")
|
41
|
-
|
42
|
-
rc = SQLFreeHandle(SQL_HANDLE_DBC, conn)
|
43
|
-
check_error(rc, "Could not free Database handle")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_connection
|
48
|
-
@pool.hold {|conn|}
|
49
|
-
true
|
50
|
-
end
|
51
|
-
|
52
|
-
def dataset(opts = nil)
|
53
|
-
DB2::Dataset.new(self, opts)
|
54
|
-
end
|
55
|
-
|
56
|
-
def execute(sql, &block)
|
57
|
-
@logger.info(sql) if @logger
|
58
|
-
@pool.hold do |conn|
|
59
|
-
rc, sth = SQLAllocHandle(SQL_HANDLE_STMT, @handle)
|
60
|
-
check_error(rc, "Could not allocate statement")
|
61
|
-
|
62
|
-
begin
|
63
|
-
rc = SQLExecDirect(sth, sql)
|
64
|
-
check_error(rc, "Could not execute statement")
|
65
|
-
|
66
|
-
block[sth] if block
|
67
|
-
|
68
|
-
rc, rpc = SQLRowCount(sth)
|
69
|
-
check_error(rc, "Could not get RPC")
|
70
|
-
rpc
|
71
|
-
ensure
|
72
|
-
rc = SQLFreeHandle(SQL_HANDLE_STMT, sth)
|
73
|
-
check_error(rc, "Could not free statement")
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
alias_method :do, :execute
|
78
|
-
end
|
79
|
-
|
80
|
-
class Dataset < Sequel::Dataset
|
81
|
-
def literal(v)
|
82
|
-
case v
|
83
|
-
when Time
|
84
|
-
literal(v.iso8601)
|
85
|
-
else
|
86
|
-
super
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def fetch_rows(sql, &block)
|
91
|
-
@db.synchronize do
|
92
|
-
@db.execute(sql) do |sth|
|
93
|
-
@column_info = get_column_info(sth)
|
94
|
-
@columns = @column_info.map {|c| c[:name]}
|
95
|
-
while (rc = SQLFetch(@handle)) != SQL_NO_DATA_FOUND
|
96
|
-
@db.check_error(rc, "Could not fetch row")
|
97
|
-
yield hash_row(sth)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
self
|
102
|
-
end
|
103
|
-
|
104
|
-
MAX_COL_SIZE = 256
|
105
|
-
|
106
|
-
def get_column_info(sth)
|
107
|
-
rc, column_count = SQLNumResultCols(sth)
|
108
|
-
@db.check_error(rc, "Could not get number of result columns")
|
109
|
-
|
110
|
-
(1..column_count).map do |i|
|
111
|
-
rc, name, buflen, datatype, size, digits, nullable = SQLDescribeCol(sth, i, MAX_COL_SIZE)
|
112
|
-
@b.check_error(rc, "Could not describe column")
|
113
|
-
|
114
|
-
{:name => name, :db2_type => datatype, :precision => size}
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def hash_row(sth)
|
119
|
-
row = {}
|
120
|
-
@column_info.each_with_index do |c, i|
|
121
|
-
rc, v = SQLGetData(sth, i+1, c[:db2_type], c[:precision])
|
122
|
-
@db.check_error(rc, "Could not get data")
|
123
|
-
|
124
|
-
@row[c[:name]] = convert_type(v)
|
125
|
-
end
|
126
|
-
row
|
127
|
-
end
|
128
|
-
|
129
|
-
def convert_type(v)
|
130
|
-
case v
|
131
|
-
when DB2CLI::Date
|
132
|
-
DBI::Date.new(v.year, v.month, v.day)
|
133
|
-
when DB2CLI::Time
|
134
|
-
DBI::Time.new(v.hour, v.minute, v.second)
|
135
|
-
when DB2CLI::Timestamp
|
136
|
-
DBI::Timestamp.new(v.year, v.month, v.day,
|
137
|
-
v.hour, v.minute, v.second, v.fraction)
|
138
|
-
when DB2CLI::Null
|
139
|
-
nil
|
140
|
-
else
|
141
|
-
v
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def insert(*values)
|
146
|
-
@db.do insert_sql(*values)
|
147
|
-
end
|
148
|
-
|
149
|
-
def update(*args, &block)
|
150
|
-
@db.do update_sql(*args, &block)
|
151
|
-
end
|
152
|
-
|
153
|
-
def delete(opts = nil)
|
154
|
-
@db.do delete_sql(opts)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
data/lib/sequel/adapters/dbi.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'dbi'
|
2
|
-
|
3
|
-
module Sequel
|
4
|
-
module DBI
|
5
|
-
class Database < Sequel::Database
|
6
|
-
set_adapter_scheme :dbi
|
7
|
-
|
8
|
-
DBI_ADAPTERS = {
|
9
|
-
:ado => "ADO",
|
10
|
-
:db2 => "DB2",
|
11
|
-
:frontbase => "FrontBase",
|
12
|
-
:interbase => "InterBase",
|
13
|
-
:msql => "Msql",
|
14
|
-
:mysql => "Mysql",
|
15
|
-
:odbc => "ODBC",
|
16
|
-
:oracle => "Oracle",
|
17
|
-
:pg => "Pg",
|
18
|
-
:proxy => "Proxy",
|
19
|
-
:sqlite => "SQLite",
|
20
|
-
:sqlrelay => "SQLRelay"
|
21
|
-
}
|
22
|
-
|
23
|
-
# Converts a uri to an options hash. These options are then passed
|
24
|
-
# to a newly created database object.
|
25
|
-
def self.uri_to_options(uri)
|
26
|
-
database = (uri.path =~ /\/(.*)/) && ($1)
|
27
|
-
if uri.scheme =~ /dbi-(.+)/
|
28
|
-
adapter = DBI_ADAPTERS[$1.to_sym] || $1
|
29
|
-
database = "#{adapter}:#{database}"
|
30
|
-
end
|
31
|
-
{
|
32
|
-
:user => uri.user,
|
33
|
-
:password => uri.password,
|
34
|
-
:host => uri.host,
|
35
|
-
:port => uri.port,
|
36
|
-
:database => database
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
def connect
|
42
|
-
dbname = @opts[:database]
|
43
|
-
dbname = 'DBI:' + dbname unless dbname =~ /^DBI:/
|
44
|
-
::DBI.connect(dbname, @opts[:user], @opts[:password])
|
45
|
-
end
|
46
|
-
|
47
|
-
def disconnect
|
48
|
-
@pool.disconnect {|c| c.disconnect}
|
49
|
-
end
|
50
|
-
|
51
|
-
def dataset(opts = nil)
|
52
|
-
DBI::Dataset.new(self, opts)
|
53
|
-
end
|
54
|
-
|
55
|
-
def execute(sql)
|
56
|
-
@logger.info(sql) if @logger
|
57
|
-
@pool.hold do |conn|
|
58
|
-
conn.execute(sql)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def do(sql)
|
63
|
-
@logger.info(sql) if @logger
|
64
|
-
@pool.hold do |conn|
|
65
|
-
conn.do(sql)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class Dataset < Sequel::Dataset
|
71
|
-
def literal(v)
|
72
|
-
case v
|
73
|
-
when Time
|
74
|
-
literal(v.iso8601)
|
75
|
-
else
|
76
|
-
super
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def fetch_rows(sql, &block)
|
81
|
-
@db.synchronize do
|
82
|
-
s = @db.execute sql
|
83
|
-
begin
|
84
|
-
@columns = s.column_names.map {|c| c.to_sym}
|
85
|
-
s.fetch {|r| yield hash_row(s, r)}
|
86
|
-
ensure
|
87
|
-
s.finish rescue nil
|
88
|
-
end
|
89
|
-
end
|
90
|
-
self
|
91
|
-
end
|
92
|
-
|
93
|
-
def array_tuples_fetch_rows(sql, &block)
|
94
|
-
@db.synchronize do
|
95
|
-
s = @db.execute sql
|
96
|
-
begin
|
97
|
-
@columns = s.column_names.map {|c| c.to_sym}
|
98
|
-
s.fetch {|r| r.keys = @columns; yield r}
|
99
|
-
ensure
|
100
|
-
s.finish rescue nil
|
101
|
-
end
|
102
|
-
end
|
103
|
-
self
|
104
|
-
end
|
105
|
-
|
106
|
-
def hash_row(stmt, row)
|
107
|
-
@columns.inject({}) do |m, c|
|
108
|
-
m[c] = row.shift
|
109
|
-
m
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def insert(*values)
|
114
|
-
@db.do insert_sql(*values)
|
115
|
-
end
|
116
|
-
|
117
|
-
def update(*args, &block)
|
118
|
-
@db.do update_sql(*args, &block)
|
119
|
-
end
|
120
|
-
|
121
|
-
def delete(opts = nil)
|
122
|
-
@db.do delete_sql(opts)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|