@@ -4,8 +4,11 @@ package treesql
44// this should pretty much be the same API as TreeSQLClient.js
55
66import (
7+ "fmt"
78 "log"
89
10+ "encoding/json"
11+
912 "github.com/gorilla/websocket"
1013 "github.com/pkg/errors"
1114)
@@ -100,10 +103,11 @@ func (conn *Client) handleIncoming() {
100103 defer conn .webSocketConn .Close ()
101104 for {
102105 parsedMessage := & BasicChannelMessage {}
103- err := conn .webSocketConn .ReadJSON (& parsedMessage )
106+ _ , rawMsg , err := conn .webSocketConn .ReadMessage ()
107+ json .Unmarshal (rawMsg , parsedMessage )
104108
105109 if err != nil {
106- log .Println ("error in handleIncoming:" , err )
110+ log .Println ("error in handleIncoming: ReadJSON: " , err )
107111 close (conn .incomingMessages )
108112 conn .ServerClosed <- true
109113 return
@@ -140,19 +144,22 @@ func (conn *Client) LiveQuery(query string) (*basicInitialResult, *ClientChannel
140144 if update .InitialResultMessage != nil {
141145 return update .InitialResultMessage , channel , nil
142146 }
143- return nil , nil , errors . New ("query result neither error nor initial result" )
147+ return nil , nil , fmt . Errorf ("query result neither error nor initial result" )
144148}
145149
146150func (conn * Client ) Query (query string ) (* basicInitialResult , error ) {
147151 resultChan := conn .RunStatement (query )
148152 update := <- resultChan .Updates
153+ if update == nil {
154+ return nil , fmt .Errorf ("update is nil" )
155+ }
149156 if update .ErrorMessage != nil {
150157 return nil , errors .New (* update .ErrorMessage )
151158 }
152159 if update .InitialResultMessage != nil {
153160 return update .InitialResultMessage , nil
154161 }
155- return nil , errors . New ("query result neither error nor initial result" )
162+ return nil , fmt . Errorf ("query result neither error nor initial result" )
156163}
157164
158165func (conn * Client ) Exec (statement string ) (string , error ) {
@@ -163,5 +170,5 @@ func (conn *Client) Exec(statement string) (string, error) {
163170 } else if update .AckMessage != nil {
164171 return * update .AckMessage , nil
165172 }
166- return "" , errors . New ("exec result neither error nor ack" )
173+ return "" , fmt . Errorf ("exec result neither error nor ack" )
167174}
0 commit comments