@@ -51,14 +51,14 @@ defmodule RethinkDB.Connection do
51
51
defmacro __using__ ( _opts ) do
52
52
quote location: :keep do
53
53
def start_link ( opts \\ [ ] ) do
54
- if Dict . has_key? ( opts , :name ) && opts [ :name ] != __MODULE__ do
54
+ if Keyword . has_key? ( opts , :name ) && opts [ :name ] != __MODULE__ do
55
55
# The whole point of this macro is to provide an implicit process
56
56
# name, so subverting it is considered an error.
57
57
raise ArgumentError . exception (
58
58
"Process name #{ inspect opts [ :name ] } conflicts with implicit name #{ inspect __MODULE__ } provided by `use RethinkDB.Connection`"
59
59
)
60
60
end
61
- RethinkDB.Connection . start_link ( Dict . put_new ( opts , :name , __MODULE__ ) )
61
+ RethinkDB.Connection . start_link ( Keyword . put_new ( opts , :name , __MODULE__ ) )
62
62
end
63
63
64
64
def run ( query , opts \\ [ ] ) do
@@ -98,12 +98,13 @@ defmodule RethinkDB.Connection do
98
98
* `profile` - whether or not to return a profile of the query’s execution (default: false).
99
99
"""
100
100
def run ( query , conn , opts \\ [ ] ) do
101
- timeout = Dict . get ( opts , :timeout , 5000 )
102
- conn_opts = Dict . drop ( opts , [ :timeout ] )
103
- noreply = Dict . get ( opts , :noreply , false )
101
+ timeout = Keyword . get ( opts , :timeout , 5000 )
102
+ conn_opts = Keyword . drop ( opts , [ :timeout ] )
103
+ noreply = Keyword . get ( opts , :noreply , false )
104
104
conn_opts = Connection . call ( conn , :conn_opts )
105
- |> Dict . take ( [ :db ] )
106
- |> Dict . merge ( conn_opts )
105
+ |> Map . to_list ( )
106
+ |> Keyword . take ( [ :db ] )
107
+ |> Keyword . merge ( conn_opts )
107
108
query = prepare_and_encode ( query , conn_opts )
108
109
msg = case noreply do
109
110
true -> { :query_noreply , query }
@@ -170,7 +171,7 @@ defmodule RethinkDB.Connection do
170
171
@ doc """
171
172
Start connection as a linked process
172
173
173
- Accepts a `Dict ` of options. Supported options:
174
+ Accepts a `Keyword.t ` of options. Supported options:
174
175
175
176
* `:host` - hostname to use to connect to database. Defaults to `'localhost'`.
176
177
* `:port` - port on which to connect to database. Defaults to `28015`.
@@ -182,26 +183,26 @@ defmodule RethinkDB.Connection do
182
183
* `:ca_certs` - a list of file paths to cacerts.
183
184
"""
184
185
def start_link ( opts \\ [ ] ) do
185
- args = Dict . take ( opts , [ :host , :port , :auth_key , :db , :sync_connect , :ssl , :max_pending ] )
186
+ args = Keyword . take ( opts , [ :host , :port , :auth_key , :db , :sync_connect , :ssl , :max_pending ] )
186
187
Connection . start_link ( __MODULE__ , args , opts )
187
188
end
188
189
189
190
def init ( opts ) do
190
- host = case Dict . get ( opts , :host , 'localhost' ) do
191
+ host = case Keyword . get ( opts , :host , 'localhost' ) do
191
192
x when is_binary ( x ) -> String . to_char_list x
192
193
x -> x
193
194
end
194
- sync_connect = Dict . get ( opts , :sync_connect , false )
195
- ssl = Dict . get ( opts , :ssl )
196
- opts = Dict . put ( opts , :host , host )
197
- |> Dict . put_new ( :port , 28015 )
198
- |> Dict . put_new ( :auth_key , "" )
199
- |> Dict . put_new ( :max_pending , 10000 )
200
- |> Dict . drop ( [ :sync_connect ] )
195
+ sync_connect = Keyword . get ( opts , :sync_connect , false )
196
+ ssl = Keyword . get ( opts , :ssl )
197
+ opts = Keyword . put ( opts , :host , host )
198
+ |> Keyword . put_new ( :port , 28015 )
199
+ |> Keyword . put_new ( :auth_key , "" )
200
+ |> Keyword . put_new ( :max_pending , 10000 )
201
+ |> Keyword . drop ( [ :sync_connect ] )
201
202
|> Enum . into ( % { } )
202
203
{ transport , transport_opts } = case ssl do
203
204
nil -> { % Transport.TCP { } , [ ] }
204
- x -> { % Transport.SSL { } , Enum . map ( Dict . fetch! ( x , :ca_certs ) , & ( { :cacertfile , & 1 } ) ) ++ [ verify: :verify_peer ] }
205
+ x -> { % Transport.SSL { } , Enum . map ( Keyword . fetch! ( x , :ca_certs ) , & ( { :cacertfile , & 1 } ) ) ++ [ verify: :verify_peer ] }
205
206
end
206
207
state = % {
207
208
pending: % { } ,
@@ -228,11 +229,11 @@ defmodule RethinkDB.Connection do
228
229
:ok ->
229
230
:ok = Transport . setopts ( socket , [ active: :once ] )
230
231
# TODO: investigate timeout vs hibernate
231
- { :ok , Dict . put ( state , :socket , socket ) }
232
+ { :ok , Map . put ( state , :socket , socket ) }
232
233
end
233
234
{ :error , :econnrefused } ->
234
- backoff = min ( Dict . get ( state , :timeout , 1000 ) , 64000 )
235
- { :backoff , backoff , Dict . put ( state , :timeout , backoff * 2 ) }
235
+ backoff = min ( Map . get ( state , :timeout , 1000 ) , 64000 )
236
+ { :backoff , backoff , Map . put ( state , :timeout , backoff * 2 ) }
236
237
end
237
238
end
238
239
0 commit comments