cassandro 0.1.0 → 0.1.1
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.
- checksums.yaml +8 -8
- data/README.md +98 -47
- data/cassandro.gemspec +1 -1
- data/lib/cassandro/core.rb +1 -1
- data/lib/cassandro/model.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Yjk2MWQwNTM2MmRlZDcyOTAyNTQzZTc4NzAxODEzNTU2MWQ0MTJkNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTYwOTU3N2E2ODQ3NWIxNTU5MzI5ZTI0OWQ5ZDI2NzNkZmYyZTFhOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTJkYjFlMDM4YmExYjYwMzJkMTYyZTkzYWJlN2Q4N2Q4NzhlM2IwYzcxZDc3
|
10
|
+
OGFiMWFjZTY1NjUwMTdlOWM2N2Y5ZTkwM2E0OWU5NzhhZjJlNGUzZTI0NDFk
|
11
|
+
NjFhYzJhNjM0YzViYWQ4OWQwMjVjY2I5NDlmYzM4MzczMmQ4YjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
CREATE TABLE IF NOT EXISTS users (
|
36
|
+
email VARCHAR,
|
37
|
+
first_name VARCHAR,
|
38
|
+
age INT,
|
39
39
|
created_at TIMESTAMP,
|
40
|
-
|
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
|
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
|
71
|
+
class User < Cassandro::Model
|
73
72
|
|
74
|
-
table '
|
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
|
80
|
+
class User < Cassandro::Model
|
82
81
|
|
83
|
-
attribute :
|
84
|
-
attribute :
|
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
|
94
|
+
class User < Cassandro::Model
|
94
95
|
|
95
|
-
|
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
|
105
|
+
class User < Cassandro::Model
|
116
106
|
|
117
|
-
unique :
|
107
|
+
unique :email
|
118
108
|
end
|
119
109
|
```
|
120
110
|
|
121
111
|
__A complete example__
|
122
112
|
|
123
113
|
```ruby
|
124
|
-
class
|
114
|
+
class User < Cassandro::Model
|
125
115
|
|
126
|
-
table '
|
116
|
+
table 'users'
|
127
117
|
|
128
|
-
attribute :
|
129
|
-
attribute :
|
118
|
+
attribute :email, :text
|
119
|
+
attribute :first_name, :text
|
120
|
+
attribute :age, :integer
|
121
|
+
attribute :created_at, :datetime
|
130
122
|
|
131
|
-
primary_key [:
|
123
|
+
primary_key [:email, :created_at]
|
132
124
|
|
133
|
-
unique :
|
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
|
-
|
143
|
-
=> #<
|
144
|
-
@attributes=
|
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
|
149
|
+
Find:
|
151
150
|
|
152
151
|
```ruby
|
153
|
-
|
154
|
-
=> #<
|
155
|
-
@attributes=
|
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
|
-
|
163
|
-
=> #<
|
164
|
-
@attributes=
|
165
|
-
|
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
|
-
|
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
|
data/cassandro.gemspec
CHANGED
data/lib/cassandro/core.rb
CHANGED
data/lib/cassandro/model.rb
CHANGED
@@ -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.
|
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-
|
12
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cassandra-driver
|