cassandro 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmU5NmI3YWNjYjMwYTYyZjQ2YjNlOGM1NTc4NTRkMmZkNDIwNjNlOA==
4
+ Yjk2MWQwNTM2MmRlZDcyOTAyNTQzZTc4NzAxODEzNTU2MWQ0MTJkNg==
5
5
  data.tar.gz: !binary |-
6
- NDZkYjJiMmZlOWU1ZTRjZDk4MmI2N2IzODFjYzJiYzY2OWI3M2Q3Yg==
6
+ YTYwOTU3N2E2ODQ3NWIxNTU5MzI5ZTI0OWQ5ZDI2NzNkZmYyZTFhOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDJiNDg1MTkyYWRmNzVjYzc0N2FkZjEzOGZmYThjMjRhZDViMmMwNjU4Yjgy
10
- ZDJjYzM4NTliYTdhNmNlZjI3MDRmMDgwZjc1ZTQ3ODQ1ZjQ4ZTNhYjEwOTcz
11
- ZmMxNjM4NjRjYjlhNjJiMWZiNTY4MjljZDNlODJjYjZkM2NmY2I=
9
+ OTJkYjFlMDM4YmExYjYwMzJkMTYyZTkzYWJlN2Q4N2Q4NzhlM2IwYzcxZDc3
10
+ OGFiMWFjZTY1NjUwMTdlOWM2N2Y5ZTkwM2E0OWU5NzhhZjJlNGUzZTI0NDFk
11
+ NjFhYzJhNjM0YzViYWQ4OWQwMjVjY2I5NDlmYzM4MzczMmQ4YjQ=
12
12
  data.tar.gz: !binary |-
13
- MGU1MjY0ZTE5NzlkNDIyMWE0N2QzODllZmRhZDZiMzBlNWI3NmI5NmZjY2E4
14
- ZjQ5YTI1OWQwYTZhMjM0OTEyY2VmMDYxYzdjY2RmNjViMDVmZDJlYTVkMTgx
15
- YmRjYjAyYzM2OWRiMjI0YmIxZGZkM2UxYmRkYTc0MDE5MDQ5ZDI=
13
+ YjhiMThkNGYxNTM4YzczYzQxZTUyY2U4YThmYjNlZGEyZGYyMjA2MjI5NDJh
14
+ YWY3ZmZmMjM5N2YwNzg4MTAxZjQ4MzAzZDkyMTJiNjZkZDE0NGQzMjI4M2Ux
15
+ YTA0OTQ0M2Y5Y2FkMGRmNjY5MjJlYzZjM2ZmYzAyYmYzNTBkNjI=
data/README.md CHANGED
@@ -32,13 +32,12 @@ Cassandro.use('keyspace_name')
32
32
  Create table.
33
33
  ```ruby
34
34
  table = <<-TABLEDEF
35
- CREATE TABLE IF NOT EXISTS table_name (
36
- id UUID,
37
- username VARCHAR,
38
- crypted_password VARCHAR,
35
+ CREATE TABLE IF NOT EXISTS users (
36
+ email VARCHAR,
37
+ first_name VARCHAR,
38
+ age INT,
39
39
  created_at TIMESTAMP,
40
- updated_at TIMESTAMP,
41
- PRIMARY KEY(id,username)
40
+ PRIMARY KEY(email,created_at)
42
41
  )
43
42
  TABLEDEF
44
43
 
@@ -62,26 +61,28 @@ result = Cassandro.client.execute(statement, id)
62
61
  Creating new model: make you class inherits form `Cassandro::Model`
63
62
 
64
63
  ```ruby
65
- class SomeModel < Cassandro::Model
64
+ class User < Cassandro::Model
66
65
  end
67
66
  ```
68
67
 
69
68
  Specifying table name using the method `table(table_name)`:
70
69
 
71
70
  ```ruby
72
- class SomeModel < Cassandro::Model
71
+ class User < Cassandro::Model
73
72
 
74
- table 'some_models'
73
+ table 'users'
75
74
  end
76
75
  ```
77
76
 
78
77
  Adding attributes using the method `attribute(name, type, options)`:
79
78
 
80
79
  ```ruby
