cql_model 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -3,16 +3,14 @@ module Cql::Model::FinderMethods
|
|
3
3
|
|
4
4
|
module ClassMethods
|
5
5
|
def all
|
6
|
-
query = "SELECT * FROM #{
|
6
|
+
query = "SELECT * FROM #{table_name}"
|
7
7
|
execute(query)
|
8
8
|
end
|
9
9
|
|
10
10
|
def find(*args)
|
11
11
|
value = args.to_a.flatten.join(',')
|
12
|
-
key = self.primary_key
|
13
|
-
table = self.model_name.plural
|
14
12
|
|
15
|
-
query = "SELECT * FROM #{
|
13
|
+
query = "SELECT * FROM #{table_name} WHERE #{primary_key} IN (#{value})"
|
16
14
|
|
17
15
|
if args[0].is_a?(Array) || args.size > 1
|
18
16
|
execute(query).to_a
|
@@ -22,13 +20,11 @@ module Cql::Model::FinderMethods
|
|
22
20
|
end
|
23
21
|
|
24
22
|
def find_by(hash)
|
25
|
-
table = self.model_name.plural
|
26
|
-
|
27
23
|
clause = "WHERE "
|
28
24
|
clause_pieces = hash.collect {|key,value| "#{key.to_s} = '#{value}'"}
|
29
25
|
clause << clause_pieces.join(' AND ')
|
30
26
|
|
31
|
-
query = "SELECT * FROM #{
|
27
|
+
query = "SELECT * FROM #{table_name} #{clause} ALLOW FILTERING"
|
32
28
|
|
33
29
|
execute(query).to_a
|
34
30
|
end
|
@@ -12,16 +12,26 @@ module Cql::Model::PersistenceMethods
|
|
12
12
|
|
13
13
|
updates = updates.join(', ')
|
14
14
|
|
15
|
-
|
16
|
-
primary_key = self.class.primary_key.to_s
|
17
|
-
|
18
|
-
query = "UPDATE #{table} SET #{updates} WHERE #{primary_key} = #{quoted_primary_value}"
|
15
|
+
query = "UPDATE #{table_name} SET #{updates} WHERE #{primary_key} = #{quoted_primary_value}"
|
19
16
|
Cql::Base.connection.execute(query)
|
20
17
|
|
21
18
|
@persisted = true
|
22
19
|
self
|
23
20
|
end
|
24
21
|
|
22
|
+
def deleted?
|
23
|
+
@deleted
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete
|
27
|
+
query = "DELETE FROM #{table_name} WHERE #{primary_key} = #{quoted_primary_value}"
|
28
|
+
Cql::Base.connection.execute(query)
|
29
|
+
|
30
|
+
@deleted = true
|
31
|
+
@persisted = false
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
25
35
|
module ClassMethods
|
26
36
|
|
27
37
|
end
|
@@ -1,7 +1,19 @@
|
|
1
1
|
module Cql::Model::SchemaMethods
|
2
2
|
extend ::ActiveSupport::Concern
|
3
3
|
|
4
|
+
def table_name
|
5
|
+
self.class.table_name
|
6
|
+
end
|
7
|
+
|
8
|
+
def primary_key
|
9
|
+
self.class.primary_key
|
10
|
+
end
|
11
|
+
|
4
12
|
module ClassMethods
|
13
|
+
def table_name
|
14
|
+
@table_name ||= self.model_name.plural
|
15
|
+
end
|
16
|
+
|
5
17
|
def columns
|
6
18
|
@columns ||= {}
|
7
19
|
end
|
data/lib/cql/model/version.rb
CHANGED
data/lib/cql/model.rb
CHANGED
@@ -23,11 +23,24 @@ describe 'Cql::Model Finders' do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
describe '#
|
26
|
+
describe '#delete' do
|
27
|
+
before :each do
|
28
|
+
@person.save
|
29
|
+
end
|
27
30
|
|
28
|
-
|
31
|
+
it { @person.delete.must_be_instance_of Person }
|
29
32
|
|
30
|
-
|
33
|
+
it do
|
34
|
+
@person.deleted?.must_equal false
|
35
|
+
@person.persisted?.must_equal true
|
36
|
+
@person.delete
|
37
|
+
@person.deleted?.must_equal true
|
38
|
+
@person.persisted?.must_equal false
|
39
|
+
end
|
31
40
|
|
41
|
+
it do
|
42
|
+
@person.delete
|
43
|
+
Person.find(123).must_be_nil
|
44
|
+
end
|
32
45
|
end
|
33
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cql_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -166,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
166
|
version: '0'
|
167
167
|
segments:
|
168
168
|
- 0
|
169
|
-
hash:
|
169
|
+
hash: -2300288373958290693
|
170
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
171
|
none: false
|
172
172
|
requirements:
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
version: '0'
|
176
176
|
segments:
|
177
177
|
- 0
|
178
|
-
hash:
|
178
|
+
hash: -2300288373958290693
|
179
179
|
requirements: []
|
180
180
|
rubyforge_project:
|
181
181
|
rubygems_version: 1.8.23
|