sequel 0.0.5 → 0.0.6
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 +14 -0
- data/README +3 -3
- data/Rakefile +3 -3
- data/lib/sequel/database.rb +33 -1
- data/lib/sequel/dataset.rb +20 -8
- data/lib/sequel/postgres.rb +0 -4
- data/lib/sequel/schema.rb +11 -3
- data/lib/sequel/sqlite.rb +3 -1
- metadata +4 -5
data/CHANGELOG
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
*0.0.6*
|
2
|
+
|
3
|
+
* Added Dataset#sql as alias to Dataset#select_sql.
|
4
|
+
|
5
|
+
* Dataset#where and Dataset#exclude can now be used for refining dataset conditions, enabling stuff like posts.where(:title => 'abcdef').exclude(:user_id => 3).
|
6
|
+
|
7
|
+
* Implemented Dataset#exclude method.
|
8
|
+
|
9
|
+
* Added Sequel::Schema#auto_primary_key method for setting an automatic primary key to be added to every table definition. Changed the schema generator to not define a primary key by default.
|
10
|
+
|
11
|
+
* Changed Sequel::Database#table_exists? to rely on the tables method if it is available.
|
12
|
+
|
13
|
+
* Implemented SQLite::Database#tables.
|
14
|
+
|
1
15
|
*0.0.5*
|
2
16
|
|
3
17
|
* Added Dataset#[] method. Refactored Model#find and Model#[].
|
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
==
|
1
|
+
== Sequel: Concise ORM for Ruby
|
2
2
|
|
3
3
|
Sequel is an ORM framework for Ruby. Sequel provides thread safety, connection pooling, and a concise DSL for constructing queries and table schemas.
|
4
4
|
|
@@ -51,11 +51,11 @@ Note: you don't need to require 'sequel' separately before that, as each adapter
|
|
51
51
|
|
52
52
|
There are two ways to create a connection to a database. The easier way is to provide a connection URL:
|
53
53
|
|
54
|
-
DB = Sequel.
|
54
|
+
DB = Sequel.open("sqlite:///blog.db")
|
55
55
|
|
56
56
|
You can also specify optional parameters, such as the connection pool size:
|
57
57
|
|
58
|
-
DB = Sequel.
|
58
|
+
DB = Sequel.open("postgres://postgres:postgres@localhost/my_db",
|
59
59
|
:max_connections => 10)
|
60
60
|
|
61
61
|
The second, more verbose, way is to create an instance of a database class:
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'fileutils'
|
|
6
6
|
include FileUtils
|
7
7
|
|
8
8
|
NAME = "sequel"
|
9
|
-
VERS = "0.0.
|
9
|
+
VERS = "0.0.6"
|
10
10
|
CLEAN.include ['**/.*.sw?', 'pkg/*', '.config', 'doc/*', 'coverage/*']
|
11
11
|
RDOC_OPTS = ['--quiet', '--title', "Sequel: Concise ORM for Ruby",
|
12
12
|
"--opname", "index.html",
|
@@ -24,7 +24,7 @@ Rake::RDocTask.new do |rdoc|
|
|
24
24
|
rdoc.rdoc_dir = 'doc/rdoc'
|
25
25
|
rdoc.options += RDOC_OPTS
|
26
26
|
rdoc.main = "README"
|
27
|
-
rdoc.title = "Sequel
|
27
|
+
rdoc.title = "Sequel: Concise ORM for Ruby"
|
28
28
|
rdoc.rdoc_files.add ['README', 'COPYING', 'lib/sequel.rb', 'lib/sequel/**/*.rb']
|
29
29
|
end
|
30
30
|
|
@@ -36,7 +36,7 @@ spec = Gem::Specification.new do |s|
|
|
36
36
|
s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
|
37
37
|
s.rdoc_options += RDOC_OPTS +
|
38
38
|
['--exclude', '^(examples|extras)\/', '--exclude', 'lib/sequel.rb']
|
39
|
-
s.summary = "ORM
|
39
|
+
s.summary = "Concise ORM for Ruby."
|
40
40
|
s.description = s.summary
|
41
41
|
s.author = "Sharon Rosner"
|
42
42
|
s.email = 'ciconia@gmail.com'
|
data/lib/sequel/database.rb
CHANGED
@@ -93,11 +93,43 @@ module Sequel
|
|
93
93
|
# Performs a brute-force check for the existance of a table. This method is
|
94
94
|
# usually overriden in descendants.
|
95
95
|
def table_exists?(name)
|
96
|
-
|
96
|
+
if respond_to?(:tables)
|
97
|
+
tables.include?(name.to_sym)
|
98
|
+
else
|
99
|
+
from(name).first && true
|
100
|
+
end
|
97
101
|
rescue
|
98
102
|
false
|
99
103
|
end
|
100
104
|
|
105
|
+
SQL_BEGIN = 'BEGIN'.freeze
|
106
|
+
SQL_COMMIT = 'COMMIT'.freeze
|
107
|
+
SQL_ROLLBACK = 'ROLLBACK'.freeze
|
108
|
+
|
109
|
+
def transaction
|
110
|
+
@pool.hold do |conn|
|
111
|
+
@transactions ||= []
|
112
|
+
if @transactions.include? Thread.current
|
113
|
+
return yield(conn)
|
114
|
+
end
|
115
|
+
# ServerSide.info('BEGIN')
|
116
|
+
conn.execute(SQL_BEGIN)
|
117
|
+
begin
|
118
|
+
@transactions << Thread.current
|
119
|
+
result = yield(conn)
|
120
|
+
# ServerSide.info('COMMIT')
|
121
|
+
conn.execute(SQL_COMMIT)
|
122
|
+
result
|
123
|
+
rescue => e
|
124
|
+
# ServerSide.info('ROLLBACK')
|
125
|
+
conn.execute(SQL_ROLLBACK)
|
126
|
+
raise e
|
127
|
+
ensure
|
128
|
+
@transactions.delete(Thread.current)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
101
133
|
@@adapters = Hash.new
|
102
134
|
|
103
135
|
# Sets the adapter scheme for the database class. Call this method in
|
data/lib/sequel/dataset.rb
CHANGED
@@ -178,15 +178,26 @@ module Sequel
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
|
181
|
+
AND_WHERE = "%s AND %s".freeze
|
182
|
+
|
181
183
|
# Returns a copy of the dataset with the where conditions changed.
|
182
|
-
def where(*
|
183
|
-
if
|
184
|
-
|
185
|
-
if @opts[:where]
|
186
|
-
|
184
|
+
def where(*cond)
|
185
|
+
cond = cond.first if cond.size == 1
|
186
|
+
if @opts[:where]
|
187
|
+
if @opts[:where].is_a?(Hash) && cond.is_a?(Hash)
|
188
|
+
cond = @opts[:where].merge(cond)
|
189
|
+
else
|
190
|
+
cond = AND_WHERE % [where_list(@opts[:where]), where_list(cond)]
|
187
191
|
end
|
188
192
|
end
|
189
|
-
dup_merge(:where =>
|
193
|
+
dup_merge(:where => cond)
|
194
|
+
end
|
195
|
+
|
196
|
+
NOT_WHERE = "NOT %s".freeze
|
197
|
+
|
198
|
+
def exclude(*cond)
|
199
|
+
cond = cond.first if cond.size == 1
|
200
|
+
where(NOT_WHERE % where_list(cond))
|
190
201
|
end
|
191
202
|
|
192
203
|
LEFT_OUTER_JOIN = 'LEFT OUTER JOIN'.freeze
|
@@ -201,9 +212,8 @@ module Sequel
|
|
201
212
|
|
202
213
|
alias_method :filter, :where
|
203
214
|
alias_method :all, :to_a
|
204
|
-
alias_method :enum_map, :map
|
205
215
|
|
206
|
-
|
216
|
+
alias_method :enum_map, :map
|
207
217
|
def map(field_name = nil, &block)
|
208
218
|
if block
|
209
219
|
enum_map(&block)
|
@@ -272,6 +282,8 @@ module Sequel
|
|
272
282
|
sql
|
273
283
|
end
|
274
284
|
|
285
|
+
alias_method :sql, :select_sql
|
286
|
+
|
275
287
|
INSERT = "INSERT INTO %s (%s) VALUES (%s)".freeze
|
276
288
|
INSERT_EMPTY = "INSERT INTO %s DEFAULT VALUES".freeze
|
277
289
|
|
data/lib/sequel/postgres.rb
CHANGED
@@ -154,10 +154,6 @@ module Sequel
|
|
154
154
|
def transaction(&block)
|
155
155
|
@pool.hold {|conn| conn.transaction(&block)}
|
156
156
|
end
|
157
|
-
|
158
|
-
def table_exists?(name)
|
159
|
-
from(:pg_class).filter(:relname => name, :relkind => 'r').count > 0
|
160
|
-
end
|
161
157
|
end
|
162
158
|
|
163
159
|
class Dataset < Sequel::Dataset
|
data/lib/sequel/schema.rb
CHANGED
@@ -83,9 +83,9 @@ module Sequel
|
|
83
83
|
class Generator
|
84
84
|
attr_reader :table_name
|
85
85
|
|
86
|
-
def initialize(table_name, &block)
|
86
|
+
def initialize(table_name, auto_primary_key, &block)
|
87
87
|
@table_name = table_name
|
88
|
-
@primary_key =
|
88
|
+
@primary_key = auto_primary_key
|
89
89
|
@columns = []
|
90
90
|
@indexes = []
|
91
91
|
instance_eval(&block)
|
@@ -140,8 +140,16 @@ module Sequel
|
|
140
140
|
instance_eval(&block) if block
|
141
141
|
end
|
142
142
|
|
143
|
+
def auto_primary_key(name, type = nil, opts = nil)
|
144
|
+
@auto_primary_key = {
|
145
|
+
:name => name,
|
146
|
+
:type => type || :serial,
|
147
|
+
:primary_key => true
|
148
|
+
}.merge(opts || {})
|
149
|
+
end
|
150
|
+
|
143
151
|
def create_table(table_name, &block)
|
144
|
-
@instructions << Generator.new(table_name, &block)
|
152
|
+
@instructions << Generator.new(table_name, @auto_primary_key, &block)
|
145
153
|
end
|
146
154
|
|
147
155
|
def create(db)
|
data/lib/sequel/sqlite.rb
CHANGED
@@ -22,9 +22,11 @@ module Sequel
|
|
22
22
|
def dataset(opts = nil)
|
23
23
|
SQLite::Dataset.new(self, opts)
|
24
24
|
end
|
25
|
+
|
26
|
+
TABLES_FILTER = "type = 'table' AND NOT name = 'sqlite_sequence'"
|
25
27
|
|
26
28
|
def tables
|
27
|
-
|
29
|
+
self[:sqlite_master].filter(TABLES_FILTER).map {|r| r[:name].to_sym}
|
28
30
|
end
|
29
31
|
|
30
32
|
def execute(sql)
|
metadata
CHANGED
@@ -3,15 +3,15 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: sequel
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-03-
|
8
|
-
summary: ORM
|
6
|
+
version: 0.0.6
|
7
|
+
date: 2007-03-22 00:00:00 +02:00
|
8
|
+
summary: Concise ORM for Ruby.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: ciconia@gmail.com
|
12
12
|
homepage: http://sequel.rubyforge.org
|
13
13
|
rubyforge_project:
|
14
|
-
description: ORM
|
14
|
+
description: Concise ORM for Ruby.
|
15
15
|
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
@@ -33,7 +33,6 @@ files:
|
|
33
33
|
- README
|
34
34
|
- Rakefile
|
35
35
|
- bin/sequel
|
36
|
-
- doc/rdoc
|
37
36
|
- lib/sequel
|
38
37
|
- lib/sequel.rb
|
39
38
|
- lib/sequel/dataset.rb
|