81
- class SomeModel < Cassandro::Model
80
+ class User < Cassandro::Model
82
81
 
83
- attribute :id, :uuid
84
- attribute :name, :text
82
+ attribute :email, :text
83
+ attribute :first_name, :text
84
+ attribute :age, :integer
85
+ attribute :created_at, :datetime
85
86
  end
86
87
  ```
87
88
 
@@ -90,47 +91,38 @@ types: :uuid, :text, :integer, :float, :timestamp, :datetime
90
91
  Setting the primary key using the method `primary_key(pk_name | Array)`:
91
92
 
92
93
  ```ruby
93
- class SomeModel < Cassandro::Model
94
+ class User < Cassandro::Model
94
95
 
95
- attribute :id, :uuid
96
- attribute :name, :text
97
-
98
- primary_key :id
96
+ primary_key [:email, :created_at]
99
97
 
100
98
  end
101
99
 
102
- class SomeModel < Cassandro::Model
103
-
104
- attribute :id, :uuid
105
- attribute :name, :text
106
-
107
- primary_key [:id,:name]
108
-
109
- end
110
100
  ```
111
101
 
112
102
  Setting unique field using the method `unique(field | Array)`:
113
103
 
114
104
  ```ruby
115
- class SomeModel < Cassandro::Model
105
+ class User < Cassandro::Model
116
106
 
117
- unique :name
107
+ unique :email
118
108
  end
119
109
  ```
120
110
 
121
111
  __A complete example__
122
112
 
123
113
  ```ruby
124
- class SomeModel < Cassandro::Model
114
+ class User < Cassandro::Model
125
115
 
126
- table 'some_models'
116
+ table 'users'
127
117
 
128
- attribute :id, :uuid
129
- attribute :name, :text
118
+ attribute :email, :text
119
+ attribute :first_name, :text
120
+ attribute :age, :integer
121
+ attribute :created_at, :datetime
130
122
 
131
- primary_key [:id, :name]
123
+ primary_key [:email, :created_at]
132
124
 
133
- unique :name
125
+ unique :email
134
126
  end
135
127
  ```
136
128
 
@@ -139,37 +131,96 @@ end
139
131
  Creating a new row:
140
132
 
141
133
  ```ruby
