sequel 0.0.4 → 0.0.5
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 +8 -0
- data/README +16 -4
- data/Rakefile +2 -2
- data/bin/sequel +1 -1
- data/lib/sequel/connection_pool.rb +4 -4
- data/lib/sequel/dataset.rb +4 -0
- data/lib/sequel/model.rb +7 -9
- data/lib/sequel/mysql.rb +5 -1
- data/lib/sequel/postgres.rb +5 -1
- data/lib/sequel/sqlite.rb +5 -1
- metadata +3 -3
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
==
|
1
|
+
== Serquel: Concise ORM for Ruby
|
2
2
|
|
3
|
-
Sequel is an ORM framework for Ruby. Sequel provides thread safety, connection pooling, and a DSL for constructing queries and table schemas.
|
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
|
+
|
5
|
+
Sequel makes it easy to deal with multiple records without having to break your teeth on SQL.
|
4
6
|
|
5
7
|
== Resources
|
6
8
|
|
@@ -31,7 +33,7 @@ Sequel currently supports:
|
|
31
33
|
|
32
34
|
== The Sequel Console
|
33
35
|
|
34
|
-
Sequel
|
36
|
+
Sequel includes an IRB console for quick'n'dirty access to databases. You can use it like this:
|
35
37
|
|
36
38
|
sequel sqlite:///test.db
|
37
39
|
|
@@ -41,6 +43,12 @@ You get an IRB session with the database object stored in DB.
|
|
41
43
|
|
42
44
|
=== Connecting to a database
|
43
45
|
|
46
|
+
Before connecting to a database, you should require the corresponding adaptor, for example:
|
47
|
+
|
48
|
+
require 'sequel/sqlite'
|
49
|
+
|
50
|
+
Note: you don't need to require 'sequel' separately before that, as each adapter requires 'sequel' if it hasn't yet been required.
|
51
|
+
|
44
52
|
There are two ways to create a connection to a database. The easier way is to provide a connection URL:
|
45
53
|
|
46
54
|
DB = Sequel.connect("sqlite:///blog.db")
|
@@ -59,7 +67,7 @@ The second, more verbose, way is to create an instance of a database class:
|
|
59
67
|
DB.execute("create table t (a text, b text)")
|
60
68
|
DB.execute("insert into t values ('a', 'b')")
|
61
69
|
|
62
|
-
Or more
|
70
|
+
Or more succinctly:
|
63
71
|
|
64
72
|
DB << "create table t (a text, b text)"
|
65
73
|
DB << "insert into t values ('a', 'b')"
|
@@ -101,6 +109,10 @@ You can also retrieve the first record in a dataset:
|
|
101
109
|
|
102
110
|
posts.first
|
103
111
|
|
112
|
+
Or retrieve a single record with a specific value:
|
113
|
+
|
114
|
+
posts[:id => 1]
|
115
|
+
|
104
116
|
If the dataset is ordered, you can also ask for the last record:
|
105
117
|
|
106
118
|
posts.order(:stamp).last
|
data/Rakefile
CHANGED
@@ -6,9 +6,9 @@ require 'fileutils'
|
|
6
6
|
include FileUtils
|
7
7
|
|
8
8
|
NAME = "sequel"
|
9
|
-
VERS = "0.0.
|
9
|
+
VERS = "0.0.5"
|
10
10
|
CLEAN.include ['**/.*.sw?', 'pkg/*', '.config', 'doc/*', 'coverage/*']
|
11
|
-
RDOC_OPTS = ['--quiet', '--title', "Sequel
|
11
|
+
RDOC_OPTS = ['--quiet', '--title', "Sequel: Concise ORM for Ruby",
|
12
12
|
"--opname", "index.html",
|
13
13
|
"--line-numbers",
|
14
14
|
"--main", "README",
|
data/bin/sequel
CHANGED
@@ -3,13 +3,13 @@ require 'thread'
|
|
3
3
|
module Sequel
|
4
4
|
class ConnectionPool
|
5
5
|
attr_reader :max_size, :mutex
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :connection_proc
|
7
7
|
attr_reader :available_connections, :allocated, :created_count
|
8
8
|
|
9
9
|
def initialize(max_size = 4, &block)
|
10
10
|
@max_size = max_size
|
11
11
|
@mutex = Mutex.new
|
12
|
-
@
|
12
|
+
@connection_proc = block
|
13
13
|
|
14
14
|
@available_connections = []
|
15
15
|
@allocated = {}
|
@@ -41,7 +41,7 @@ module Sequel
|
|
41
41
|
|
42
42
|
def acquire(thread)
|
43
43
|
@mutex.synchronize do
|
44
|
-
@allocated[thread]
|
44
|
+
@allocated[thread] = available
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -52,7 +52,7 @@ module Sequel
|
|
52
52
|
def make_new
|
53
53
|
if @created_count < @max_size
|
54
54
|
@created_count += 1
|
55
|
-
@
|
55
|
+
@connection_proc.call
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
data/lib/sequel/dataset.rb
CHANGED
data/lib/sequel/model.rb
CHANGED
@@ -126,6 +126,12 @@ module Sequel
|
|
126
126
|
get_hooks(:after_create) << block
|
127
127
|
end
|
128
128
|
|
129
|
+
def self.find(cond)
|
130
|
+
dataset[cond.is_a?(Hash) ? cond : {primary_key => cond}]
|
131
|
+
end
|
132
|
+
|
133
|
+
class << self; alias_method :[], :find; end
|
134
|
+
|
129
135
|
############################################################################
|
130
136
|
|
131
137
|
attr_reader :values, :pkey
|
@@ -135,7 +141,7 @@ module Sequel
|
|
135
141
|
end
|
136
142
|
|
137
143
|
def primary_key
|
138
|
-
|
144
|
+
self.class.primary_key
|
139
145
|
end
|
140
146
|
|
141
147
|
def initialize(values)
|
@@ -154,10 +160,6 @@ module Sequel
|
|
154
160
|
self
|
155
161
|
end
|
156
162
|
|
157
|
-
def self.find(cond)
|
158
|
-
dataset.filter(cond).first # || (raise RuntimeError, "Record not found.")
|
159
|
-
end
|
160
|
-
|
161
163
|
def self.each(&block); dataset.each(&block); end
|
162
164
|
def self.all; dataset.all; end
|
163
165
|
def self.filter(*arg); dataset.filter(*arg); end
|
@@ -172,10 +174,6 @@ module Sequel
|
|
172
174
|
end
|
173
175
|
def self.delete_all; dataset.delete; end
|
174
176
|
|
175
|
-
def self.[](key)
|
176
|
-
find key.is_a?(Hash) ? key : {primary_key => key}
|
177
|
-
end
|
178
|
-
|
179
177
|
def self.create(values = nil)
|
180
178
|
db.transaction do
|
181
179
|
obj = find(primary_key => dataset.insert(values))
|
data/lib/sequel/mysql.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
if !Object.const_defined?('Sequel')
|
2
|
+
require File.join(File.dirname(__FILE__), '../sequel')
|
3
|
+
end
|
4
|
+
|
1
5
|
require 'mysql'
|
2
6
|
|
3
7
|
module Sequel
|
@@ -8,7 +12,7 @@ module Sequel
|
|
8
12
|
|
9
13
|
def initialize(opts = {})
|
10
14
|
super
|
11
|
-
@pool.
|
15
|
+
@pool.connection_proc = proc do
|
12
16
|
Mysql.real_connect(@opts[:host], @opts[:user], @opts[:password],
|
13
17
|
@opts[:database], @opts[:port])
|
14
18
|
end
|
data/lib/sequel/postgres.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
if !Object.const_defined?('Sequel')
|
2
|
+
require File.join(File.dirname(__FILE__), '../sequel')
|
3
|
+
end
|
4
|
+
|
1
5
|
require 'postgres'
|
2
6
|
|
3
7
|
class PGconn
|
@@ -103,7 +107,7 @@ module Sequel
|
|
103
107
|
|
104
108
|
def initialize(opts = {})
|
105
109
|
super
|
106
|
-
@pool.
|
110
|
+
@pool.connection_proc = proc do
|
107
111
|
PGconn.connect(
|
108
112
|
@opts[:host] || 'localhost',
|
109
113
|
@opts[:port] || 5432,
|
data/lib/sequel/sqlite.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
if !Object.const_defined?('Sequel')
|
2
|
+
require File.join(File.dirname(__FILE__), '../sequel')
|
3
|
+
end
|
4
|
+
|
1
5
|
require 'sqlite3'
|
2
6
|
require 'metaid'
|
3
7
|
|
@@ -8,7 +12,7 @@ module Sequel
|
|
8
12
|
|
9
13
|
def initialize(opts = {})
|
10
14
|
super
|
11
|
-
@pool.
|
15
|
+
@pool.connection_proc = proc do
|
12
16
|
db = SQLite3::Database.new(@opts[:database])
|
13
17
|
db.type_translation = true
|
14
18
|
db
|
metadata
CHANGED
@@ -3,8 +3,8 @@ 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-
|
6
|
+
version: 0.0.5
|
7
|
+
date: 2007-03-21 00:00:00 +02:00
|
8
8
|
summary: ORM framework for Ruby.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -51,7 +51,7 @@ test_files: []
|
|
51
51
|
rdoc_options:
|
52
52
|
- --quiet
|
53
53
|
- --title
|
54
|
-
- Sequel
|
54
|
+
- "Sequel: Concise ORM for Ruby"
|
55
55
|
- --opname
|
56
56
|
- index.html
|
57
57
|
- --line-numbers
|