@@ -25,10 +25,11 @@ defmodule Postgrex.Protocol do
25
25
custom = opts [ :extensions ] || [ ]
26
26
extensions = custom ++ @ default_extensions
27
27
ssl? = opts [ :ssl ] || false
28
+ types? = opts [ :types ] || true
28
29
29
30
s = % { sock: nil , backend_key: nil , types: nil , timeout: timeout }
30
31
31
- types_key = { host , port , Keyword . fetch! ( opts , :database ) , custom }
32
+ types_key = if types? , do: { host , port , Keyword . fetch! ( opts , :database ) , custom }
32
33
status = % { opts: opts , parameters: % { } , notifications: [ ] ,
33
34
types_key: types_key , types_ref: nil , extensions: extensions ,
34
35
extension_info: nil }
@@ -54,6 +55,15 @@ defmodule Postgrex.Protocol do
54
55
activate ( sock , buffer )
55
56
end
56
57
58
+ @ spec simple_query ( state , String . t , binary | :active_once ) ::
59
+ { :ok , Postgrex.Result . t | Postgrex.Error . t , parameters , notifications ,
60
+ binary } |
61
+ { :error , Postgrex.Error . t }
62
+ def simple_query ( s , statement , buffer ) do
63
+ status = % { parameters: % { } , notifications: [ ] , ok: :result , sync: :sync }
64
+ simple_send ( s , status , statement , buffer )
65
+ end
66
+
57
67
@ spec query ( state , String . t , [ any ] , binary | :active_once ) ::
58
68
{ :ok , Postgrex.Result . t | Postgrex.Error . t |
59
69
{ :error | :throw | :exit , any , list } , parameters , notifications , binary } |
@@ -243,6 +253,9 @@ defmodule Postgrex.Protocol do
243
253
244
254
## bootstrap
245
255
256
+ defp bootstrap ( s , % { types_key: nil } = status , buffer ) do
257
+ bootstrap_ready ( s , status , buffer )
258
+ end
246
259
defp bootstrap ( s , % { types_key: types_key } = status , buffer ) do
247
260
case Postgrex.TypeServer . fetch ( types_key ) do
248
261
{ :ok , table } ->
@@ -331,6 +344,30 @@ defmodule Postgrex.Protocol do
331
344
end
332
345
end
333
346
347
+ ## simple
348
+
349
+ defp simple_send ( % { sock: sock } = s , status , statement , buffer ) do
350
+ msg = msg_query ( statement: statement )
351
+ case msg_send ( msg , sock ) do
352
+ :ok -> simple_recv ( s , status , buffer )
353
+ { :error , _ } = err -> err
354
+ end
355
+ end
356
+
357
+ defp simple_recv ( s , status , buffer ) do
358
+ % { sock: sock , timeout: timeout } = s
359
+ case msg_recv ( sock , buffer , timeout ) do
360
+ { :ok , msg_command_complete ( tag: tag ) , buffer } ->
361
+ complete ( s , status , % Query { } , [ ] , tag , buffer )
362
+ { :ok , msg_error ( fields: fields ) , buffer } ->
363
+ sync_recv ( s , status , Postgrex.Error . exception ( postgres: fields ) , buffer )
364
+ { :ok , msg , buffer } ->
365
+ simple_recv ( s , handle_msg ( status , msg ) , buffer )
366
+ { :error , _ } = err ->
367
+ err
368
+ end
369
+ end
370
+
334
371
## query
335
372
336
373
defp query_encode ( s , status , query , params , buffer ) do
0 commit comments