tako 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9861d9ec9b928c4ed0bbe68ada132a9335fd6077
4
- data.tar.gz: 78351b4438784d0b40bf5a4e3b826ef5c60624eb
3
+ metadata.gz: 251999f9587d91e10a4124565e939a832f1a07da
4
+ data.tar.gz: 4161bbab1056d2c22a2984fd4b4429f73f51f4da
5
5
  SHA512:
6
- metadata.gz: cbb4e884798a8dbb5d2de722ffcc196c048a82df49ce45b56c9530c878e492489bae0f8e5d3a71f577f765c8c41ff87fb90da93877b7efdc7237075838f66acc
7
- data.tar.gz: 29f14c874dbf1d539dfbdfc263121406daee76fd53f3ca44a9c06eeec724cadcea11adfee04fde6aab5b1512d71f53164340adac25a96cc802749fe7efa7fbb9
6
+ metadata.gz: 80506c988bd63b6b3a437c16998a79bccd22126e6b667e5f2fd917d097f44488ba52f1a615aea3c86f0d811275a00c9bb53e42d5dd807ebf2495f57393243f54
7
+ data.tar.gz: 5473bc23a5dcfaf1d96bb437c4d3b7796fce09e816b2226a02406a0bed008859b86b48e0df1f14417a5a4a577261ace70daa58874414e556a6c046d297ef8dc8
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # Tako
2
2
  [![CircleCI](https://circleci.com/gh/the40san/tako/tree/master.svg?style=svg)](https://circleci.com/gh/the40san/tako/tree/master)
3
3
 
4
- Provides features for Database Sharding in ActiveRecord.
5
- The main goal of tako is implementing sharding features with less ActiveRecord-dependent, catching up Rails version up.
6
- Rails 5 Ready.
4
+ Tako provides Database-Sharding features for ActiveRecord.
5
+ Respecting [Octopus](https://github.com/thiagopradi/octopus)
6
+
7
+ # Motivation
8
+ The main goal of Tako is implementing sharding features with less ActiveRecord-dependent; catching up Rails version up.
9
+ And also, Tako supports migration from Octopus because it is no longer maintained.
10
+
7
11
 
8
12
  ## Installation
9
13
 
@@ -29,7 +33,7 @@ Or install it yourself as:
29
33
 
30
34
  ## Usage
31
35
  ## How to use Tako?
32
- First, you need to create a config file, shards.yml, inside your config/ directory.
36
+ First, you need to create a config file, `shards.yml`, inside your config/ directory.
33
37
  Also you can override config file path with environment variable.
34
38
 
35
39
  ### Syntax
@@ -37,22 +41,49 @@ Tako adds a method to each AR Class and object: the shard method is used to sele
37
41
 
38
42
  ```ruby
39
43
  User.shard(:slave_one).where(:name => "Thiago").limit(3)
44
+ # => Query will run in :slave_one
40
45
  ```
41
46
 
42
47
  Tako also supports queries within a block. When you pass a block to the shard method, all queries inside the block will be sent to the specified shard.
43
48
 
44
49
  ```ruby
50
+ User.create(name: "Bob")
51
+ # => Query will run in default connection in database.yml
52
+
45
53
  Tako.shard(:slave_two) do
46
- User.create(:name => "Mike")
54
+ User.create(name: "Mike")
55
+ # => Query will run in :slave_two
47
56
  end
48
57
 
49
58
  # or
50
59
 
51
- ModelA.shard(:slave_two) do
52
- User.create(:name => "Mike")
60
+ User.shard(:slave_two) do
61
+ User.create(name: "Mike")
62
+ # => Query will run in :slave_two
53
63
  end
54
64
  ```
55
65
 
66
+ ## Associations
67
+
68
+ ```
69
+ class User < ActiveRecord::Base
70
+ has_many :logs
71
+ has_one :life
72
+ end
73
+
74
+ user = User.shard(:shard01).create(name: "Jerry")
75
+
76
+ user.logs.create
77
+ # => Query will run in :shard01 (same as user)
78
+
79
+ user.logs << Log.shard(:shard02).new
80
+ # => Query will run in :shard02 (careful)
81
+
82
+ life = user.build_life
83
+ life.save!
84
+ # => Query will run in :shard01 (same as user)
85
+ ```
86
+
56
87
  ## Vertical Sharding
57
88
 
58
89
  Add `force_shard` definition to your Vertical-Sharding model
@@ -61,8 +92,20 @@ Add `force_shard` definition to your Vertical-Sharding model
61
92
  class YourModel < ActiveRecord::Base
62
93
  force_shard :shard01
63
94
  end
95
+
96
+ YourModel.create
97
+ # => Query will run in :shard01
98
+
99
+ Tako.shard(:shard02) do
100
+ YourModel.create
101
+ # => Query will run in :shard01
102
+ end
64
103
  ```
65
104
 
105
+ ## TODO
106
+
107
+ * Make more independent of ActiveRecord implementation.
108
+
66
109
  ## Development
67
110
 
68
111
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -73,14 +116,15 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
73
116
 
74
117
  Run `bundle exec rake` to run rspec
75
118
 
76
- Run `bundle exec rake` in `spec/dummy5` will run rspec with rails 5
119
+ Run `bundle exec rake` in `spec/dummy5` will run rspec with rails 5.0.0.1
77
120
 
78
- Run `bundle exec rake` in `spec/dummy42` will run rspec with rails 4.2
121
+ Run `bundle exec rake` in `spec/dummy42` will run rspec with rails 4.2.7.1
79
122
 
80
123
 
81
124
  ## Contributing
82
125
 
83
- Bug reports and pull requests are welcome on GitHub at https://github.com/the40san/tako. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
126
+ Contributors are welcome on GitHub at https://github.com/the40san/tako. Documentation contributors also welcome!
127
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
84
128
 
85
129
 
86
130
  ## License
data/lib/tako.rb CHANGED
@@ -23,6 +23,7 @@ module Tako
23
23
  end
24
24
 
25
25
  def load_connections_from_yaml
26
+ Tako::Repository.clear
26
27
  (config[env] || []).each do |shard_name, conf|
27
28
  Tako::Repository.add(shard_name, conf)
28
29
  end
@@ -9,6 +9,15 @@ module Tako
9
9
  @proxy_connections ||= {}
10
10
  end
11
11
 
12
+ def clear
13
+ proxy_connections.each do |shard_name, connection|
14
+ connection.disconnect!
15
+ remove_const("TAKO_AR_CLASS_#{shard_name.upcase}")
16
+ end
17
+ proxy_configs.clear
18
+ proxy_connections.clear
19
+ end
20
+
12
21
  def add(shard_name, conf)
13
22
  shard_name = shard_name.to_sym
14
23
  return if proxy_configs[shard_name]
data/lib/tako/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tako
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tako
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masashi AKISUE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2016-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord