File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,28 @@ public function streamQuery(string $query): StreamEventHandler
183183 return $ connection ->streamQuery ($ query );
184184 }
185185
186+ /**
187+ * @throws \Saraf\QB\QueryBuilder\Exceptions\DBFactoryException
188+ */
189+ public function streamQueryRaw (string $ query ): ReadableStreamInterface
190+ {
191+ $ isWrite = true ;
192+ if (str_starts_with (strtolower ($ query ), "select " )
193+ || str_starts_with (strtolower ($ query ), "show " )
194+ ) $ isWrite = false ;
195+
196+ $ bestConnections = $ this ->getBestConnection ();
197+
198+ $ connection = $ isWrite
199+ ? $ this ->writeConnections [$ bestConnections ['write ' ]]
200+ : $ this ->readConnections [$ bestConnections ['read ' ]];
201+
202+ if (!($ connection instanceof DBWorker))
203+ throw new DBFactoryException ("Connections Not Instance of Worker / Restart App " );
204+
205+ return $ connection ->streamQueryRaw ($ query );
206+ }
207+
186208 /**
187209 * @throws DBFactoryException
188210 */
Original file line number Diff line number Diff line change @@ -40,6 +40,11 @@ public function streamQuery(string $query): StreamEventHandler
4040 }));
4141 }
4242
43+ public function streamQueryRaw (string $ query ): ReadableStreamInterface
44+ {
45+ return $ this ->connection ->queryStream ($ query );
46+ }
47+
4348 protected function handleResult (QueryResult $ result ): array
4449 {
4550 if (!is_null ($ result ->resultRows )) {
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ public function stream(): StreamEventHandler
3636 return $ this ->factory ->streamQuery ($ this ->query );
3737 }
3838
39+ public function streamRaw (): ReadableStreamInterface
40+ {
41+ return $ this ->factory ->streamQueryRaw ($ this ->query );
42+ }
43+
3944 public function getQuery (): Promise
4045 {
4146 return new Promise (function (callable $ resolve ) {
You can’t perform that action at this time.
0 commit comments