@@ -107,7 +107,9 @@ defmodule Feeb.DB do
107107 def one ( { domain , :fetch } , value , opts ) , do: one ( { domain , :fetch } , [ value ] , opts )
108108
109109 def one ( { domain , query_name } , bindings , opts ) when is_list ( bindings ) do
110- one ( { get_context! ( ) , domain , query_name } , bindings , opts )
110+ { get_context! ( ) , domain , query_name }
111+ |> get_query_id_for_select_query ( opts )
112+ |> one ( bindings , opts )
111113 end
112114
113115 def one ( { domain , query_name } , value , opts ) , do: one ( { domain , query_name } , [ value ] , opts )
@@ -135,13 +137,15 @@ defmodule Feeb.DB do
135137 |> all ( [ ] , opts )
136138 end
137139
138- def all ( { domain , query_name } , bindings , opts ) do
139- all ( { get_context! ( ) , domain , query_name } , bindings , opts )
140+ def all ( { domain , query_name } , bindings , opts ) when is_list ( bindings ) do
141+ { get_context! ( ) , domain , query_name }
142+ |> get_query_id_for_select_query ( opts )
143+ |> all ( bindings , opts )
140144 end
141145
142- def all ( { _ , domain , query_name } , bindings , opts ) do
143- bindings = if is_list ( bindings ) , do: bindings , else: [ bindings ]
146+ def all ( { domain , query_name } , value , opts ) , do: all ( { domain , query_name } , [ value ] , opts )
144147
148+ def all ( { _ , domain , query_name } , bindings , opts ) do
145149 case GenServer . call ( get_pid! ( ) , { :query , :all , { domain , query_name } , bindings , opts } ) do
146150 { :ok , rows } -> rows
147151 { :error , reason } -> raise reason
@@ -291,6 +295,18 @@ defmodule Feeb.DB do
291295 LocalState . get_current_context! ( ) . context
292296 end
293297
298+ defp get_query_id_for_select_query ( original_query_id , [ ] ) , do: original_query_id
299+
300+ defp get_query_id_for_select_query ( original_query_id , opts ) do
301+ target_fields = opts [ :select ] || [ :* ]
302+
303+ if target_fields == [ :* ] do
304+ original_query_id
305+ else
306+ Query . compile_adhoc_query ( original_query_id , target_fields )
307+ end
308+ end
309+
294310 defp get_bindings ( query_id , struct ) do
295311 { _ , { _ , params_bindings } , _ } = Query . fetch! ( query_id )
296312
0 commit comments