You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The [Crate](http://www.crate.io) adapter for ActiveRecord.
6
5
6
+
## About
7
7
8
+
The Ruby on Rails ActiveRecord adapter for [CrateDB],
9
+
using the [crate_ruby] driver with HTTP connectivity.
10
+
11
+
**Note:** The `activerecord-crate-adapter` currently only works with Rails 4.1.x.
8
12
9
-
## Installation
10
13
11
-
**Note:**`activerecord-crate-adapter` currently only works with Rails 4.1.x
14
+
## Installation
12
15
13
-
Add this line to your application's Gemfile:
16
+
Add this line to your application's `Gemfile`:
14
17
15
18
gem 'activerecord-crate-adapter'
16
19
@@ -31,9 +34,9 @@ When using Rails update your database.yml
31
34
host: 127.0.0.1
32
35
port: 4200
33
36
34
-
Crate doesn't come with an autoincrement feature for your model ids. So you need to set
35
-
it yourself. One way is to use SecureRandom.uuid, if you think there is a better one,
36
-
please add an issue so we can discuss.
37
+
CrateDB doesn't come with an autoincrement feature for your model ids. So you need to set
38
+
it yourself. One way is to use `SecureRandom.uuid`, if you think there is a better one,
39
+
please add an issue, so we can discuss.
37
40
38
41
class Post < ActiveRecord::Base
39
42
@@ -47,10 +50,10 @@ please add an issue so we can discuss.
47
50
48
51
end
49
52
50
-
## Special Data Types
53
+
## Special data types
51
54
52
55
### Array
53
-
You can simply create Array columns by specifying t.array and passing array_type when you create a migration.
56
+
You can simply create Array columns by specifying `t.array` and passing `array_type` when you create a migration.
54
57
55
58
t.array :tags, array_type: :string
56
59
t.array :votes, array_type: :integer
@@ -62,10 +65,10 @@ When you create an object just pass your Array directly
62
65
post = Post.where("'fresh' = ANY (tags)")
63
66
64
67
### Object
65
-
Crate allows you to define nested objects. I tried to make it as simply as possible to use and reuse existing AR functionality,
66
-
I therefore ask you to reuse the existing serialize functionality. AR#serialize allows you to define your own serialization
67
-
mechanism and we simply reuse that for serializing an AR object. To get serialize working simply create a #dump and #load method
68
-
on the class that creates a literal statement that is then used in the SQL. Read up more in this [commit}(https://github.com/crate/crate/commit/16a3d4b3f23996a327f91cdacef573f7ba946017).
68
+
CrateDB allows you to define nested objects. I tried to make it as simply as possible to use and reuse existing AR functionality,
69
+
I therefore ask you to reuse the existing serialize functionality. `AR#serialize` allows you to define your own serialization
70
+
mechanism, and we simply reuse that for serializing an AR object. To get serialize working simply create `#dump` and `#load` methods
71
+
on the class that creates a literal statement that is then used in the SQL. Read up more in this [commit about array and object literals].
69
72
70
73
I tried to make your guys life easier and created a module that does this automatically for you. Simply make all attributes accessible
71
74
and assign it in the initializer. So a serialized class should look like this:
@@ -86,9 +89,9 @@ and assign it in the initializer. So a serialized class should look like this:
86
89
87
90
end
88
91
89
-
Check out CrateObject module if you need to write your own serializer.
92
+
Check out the `CrateObject` module if you need to write your own serializer.
90
93
91
-
Then in your model simply use #serialize to have objects working
94
+
Then in your model simply use `#serialize` to have objects working.
92
95
93
96
class User < ActiveRecord::Base
94
97
serialize :address, Address
@@ -98,7 +101,8 @@ Note: I do not plan to support nested objects inside objects.
98
101
99
102
#### Object Migrations
100
103
101
-
In the migrations you can create an object and specify the object behaviour(strict|dynamic|ignored) and it's schema.
104
+
In the migrations, you can create an object, specify the object behaviour
0 commit comments