swift 0.7.1 → 0.7.2
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/Rakefile +4 -8
- data/VERSION +1 -1
- data/ext/swift.h +3 -0
- data/lib/swift.rb +84 -1
- data/lib/swift/adapter.rb +120 -5
- data/lib/swift/attribute.rb +17 -0
- data/lib/swift/db.rb +10 -6
- data/lib/swift/scheme.rb +95 -0
- data/swift.gemspec +12 -12
- metadata +12 -12
data/Rakefile
CHANGED
@@ -30,12 +30,8 @@ end
|
|
30
30
|
task :test => :check_dependencies
|
31
31
|
task :default => :test
|
32
32
|
|
33
|
-
require '
|
34
|
-
Rake::
|
35
|
-
|
36
|
-
|
37
|
-
rdoc.rdoc_dir = 'rdoc'
|
38
|
-
rdoc.title = "swift #{version}"
|
39
|
-
rdoc.rdoc_files.include('README*')
|
40
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
33
|
+
require 'yard'
|
34
|
+
YARD::Rake::YardocTask.new do |yard|
|
35
|
+
yard.files = ['lib/**/*.rb']
|
41
36
|
end
|
37
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.2
|
data/ext/swift.h
CHANGED
data/lib/swift.rb
CHANGED
@@ -7,8 +7,69 @@ require_relative 'swift/header'
|
|
7
7
|
require_relative 'swift/scheme'
|
8
8
|
require_relative 'swift/type'
|
9
9
|
|
10
|
+
# A rational rudimentary object relational mapper.
|
11
|
+
#
|
12
|
+
# == Synopsis
|
13
|
+
# require 'swift'
|
14
|
+
# require 'swift/migrations'
|
15
|
+
#
|
16
|
+
# Swift.trace true # Debugging.
|
17
|
+
# Swift.setup :default, Swift::DB::Postgres, db: 'swift'
|
18
|
+
#
|
19
|
+
# class User < Swift::Scheme
|
20
|
+
# store :users
|
21
|
+
# attribute :id, Swift::Type::Integer, serial: true, key: true
|
22
|
+
# attribute :name, Swift::Type::String
|
23
|
+
# attribute :email, Swift::Type::String
|
24
|
+
# end # User
|
25
|
+
#
|
26
|
+
# # Migrate it.
|
27
|
+
# User.migrate!
|
28
|
+
#
|
29
|
+
# # Create
|
30
|
+
# User.create name: 'Apple Arthurton', email: 'apple@arthurton.local' # => User
|
31
|
+
#
|
32
|
+
# # Get by key.
|
33
|
+
# user = User.get id: 1
|
34
|
+
#
|
35
|
+
# # Alter attribute and update in one.
|
36
|
+
# user.update name: 'Jimmy Arthurton'
|
37
|
+
#
|
38
|
+
# # Alter attributes and update.
|
39
|
+
# user.name = 'Apple Arthurton'
|
40
|
+
# user.update
|
41
|
+
#
|
42
|
+
# # Destroy
|
43
|
+
# user.destroy
|
44
|
+
#
|
45
|
+
# == See
|
46
|
+
# * README.rdoc has more usage examples.
|
47
|
+
# * API.rdoc is a public API overview.
|
10
48
|
module Swift
|
11
49
|
class << self
|
50
|
+
|
51
|
+
# Setup a new DB connection.
|
52
|
+
#
|
53
|
+
# You almost certainly want to setup a <tt>:default</tt> named adapter. The <tt>:default</tt> scope will be used
|
54
|
+
# for unscoped calls to <tt>Swift.db</tt>.
|
55
|
+
#
|
56
|
+
# @example
|
57
|
+
# Swift.setup :default, Swift::DB::Postgres, db: 'db1'
|
58
|
+
# Swift.setup :other, Swift::DB::Postgres, db: 'db2'
|
59
|
+
#
|
60
|
+
# @param [Symbol] name Adapter name.
|
61
|
+
# @param [Swift::Adapter] type Concrete adapter subclass. See Swift::DB
|
62
|
+
# @param [Hash] options Connection options
|
63
|
+
# @option options [String] :db Name.
|
64
|
+
# @option options [String] :user (*nix login user)
|
65
|
+
# @option options [String] :password ('')
|
66
|
+
# @option options [String] :host ('localhost')
|
67
|
+
# @option options [Integer] :port (DB default)
|
68
|
+
# @option options [String] :timezone (*nix TZ format) See http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
69
|
+
# @return [Swift::Adapter]
|
70
|
+
#
|
71
|
+
# @see Swift::DB
|
72
|
+
# @see Swift::Adapter
|
12
73
|
def setup name, type, options = {}
|
13
74
|
unless type.kind_of?(Class) && type < Swift::Adapter
|
14
75
|
raise TypeError, "Expected +type+ Swift::Adapter subclass but got #{type.inspect}"
|
@@ -16,8 +77,25 @@ module Swift
|
|
16
77
|
(@repositories ||= {})[name] = type.new(options)
|
17
78
|
end
|
18
79
|
|
80
|
+
# Fetch or scope a block to a specific DB by name.
|
81
|
+
#
|
82
|
+
# @example
|
83
|
+
# Swift.db :other do |other|
|
84
|
+
# # Inside this block all these are the same:
|
85
|
+
# # other
|
86
|
+
# # Swift.db
|
87
|
+
# # Swift.db :other
|
88
|
+
#
|
89
|
+
# other_users = User.prepare('select * from users where age > ?')
|
90
|
+
# other_users.execute(32)
|
91
|
+
# end
|
92
|
+
#
|
93
|
+
# @param [Symbol] name Adapter name.
|
94
|
+
# @param [Proc] &block Scope this block to the named adapter instead of <tt>:default</tt>.
|
95
|
+
# @return [Swift::Adapter]
|
96
|
+
#--
|
97
|
+
# I pilfered the logic from DM but I don't really understand what is/isn't thread safe.
|
19
98
|
def db name = nil, &block
|
20
|
-
# I pilfered the logic from DM but I don't really understand what is/isn't thread safe.
|
21
99
|
scopes = (Thread.current[:swift_db] ||= [])
|
22
100
|
repository = if name || scopes.empty?
|
23
101
|
@repositories[name || :default] or raise "Unknown db '#{name || :default}', did you forget to #setup?"
|
@@ -36,6 +114,11 @@ module Swift
|
|
36
114
|
repository
|
37
115
|
end
|
38
116
|
|
117
|
+
# List of known Swift::Schema classes.
|
118
|
+
#
|
119
|
+
# Handy if you are brewing stuff like migrations and need a list of defined schema subclasses.
|
120
|
+
#
|
121
|
+
# @return [Array<Swift::Schema>]
|
39
122
|
def schema
|
40
123
|
@schema ||= []
|
41
124
|
end
|
data/lib/swift/adapter.rb
CHANGED
@@ -1,22 +1,96 @@
|
|
1
1
|
module Swift
|
2
|
+
|
3
|
+
# Adapter.
|
4
|
+
#
|
5
|
+
# @abstract
|
6
|
+
# @see Swift::DB See Swift::DB for concrete adapters.
|
7
|
+
# @todo For the time being all adapters are SQL and DBIC++ centric. It would be super easy to abstract though I
|
8
|
+
# don't know if you would be better off doing it at the Ruby or DBIC++ level (or both).
|
9
|
+
#--
|
10
|
+
# TODO: Extension methods are undocumented.
|
2
11
|
class Adapter
|
3
12
|
attr_reader :options
|
4
13
|
|
14
|
+
# Select by id(s).
|
15
|
+
#
|
16
|
+
# @example Single key.
|
17
|
+
# Swift.db.get(User, id: 12)
|
18
|
+
# @example Complex primary key.
|
19
|
+
# Swift.db.get(UserAddress, user_id: 12, address_id: 15)
|
20
|
+
#
|
21
|
+
# @param [Swift::Scheme] scheme Concrete scheme subclass to load.
|
22
|
+
# @param [Hash] keys Hash of id(s) <tt>{id_name: value}</tt>.
|
23
|
+
# @return [Swift::Scheme, nil]
|
24
|
+
# @see Swift::Scheme.get
|
25
|
+
#--
|
26
|
+
# NOTE: Not significantly shorter than Scheme.db.first(User, 'id = ?', 12)
|
5
27
|
def get scheme, keys
|
6
28
|
relation = scheme.new(keys)
|
7
29
|
prepare_get(scheme).execute(*relation.tuple.values_at(*scheme.header.keys)).first
|
8
30
|
end
|
9
31
|
|
32
|
+
# Select one or more.
|
33
|
+
#
|
34
|
+
# @example All.
|
35
|
+
# Swif.db.all(User)
|
36
|
+
# @example All with conditions and binds.
|
37
|
+
# Swift.db.all(User, ':name = ? and :age > ?', 'Apple Arthurton', 32)
|
38
|
+
# @example Block form iterator.
|
39
|
+
# Swift.db.all(User, ':age > ?', 32) do |user|
|
40
|
+
# puts user.name
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# @param [Swift::Scheme] scheme Concrete scheme subclass to load.
|
44
|
+
# @param [String] conditions Optional SQL 'where' fragment.
|
45
|
+
# @param [Object, ...] *binds Optional bind values that accompany conditions SQL fragment.
|
46
|
+
# @param [Proc] &block Optional 'each' iterator block.
|
47
|
+
# @return [Swift::Result]
|
48
|
+
# @see Swift::Scheme.all
|
10
49
|
def all scheme, conditions = '', *binds, &block
|
11
50
|
where = "where #{exchange_names(scheme, conditions)}" unless conditions.empty?
|
12
51
|
prepare(scheme, "select * from #{scheme.store} #{where}").execute(*binds, &block)
|
13
52
|
end
|
14
53
|
|
54
|
+
# Select one.
|
55
|
+
#
|
56
|
+
# @example First.
|
57
|
+
# Swif.db.first(User)
|
58
|
+
# @example First with conditions and binds.
|
59
|
+
# Swift.db.first(User, ':name = ? and :age > ?', 'Apple Arthurton', 32)
|
60
|
+
# @example Block form iterator.
|
61
|
+
# Swift.db.first(User, ':age > ?', 32) do |user|
|
62
|
+
# puts user.name
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# @param [Swift::Scheme] scheme Concrete scheme subclass to load.
|
66
|
+
# @param [String] conditions Optional SQL 'where' fragment.
|
67
|
+
# @param [Object, ...] *binds Optional bind values that accompany conditions SQL fragment.
|
68
|
+
# @param [Proc] &block Optional 'each' iterator block.
|
69
|
+
# @return [Swift::Scheme, nil]
|
70
|
+
# @see Swift::Scheme.first
|
15
71
|
def first scheme, conditions = '', *binds, &block
|
16
72
|
where = "where #{exchange_names(scheme, conditions)}" unless conditions.empty?
|
17
73
|
prepare(scheme, "select * from #{scheme.store} #{where} limit 1").execute(*binds, &block).first
|
18
74
|
end
|
19
75
|
|
76
|
+
# Create one or more.
|
77
|
+
#
|
78
|
+
# @example Scheme.
|
79
|
+
# user = User.new(name: 'Apply Arthurton', age: 32)
|
80
|
+
# Swift.db.create(User, user)
|
81
|
+
# @example Coerce hash to scheme.
|
82
|
+
# Swif.db.create(User, name: 'Apple Arthurton', age: 32)
|
83
|
+
# @example Multiple relations.
|
84
|
+
# apple = User.new(name: 'Apple Arthurton', age: 32)
|
85
|
+
# benny = User.new(name: 'Benny Arthurton', age: 30)
|
86
|
+
# Swift.db.first(User, apple, benny)
|
87
|
+
# @example Coerce multiple relations.
|
88
|
+
# Swift.db.first(User, {name: 'Apple Arthurton', age: 32}, {name: 'Benny Arthurton', age: 30})
|
89
|
+
#
|
90
|
+
# @param [Swift::Scheme] scheme Concrete scheme subclass to load.
|
91
|
+
# @param [Swift::Scheme, Hash> *relations Scheme or tuple hash. Hashes will be coerced into scheme via Swift::Scheme#new
|
92
|
+
# @return [Array<Swift::Scheme>]
|
93
|
+
# @see Swift::Scheme.create
|
20
94
|
def create scheme, *relations
|
21
95
|
statement = prepare_create(scheme)
|
22
96
|
relations.map do |relation|
|
@@ -28,6 +102,29 @@ module Swift
|
|
28
102
|
end
|
29
103
|
end
|
30
104
|
|
105
|
+
# Update one or more.
|
106
|
+
#
|
107
|
+
# @example Scheme.
|
108
|
+
# user = Swift.db.create(User, name: 'Apply Arthurton', age: 32)
|
109
|
+
# user.name = 'Arthur Appleton'
|
110
|
+
# Swift.db.update(User, user)
|
111
|
+
# @example Coerce hash to scheme.
|
112
|
+
# user = Swift.db.create(User, name: 'Apply Arthurton', age: 32)
|
113
|
+
# user.name = 'Arthur Appleton'
|
114
|
+
# Swif.db.update(User, user.tuple)
|
115
|
+
# @example Multiple relations.
|
116
|
+
# apple = Swift.db.create(User, name: 'Apple Arthurton', age: 32)
|
117
|
+
# benny = Swift.db.create(User, name: 'Benny Arthurton', age: 30)
|
118
|
+
# Swift.db.update(User, apple, benny)
|
119
|
+
# @example Coerce multiple relations.
|
120
|
+
# apple = Swift.db.create(User, name: 'Apple Arthurton', age: 32)
|
121
|
+
# benny = Swift.db.create(User, name: 'Benny Arthurton', age: 30)
|
122
|
+
# Swift.db.update(User, apple.tuple, benny.tuple)
|
123
|
+
#
|
124
|
+
# @param [Swift::Scheme] scheme Concrete scheme subclass to load.
|
125
|
+
# @param [Swift::Scheme, Hash> *relations Scheme or tuple hash. Hashes will be coerced into scheme via Swift::Scheme#new
|
126
|
+
# @return [Array<Swift::Scheme>]
|
127
|
+
# @see Swift::Scheme#update
|
31
128
|
def update scheme, *relations
|
32
129
|
statement = prepare_update(scheme)
|
33
130
|
relations.map do |relation|
|
@@ -37,6 +134,28 @@ module Swift
|
|
37
134
|
end
|
38
135
|
end
|
39
136
|
|
137
|
+
# Destroy one or more.
|
138
|
+
#
|
139
|
+
# @example Scheme.
|
140
|
+
# user = Swift.db.create(User, name: 'Apply Arthurton', age: 32)
|
141
|
+
# user.name = 'Arthur Appleton'
|
142
|
+
# Swift.db.destroy(User, user)
|
143
|
+
# @example Coerce hash to scheme.
|
144
|
+
# user = Swift.db.create(User, name: 'Apply Arthurton', age: 32)
|
145
|
+
# user.name = 'Arthur Appleton'
|
146
|
+
# Swif.db.destroy(User, user.tuple)
|
147
|
+
# @example Multiple relations.
|
148
|
+
# apple = Swift.db.create(User, name: 'Apple Arthurton', age: 32)
|
149
|
+
# benny = Swift.db.create(User, name: 'Benny Arthurton', age: 30)
|
150
|
+
# Swift.db.destroy(User, apple, benny)
|
151
|
+
# @example Coerce multiple relations.
|
152
|
+
# apple = Swift.db.create(User, name: 'Apple Arthurton', age: 32)
|
153
|
+
# benny = Swift.db.create(User, name: 'Benny Arthurton', age: 30)
|
154
|
+
# Swift.db.destroy(User, apple.tuple, benny.tuple)
|
155
|
+
#
|
156
|
+
# @param [Swift::Scheme] scheme Concrete scheme subclass to load.
|
157
|
+
# @param [Swift::Scheme, Hash] *relations Scheme or tuple hash. Hashes will be coerced into scheme via Swift::Scheme#new
|
158
|
+
# @see Swift::Scheme#destroy
|
40
159
|
def destroy scheme, *relations
|
41
160
|
statement = prepare_destroy(scheme)
|
42
161
|
relations.map do |relation|
|
@@ -53,14 +172,10 @@ module Swift
|
|
53
172
|
fields = scheme.header.map{|p| field_definition(p)}.join(', ')
|
54
173
|
fields += ", primary key (#{keys.join(', ')})" unless keys.empty?
|
55
174
|
|
56
|
-
|
175
|
+
execute("drop table if exists #{scheme.store}")
|
57
176
|
execute("create table #{scheme.store} (#{fields})")
|
58
177
|
end
|
59
178
|
|
60
|
-
def drop_store name
|
61
|
-
execute("drop table if exists #{name}")
|
62
|
-
end
|
63
|
-
|
64
179
|
protected
|
65
180
|
def exchange_names scheme, query
|
66
181
|
query.gsub(/:(\w+)/){ scheme.send($1.to_sym).field }
|
data/lib/swift/attribute.rb
CHANGED
@@ -1,9 +1,25 @@
|
|
1
1
|
module Swift
|
2
|
+
|
3
|
+
# An attribute (column) definition.
|
2
4
|
#--
|
3
5
|
# NOTE: Default method is defined in the extension.
|
4
6
|
class Attribute
|
5
7
|
attr_reader :name, :field, :key, :serial
|
6
8
|
|
9
|
+
# @example
|
10
|
+
# user = Class.new(Swift::Scheme)
|
11
|
+
# Swift::Attribute.new(user, :name, Swift::Type::String)
|
12
|
+
#
|
13
|
+
# @param [Swift::Scheme] scheme
|
14
|
+
# @param [Symbol] name
|
15
|
+
# @param [Hash] options
|
16
|
+
# @option options [Object, Proc] :default
|
17
|
+
# @option options [Symbol] :field
|
18
|
+
# @option options [TrueClass, FalseClass] :key
|
19
|
+
# @option options [TrueClass, FalseClass] :serial
|
20
|
+
#
|
21
|
+
# @see Swift::Scheme
|
22
|
+
# @see Swift::Type
|
7
23
|
def initialize scheme, name, options = {}
|
8
24
|
@name = name
|
9
25
|
@default = options.fetch(:default, nil)
|
@@ -13,6 +29,7 @@ module Swift
|
|
13
29
|
define_scheme_methods(scheme)
|
14
30
|
end
|
15
31
|
|
32
|
+
# Evals attribute accessors for this attribute into the scheme.
|
16
33
|
def define_scheme_methods scheme
|
17
34
|
scheme.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
18
35
|
def #{name}; tuple.fetch(:#{field}, nil) end
|
data/lib/swift/db.rb
CHANGED
@@ -36,14 +36,18 @@ module Swift
|
|
36
36
|
false
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
39
|
+
def migrate!
|
40
|
+
keys = scheme.header.keys
|
41
|
+
fields = scheme.header.map{|p| field_definition(p)}.join(', ')
|
42
|
+
fields += ", primary key (#{keys.join(', ')})" unless keys.empty?
|
43
|
+
|
44
|
+
sql = <<-SQL
|
45
|
+
select count(*) as exists from syscat.tables
|
46
|
+
where tabschema = CURRENT_SCEMA and tabname = '#{scheme.store.upcase}'
|
42
47
|
SQL
|
43
48
|
|
44
|
-
execute(
|
45
|
-
|
46
|
-
end
|
49
|
+
execute(sql) {|result| execute("drop table #{scheme.store}") if result[:exists] > 0 }
|
50
|
+
execute("create table #{scheme.store} (#{fields})")
|
47
51
|
end
|
48
52
|
|
49
53
|
def field_type attribute
|
data/lib/swift/scheme.rb
CHANGED
@@ -1,23 +1,62 @@
|
|
1
1
|
module Swift
|
2
|
+
|
3
|
+
# A relation (instance) definition.
|
4
|
+
#
|
5
|
+
# @example A user scheme.
|
6
|
+
# class User < Swift::Scheme
|
7
|
+
# store :users
|
8
|
+
# attribute :id, Swift::Type::Integer, serial: true, key: true
|
9
|
+
# attribute :name, Swift::Type::String
|
10
|
+
# attribute :email, Swift::Type::String
|
11
|
+
# attribute :updated_at, Swift::Type::Time
|
12
|
+
# end # User
|
13
|
+
#
|
14
|
+
# @todo Tuple should be renamed tuples (plural?)
|
2
15
|
class Scheme
|
3
16
|
attr_accessor :tuple
|
4
17
|
alias_method :scheme, :class
|
5
18
|
|
19
|
+
# @example
|
20
|
+
# User.new(
|
21
|
+
# name: 'Apple Arthurton',
|
22
|
+
# email: 'apple@arthurton.local',
|
23
|
+
# updated_at: Time.now
|
24
|
+
# )
|
25
|
+
# @param [Hash] options Create relation and set attributes. <tt>{name: value}</tt>
|
6
26
|
def initialize options = {}
|
7
27
|
@tuple = scheme.header.new_tuple
|
8
28
|
options.each{|k, v| send(:"#{k}=", v)}
|
9
29
|
end
|
10
30
|
|
31
|
+
# @example
|
32
|
+
# apple = User.create(
|
33
|
+
# name: 'Apple Arthurton',
|
34
|
+
# email: 'apple@arthurton.local',
|
35
|
+
# updated_at: Time.now
|
36
|
+
# )
|
37
|
+
# apple.update(name: 'Arthur Appleton')
|
38
|
+
#
|
39
|
+
# @param [Hash] options Update attributes. <tt>{name: value}</tt>
|
11
40
|
def update options = {}
|
12
41
|
options.each{|k, v| send(:"#{k}=", v)}
|
13
42
|
Swift.db.update(scheme, self)
|
14
43
|
end
|
15
44
|
|
45
|
+
# @example
|
46
|
+
# apple = User.create(
|
47
|
+
# name: 'Apple Arthurton',
|
48
|
+
# email: 'apple@arthurton.local',
|
49
|
+
# updated_at: Time.now
|
50
|
+
# )
|
51
|
+
# apple.destroy
|
16
52
|
def destroy
|
17
53
|
Swift.db.destroy(scheme, self)
|
18
54
|
end
|
19
55
|
|
20
56
|
class << self
|
57
|
+
# Attribute set.
|
58
|
+
#
|
59
|
+
# @return [Swift::Header]
|
21
60
|
attr_accessor :header
|
22
61
|
|
23
62
|
def inherited klass
|
@@ -32,27 +71,83 @@ module Swift
|
|
32
71
|
scheme
|
33
72
|
end
|
34
73
|
|
74
|
+
# Define a new attribute for this scheme.
|
75
|
+
#
|
76
|
+
# @see Swift::Attribute#new
|
35
77
|
def attribute name, type, options = {}
|
36
78
|
header.push(attribute = type.new(self, name, options))
|
37
79
|
(class << self; self end).send(:define_method, name, lambda{ attribute })
|
38
80
|
end
|
39
81
|
|
82
|
+
# Define the store (table).
|
83
|
+
#
|
84
|
+
# @param [Symbol] name Storage name.
|
85
|
+
# @return [Symbol]
|
40
86
|
def store name = nil
|
41
87
|
name ? @store = name : @store
|
42
88
|
end
|
43
89
|
|
90
|
+
# Create (insert).
|
91
|
+
#
|
92
|
+
# @example
|
93
|
+
# apple = User.create(
|
94
|
+
# name: 'Apple Arthurton',
|
95
|
+
# email: 'apple@arthurton.local',
|
96
|
+
# updated_at: Time.now
|
97
|
+
# )
|
98
|
+
#
|
99
|
+
# @param [Hash] options Create with attributes. <tt>{name: value}</tt>
|
44
100
|
def create options = {}
|
45
101
|
Swift.db.create(self, options)
|
46
102
|
end
|
47
103
|
|
104
|
+
# Select by id(s).
|
105
|
+
#
|
106
|
+
# @example Single key.
|
107
|
+
# User.get(id: 12)
|
108
|
+
# @example Complex primary key.
|
109
|
+
# UserAddress.get(user_id: 12, address_id: 15)
|
110
|
+
#
|
111
|
+
# @param [Hash] keys Hash of id(s) <tt>{id_name: value}</tt>.
|
112
|
+
# @return [Swift::Scheme, nil]
|
48
113
|
def get keys
|
49
114
|
Swift.db.get(self, keys)
|
50
115
|
end
|
51
116
|
|
117
|
+
# Select one or more.
|
118
|
+
#
|
119
|
+
# @example All.
|
120
|
+
# User.all
|
121
|
+
# @example All with conditions and binds.
|
122
|
+
# User.all(':name = ? and :age > ?', 'Apple Arthurton', 32)
|
123
|
+
# @example Block form iterator.
|
124
|
+
# User.all(':age > ?', 32) do |user|
|
125
|
+
# puts user.name
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# @param [String] conditions Optional SQL 'where' fragment.
|
129
|
+
# @param [Object, ...] *binds Optional bind values that accompany conditions SQL fragment.
|
130
|
+
# @param [Proc] &block Optional 'each' iterator block.
|
131
|
+
# @return [Swift::Result]
|
52
132
|
def all conditions = '', *binds, &block
|
53
133
|
Swift.db.all(self, conditions, *binds, &block)
|
54
134
|
end
|
55
135
|
|
136
|
+
# Select one.
|
137
|
+
#
|
138
|
+
# @example First.
|
139
|
+
# User.first
|
140
|
+
# @example First with conditions and binds.
|
141
|
+
# User.first(':name = ? and :age > ?', 'Apple Arthurton', 32)
|
142
|
+
# @example Block form iterator.
|
143
|
+
# User.first(User, 'age > ?', 32) do |user|
|
144
|
+
# puts user.name
|
145
|
+
# end
|
146
|
+
#
|
147
|
+
# @param [String] conditions Optional SQL 'where' fragment.
|
148
|
+
# @param [Object, ...] *binds Optional bind values that accompany conditions SQL fragment.
|
149
|
+
# @param [Proc] &block Optional 'each' iterator block.
|
150
|
+
# @return [Swift::Scheme, nil]
|
56
151
|
def first conditions = '', *binds, &block
|
57
152
|
Swift.db.first(self, conditions, *binds, &block)
|
58
153
|
end
|
data/swift.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{swift}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Shane Hanna", "Bharanee 'Barney' Rathna"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-10-02}
|
13
13
|
s.description = %q{A rational rudimentary database abstraction.}
|
14
14
|
s.email = ["shane.hanna@gmail.com", "deepfryed@gmail.com"]
|
15
15
|
s.extensions = ["ext/extconf.rb"]
|
@@ -74,20 +74,20 @@ Gem::Specification.new do |s|
|
|
74
74
|
s.rubygems_version = %q{1.3.6}
|
75
75
|
s.summary = %q{A rational rudimentary database abstraction.}
|
76
76
|
s.test_files = [
|
77
|
-
"test/
|
78
|
-
"test/
|
79
|
-
"test/
|
80
|
-
"test/test_transactions.rb",
|
81
|
-
"test/test_adapter.rb",
|
82
|
-
"test/test_identity_map.rb",
|
77
|
+
"test/test_adapter.rb",
|
78
|
+
"test/test_scheme.rb",
|
79
|
+
"test/test_types.rb",
|
83
80
|
"test/test_error.rb",
|
84
|
-
"test/
|
81
|
+
"test/test_io.rb",
|
85
82
|
"test/test_encoding.rb",
|
83
|
+
"test/test_transactions.rb",
|
84
|
+
"test/test_validations.rb",
|
86
85
|
"test/test_timestamps.rb",
|
87
|
-
"test/
|
88
|
-
"test/
|
89
|
-
"
|
86
|
+
"test/helper.rb",
|
87
|
+
"test/test_identity_map.rb",
|
88
|
+
"test/test_pool.rb",
|
90
89
|
"examples/async.rb",
|
90
|
+
"examples/scheme.rb",
|
91
91
|
"examples/db.rb"
|
92
92
|
]
|
93
93
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 2
|
9
|
+
version: 0.7.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Shane Hanna
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-02 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -136,18 +136,18 @@ signing_key:
|
|
136
136
|
specification_version: 3
|
137
137
|
summary: A rational rudimentary database abstraction.
|
138
138
|
test_files:
|
139
|
-
- test/test_pool.rb
|
140
|
-
- test/test_io.rb
|
141
|
-
- test/test_validations.rb
|
142
|
-
- test/test_transactions.rb
|
143
139
|
- test/test_adapter.rb
|
144
|
-
- test/
|
140
|
+
- test/test_scheme.rb
|
141
|
+
- test/test_types.rb
|
145
142
|
- test/test_error.rb
|
146
|
-
- test/
|
143
|
+
- test/test_io.rb
|
147
144
|
- test/test_encoding.rb
|
145
|
+
- test/test_transactions.rb
|
146
|
+
- test/test_validations.rb
|
148
147
|
- test/test_timestamps.rb
|
149
|
-
- test/
|
150
|
-
- test/
|
151
|
-
-
|
148
|
+
- test/helper.rb
|
149
|
+
- test/test_identity_map.rb
|
150
|
+
- test/test_pool.rb
|
152
151
|
- examples/async.rb
|
152
|
+
- examples/scheme.rb
|
153
153
|
- examples/db.rb
|