142
- somemodel = SomeModel.create(name: 'DaModel')
143
- => #<SomeModel:0x00000001e7a0a8
144
- @attributes={:name=>"DaModel", :id=>"1534214c-0e0b-455c-95e8-13677f56d6e5"},
134
+ user = User.create(email: 'test1@example.com', first_name: 'Test', age: 30, created_at: DateTime.now)
135
+ => #<User:0x00000001b9dc40
136
+ @attributes=
137
+ {:email=>"test1@example.com",
138
+ :first_name=>"Test",
139
+ :age=>30,
140
+ :created_at=>
141
+ #<DateTime: 2014-11-03T11:34:47-03:00 ((2456965j,52487s,201385585n),-10800s,2299161j)>},
145
142
  @errors={},
143
+ @insert_statement=
144
+ #<Cassandra::Statements::Prepared:0xdcd4f8 @cql=" INSERT INTO users(email,first_name,age,created_at)\n VALUES(?,?,?,?)\n IF NOT EXISTS\n">,
146
145
  @persisted=true>
147
146
 
148
147
  ```
149
148
 
150
- Find row:
149
+ Find:
151
150
 
152
151
  ```ruby
153
- SomeModel[name: 'DaModel']
154
- => #<SomeModel:0x00000001d27930
155
- @attributes={:id=>1534214c-0e0b-455c-95e8-13677f56d6e5, :name=>"DaModel"},
152
+ User[email: 'test1@example.com']
153
+ => #<User:0x00000001cc59d8
154
+ @attributes=
155
+ {:email=>"test1@example.com",
156
+ :created_at=>2014-11-03 11:34:47 -0300,
157
+ :age=>30,
158
+ :first_name=>"Test"},
156
159
  @errors={},
157
160
  @persisted=true>
161
+
162
+ User.where('email','test1@example.com')
163
+ => #<User:0x00000001cc59d8
164
+ @attributes=
165
+ {:email=>"test1@example.com",
166
+ :created_at=>2014-11-03 11:34:47 -0300,
167
+ :age=>30,
168
+ :first_name=>"Test"},
169
+ @errors={},
170
+ @persisted=true>
171
+
172
+ ```
173
+
174
+ ```ruby
175
+ User.all
176
+ => [#<User:0x00000002bc75f8
177
+ @attributes=
178
+ {:email=>"test@example.com",
179
+ :created_at=>2014-11-03 11:30:52 -0300,
180
+ :age=>30,
181
+ :first_name=>"Test"},
182
+ @errors={},
183
+ @persisted=true>,
184
+ #<User:0x00000002bc6b30
185
+ @attributes=
186
+ {:email=>"test1@example.com",
187
+ :created_at=>2014-11-03 11:34:47 -0300,
188
+ :age=>30,
189
+ :first_name=>"Test"},
190
+ @errors={},
191
+ @persisted=true>]
192
+ ```
193
+
194
+ ```ruby
195
+ User.query('created_at > ?', Time.now.to_i)
196
+ => #<Cassandra::Result:0x1fcb254 @rows=[{"email"=>"test@example.com", "created_at"=>2014-11-03 11:30:52 -0300, "age"=>30, "first_name"=>"Test"}, {"email"=>"test1@example.com", "created_at"=>2014-11-03 11:34:47 -0300, "age"=>30, "first_name"=>"Test"}] @last_page=true>
197
+ ```
198
+
199
+ Count:
200
+
201
+ ```ruby
202
+ User.count('email', 'test@example.com')
203
+ => 1
158
204
  ```
159
205
 
160
206
  Checking errors:
161
207
  ```ruby
162
- somemodel = SomeModel.create(name: 'DaModel')
163
- => #<SomeModel:0x00000001d68160
164
- @attributes={:name=>"DaModel", :id=>"a723301b-b94b-4a4b-8d36-872055734ab5"},
165
- @errors={:unique=>"somemodel_not_unique"},
208
+ user = User.create(email: 'test1@example.com', first_name: 'Test', age: 30, created_at: DateTime.now)
209
+ => #<User:0x00000001dc7a48
210
+ @attributes=
211
+ {:email=>"test1@example.com",
212
+ :first_name=>"Test",
213
+ :age=>30,
214
+ :created_at=>
215
+ #<DateTime: 2014-11-03T11:36:40-03:00 ((2456965j,52600s,972972939n),-10800s,2299161j)>},
216
+ @errors={:unique=>"user_not_unique"},
166
217
  @persisted=false>
167
218
 
168
- somemodel.persisted?
219
+ user.persisted?
169
220
  => false
221
+ user.errors
222
+ => {:unique=>"user_not_unique"}
170
223
 
171
- somemodel.errors
172
- => {:unique=>"somemodel_not_unique"}
173
224
  ```
174
225
 
175
226
  ## TODO
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "cassandro"
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
  s.summary = "Ruby ORM for Apache Cassandra"
7
7
  s.license = "MIT"
8
8
  s.description = "Lightweight Apache Cassandra ORM for Ruby"
@@ -24,7 +24,7 @@ module Cassandro
24
24
  end
25
25
 
26
26
  def self.use(keyspace)
27
- @@session.execute("USE #{keyspace}") if @session
27
+ @@session.execute("USE #{keyspace}") if @@session
28
28
  end
29
29
 
30
30
  def self.disconnect
@@ -181,7 +181,7 @@ module Cassandro
181
181
  rows = Cassandro.execute(query)
182
182
  all = []
183
183
  rows.each do |row|
184
- all << new(row)
184
+ all << new(row, true)
185
185
  end
186
186
  all
187
187
  end
@@ -196,7 +196,7 @@ module Cassandro
196
196
  rows = Cassandro.client.execute(st, value)
197
197
 
198
198
  rows.each do |result|
199
- results << new(result)
199
+ results << new(result, true)
200
200
  end
201
201
 
202
202
  results
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassandro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lautaro Orazi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-31 00:00:00.000000000 Z
12
+ date: 2014-11-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cassandra-driver