id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
152,200 | bitfinexcom/bitfinex-api-go | v1/orders.go | Cancel | func (s *OrderService) Cancel(orderID int64) error {
payload := map[string]interface{}{
"order_id": orderID,
}
req, err := s.client.newAuthenticatedRequest("POST", "order/cancel", payload)
if err != nil {
return err
}
_, err = s.client.do(req, nil)
if err != nil {
return err
}
return nil
} | go | func (s *OrderService) Cancel(orderID int64) error {
payload := map[string]interface{}{
"order_id": orderID,
}
req, err := s.client.newAuthenticatedRequest("POST", "order/cancel", payload)
if err != nil {
return err
}
_, err = s.client.do(req, nil)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"s",
"*",
"OrderService",
")",
"Cancel",
"(",
"orderID",
"int64",
")",
"error",
"{",
"payload",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"orderID",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"s",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"s",
".",
"client",
".",
"do",
"(",
"req",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Cancel the order with id `orderID`. | [
"Cancel",
"the",
"order",
"with",
"id",
"orderID",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/orders.go#L111-L127 |
152,201 | bitfinexcom/bitfinex-api-go | v1/orders.go | CreateMulti | func (s *OrderService) CreateMulti(orders []SubmitOrder) (MultipleOrderResponse, error) {
ordersMap := make([]interface{}, 0)
for _, order := range orders {
var side string
if order.Amount < 0 {
order.Amount = math.Abs(order.Amount)
side = "sell"
} else {
side = "buy"
}
ordersMap = append(ordersMap, map[string]interface{}{
"symbol": order.Symbol,
"amount": strconv.FormatFloat(order.Amount, 'f', -1, 32),
"price": strconv.FormatFloat(order.Price, 'f', -1, 32),
"exchange": "bitfinex",
"side": side,
"type": order.Type,
})
}
payload := map[string]interface{}{
"orders": ordersMap,
}
req, err := s.client.newAuthenticatedRequest("POST", "order/new/multi", payload)
if err != nil {
return MultipleOrderResponse{}, err
}
response := new(MultipleOrderResponse)
_, err = s.client.do(req, response)
return *response, err
} | go | func (s *OrderService) CreateMulti(orders []SubmitOrder) (MultipleOrderResponse, error) {
ordersMap := make([]interface{}, 0)
for _, order := range orders {
var side string
if order.Amount < 0 {
order.Amount = math.Abs(order.Amount)
side = "sell"
} else {
side = "buy"
}
ordersMap = append(ordersMap, map[string]interface{}{
"symbol": order.Symbol,
"amount": strconv.FormatFloat(order.Amount, 'f', -1, 32),
"price": strconv.FormatFloat(order.Price, 'f', -1, 32),
"exchange": "bitfinex",
"side": side,
"type": order.Type,
})
}
payload := map[string]interface{}{
"orders": ordersMap,
}
req, err := s.client.newAuthenticatedRequest("POST", "order/new/multi", payload)
if err != nil {
return MultipleOrderResponse{}, err
}
response := new(MultipleOrderResponse)
_, err = s.client.do(req, response)
return *response, err
} | [
"func",
"(",
"s",
"*",
"OrderService",
")",
"CreateMulti",
"(",
"orders",
"[",
"]",
"SubmitOrder",
")",
"(",
"MultipleOrderResponse",
",",
"error",
")",
"{",
"ordersMap",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"0",
")",
"\n",
"for",
"_",
",",
"order",
":=",
"range",
"orders",
"{",
"var",
"side",
"string",
"\n",
"if",
"order",
".",
"Amount",
"<",
"0",
"{",
"order",
".",
"Amount",
"=",
"math",
".",
"Abs",
"(",
"order",
".",
"Amount",
")",
"\n",
"side",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"side",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"ordersMap",
"=",
"append",
"(",
"ordersMap",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"order",
".",
"Symbol",
",",
"\"",
"\"",
":",
"strconv",
".",
"FormatFloat",
"(",
"order",
".",
"Amount",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
",",
"\"",
"\"",
":",
"strconv",
".",
"FormatFloat",
"(",
"order",
".",
"Price",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"side",
",",
"\"",
"\"",
":",
"order",
".",
"Type",
",",
"}",
")",
"\n",
"}",
"\n\n",
"payload",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ordersMap",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"s",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"MultipleOrderResponse",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"response",
":=",
"new",
"(",
"MultipleOrderResponse",
")",
"\n",
"_",
",",
"err",
"=",
"s",
".",
"client",
".",
"do",
"(",
"req",
",",
"response",
")",
"\n\n",
"return",
"*",
"response",
",",
"err",
"\n\n",
"}"
] | // CreateMulti allows batch creation of orders. | [
"CreateMulti",
"allows",
"batch",
"creation",
"of",
"orders",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/orders.go#L144-L178 |
152,202 | bitfinexcom/bitfinex-api-go | v1/orders.go | CancelMulti | func (s *OrderService) CancelMulti(orderIDS []int64) (string, error) {
payload := map[string]interface{}{
"order_ids": orderIDS,
}
req, err := s.client.newAuthenticatedRequest("POST", "order/cancel/multi", payload)
if err != nil {
return "", err
}
response := make(map[string]string)
_, err = s.client.do(req, &response)
return response["result"], err
} | go | func (s *OrderService) CancelMulti(orderIDS []int64) (string, error) {
payload := map[string]interface{}{
"order_ids": orderIDS,
}
req, err := s.client.newAuthenticatedRequest("POST", "order/cancel/multi", payload)
if err != nil {
return "", err
}
response := make(map[string]string)
_, err = s.client.do(req, &response)
return response["result"], err
} | [
"func",
"(",
"s",
"*",
"OrderService",
")",
"CancelMulti",
"(",
"orderIDS",
"[",
"]",
"int64",
")",
"(",
"string",
",",
"error",
")",
"{",
"payload",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"orderIDS",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"s",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"payload",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"response",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"_",
",",
"err",
"=",
"s",
".",
"client",
".",
"do",
"(",
"req",
",",
"&",
"response",
")",
"\n\n",
"return",
"response",
"[",
"\"",
"\"",
"]",
",",
"err",
"\n",
"}"
] | // CancelMulti allows batch cancellation of orders. | [
"CancelMulti",
"allows",
"batch",
"cancellation",
"of",
"orders",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/orders.go#L181-L196 |
152,203 | bitfinexcom/bitfinex-api-go | v1/orders.go | Replace | func (s *OrderService) Replace(orderID int64, useRemaining bool, newOrder SubmitOrder) (Order, error) {
var side string
if newOrder.Amount < 0 {
newOrder.Amount = math.Abs(newOrder.Amount)
side = "sell"
} else {
side = "buy"
}
payload := map[string]interface{}{
"order_id": strconv.FormatInt(orderID, 10),
"symbol": newOrder.Symbol,
"amount": strconv.FormatFloat(newOrder.Amount, 'f', -1, 32),
"price": strconv.FormatFloat(newOrder.Price, 'f', -1, 32),
"exchange": "bitfinex",
"side": side,
"type": newOrder.Type,
"use_remaining": useRemaining,
}
req, err := s.client.newAuthenticatedRequest("POST", "order/cancel/replace", payload)
if err != nil {
return Order{}, err
}
order := new(Order)
_, err = s.client.do(req, order)
if err != nil {
return *order, err
}
return *order, nil
} | go | func (s *OrderService) Replace(orderID int64, useRemaining bool, newOrder SubmitOrder) (Order, error) {
var side string
if newOrder.Amount < 0 {
newOrder.Amount = math.Abs(newOrder.Amount)
side = "sell"
} else {
side = "buy"
}
payload := map[string]interface{}{
"order_id": strconv.FormatInt(orderID, 10),
"symbol": newOrder.Symbol,
"amount": strconv.FormatFloat(newOrder.Amount, 'f', -1, 32),
"price": strconv.FormatFloat(newOrder.Price, 'f', -1, 32),
"exchange": "bitfinex",
"side": side,
"type": newOrder.Type,
"use_remaining": useRemaining,
}
req, err := s.client.newAuthenticatedRequest("POST", "order/cancel/replace", payload)
if err != nil {
return Order{}, err
}
order := new(Order)
_, err = s.client.do(req, order)
if err != nil {
return *order, err
}
return *order, nil
} | [
"func",
"(",
"s",
"*",
"OrderService",
")",
"Replace",
"(",
"orderID",
"int64",
",",
"useRemaining",
"bool",
",",
"newOrder",
"SubmitOrder",
")",
"(",
"Order",
",",
"error",
")",
"{",
"var",
"side",
"string",
"\n",
"if",
"newOrder",
".",
"Amount",
"<",
"0",
"{",
"newOrder",
".",
"Amount",
"=",
"math",
".",
"Abs",
"(",
"newOrder",
".",
"Amount",
")",
"\n",
"side",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"side",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"payload",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"strconv",
".",
"FormatInt",
"(",
"orderID",
",",
"10",
")",
",",
"\"",
"\"",
":",
"newOrder",
".",
"Symbol",
",",
"\"",
"\"",
":",
"strconv",
".",
"FormatFloat",
"(",
"newOrder",
".",
"Amount",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
",",
"\"",
"\"",
":",
"strconv",
".",
"FormatFloat",
"(",
"newOrder",
".",
"Price",
",",
"'f'",
",",
"-",
"1",
",",
"32",
")",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"side",
",",
"\"",
"\"",
":",
"newOrder",
".",
"Type",
",",
"\"",
"\"",
":",
"useRemaining",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"s",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Order",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"order",
":=",
"new",
"(",
"Order",
")",
"\n",
"_",
",",
"err",
"=",
"s",
".",
"client",
".",
"do",
"(",
"req",
",",
"order",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"*",
"order",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"*",
"order",
",",
"nil",
"\n",
"}"
] | // Replace an Order | [
"Replace",
"an",
"Order"
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/orders.go#L199-L231 |
152,204 | bitfinexcom/bitfinex-api-go | v1/orders.go | Status | func (s *OrderService) Status(orderID int64) (Order, error) {
payload := map[string]interface{}{
"order_id": orderID,
}
req, err := s.client.newAuthenticatedRequest("POST", "order/status", payload)
if err != nil {
return Order{}, err
}
order := new(Order)
_, err = s.client.do(req, order)
if err != nil {
return *order, err
}
return *order, nil
} | go | func (s *OrderService) Status(orderID int64) (Order, error) {
payload := map[string]interface{}{
"order_id": orderID,
}
req, err := s.client.newAuthenticatedRequest("POST", "order/status", payload)
if err != nil {
return Order{}, err
}
order := new(Order)
_, err = s.client.do(req, order)
if err != nil {
return *order, err
}
return *order, nil
} | [
"func",
"(",
"s",
"*",
"OrderService",
")",
"Status",
"(",
"orderID",
"int64",
")",
"(",
"Order",
",",
"error",
")",
"{",
"payload",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"orderID",
",",
"}",
"\n\n",
"req",
",",
"err",
":=",
"s",
".",
"client",
".",
"newAuthenticatedRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"payload",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Order",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"order",
":=",
"new",
"(",
"Order",
")",
"\n",
"_",
",",
"err",
"=",
"s",
".",
"client",
".",
"do",
"(",
"req",
",",
"order",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"*",
"order",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"*",
"order",
",",
"nil",
"\n",
"}"
] | // Status retrieves the given order from the API. | [
"Status",
"retrieves",
"the",
"given",
"order",
"from",
"the",
"API",
"."
] | c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b | https://github.com/bitfinexcom/bitfinex-api-go/blob/c16c61b288fbf09bfe1b22ee0a0e66b83f6c326b/v1/orders.go#L234-L253 |
152,205 | firstrow/tcp_server | tcp_server.go | listen | func (c *Client) listen() {
c.Server.onNewClientCallback(c)
reader := bufio.NewReader(c.conn)
for {
message, err := reader.ReadString('\n')
if err != nil {
c.conn.Close()
c.Server.onClientConnectionClosed(c, err)
return
}
c.Server.onNewMessage(c, message)
}
} | go | func (c *Client) listen() {
c.Server.onNewClientCallback(c)
reader := bufio.NewReader(c.conn)
for {
message, err := reader.ReadString('\n')
if err != nil {
c.conn.Close()
c.Server.onClientConnectionClosed(c, err)
return
}
c.Server.onNewMessage(c, message)
}
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"listen",
"(",
")",
"{",
"c",
".",
"Server",
".",
"onNewClientCallback",
"(",
"c",
")",
"\n",
"reader",
":=",
"bufio",
".",
"NewReader",
"(",
"c",
".",
"conn",
")",
"\n",
"for",
"{",
"message",
",",
"err",
":=",
"reader",
".",
"ReadString",
"(",
"'\\n'",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"c",
".",
"conn",
".",
"Close",
"(",
")",
"\n",
"c",
".",
"Server",
".",
"onClientConnectionClosed",
"(",
"c",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"c",
".",
"Server",
".",
"onNewMessage",
"(",
"c",
",",
"message",
")",
"\n",
"}",
"\n",
"}"
] | // Read client data from channel | [
"Read",
"client",
"data",
"from",
"channel"
] | b7a05ff2879d47e69dadf22f9149a86544d7efeb | https://github.com/firstrow/tcp_server/blob/b7a05ff2879d47e69dadf22f9149a86544d7efeb/tcp_server.go#L26-L38 |
152,206 | firstrow/tcp_server | tcp_server.go | Send | func (c *Client) Send(message string) error {
_, err := c.conn.Write([]byte(message))
return err
} | go | func (c *Client) Send(message string) error {
_, err := c.conn.Write([]byte(message))
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Send",
"(",
"message",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"c",
".",
"conn",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"message",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Send text message to client | [
"Send",
"text",
"message",
"to",
"client"
] | b7a05ff2879d47e69dadf22f9149a86544d7efeb | https://github.com/firstrow/tcp_server/blob/b7a05ff2879d47e69dadf22f9149a86544d7efeb/tcp_server.go#L41-L44 |
152,207 | firstrow/tcp_server | tcp_server.go | SendBytes | func (c *Client) SendBytes(b []byte) error {
_, err := c.conn.Write(b)
return err
} | go | func (c *Client) SendBytes(b []byte) error {
_, err := c.conn.Write(b)
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SendBytes",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"_",
",",
"err",
":=",
"c",
".",
"conn",
".",
"Write",
"(",
"b",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Send bytes to client | [
"Send",
"bytes",
"to",
"client"
] | b7a05ff2879d47e69dadf22f9149a86544d7efeb | https://github.com/firstrow/tcp_server/blob/b7a05ff2879d47e69dadf22f9149a86544d7efeb/tcp_server.go#L47-L50 |
152,208 | firstrow/tcp_server | tcp_server.go | OnClientConnectionClosed | func (s *server) OnClientConnectionClosed(callback func(c *Client, err error)) {
s.onClientConnectionClosed = callback
} | go | func (s *server) OnClientConnectionClosed(callback func(c *Client, err error)) {
s.onClientConnectionClosed = callback
} | [
"func",
"(",
"s",
"*",
"server",
")",
"OnClientConnectionClosed",
"(",
"callback",
"func",
"(",
"c",
"*",
"Client",
",",
"err",
"error",
")",
")",
"{",
"s",
".",
"onClientConnectionClosed",
"=",
"callback",
"\n",
"}"
] | // Called right after connection closed | [
"Called",
"right",
"after",
"connection",
"closed"
] | b7a05ff2879d47e69dadf22f9149a86544d7efeb | https://github.com/firstrow/tcp_server/blob/b7a05ff2879d47e69dadf22f9149a86544d7efeb/tcp_server.go#L66-L68 |
152,209 | firstrow/tcp_server | tcp_server.go | OnNewMessage | func (s *server) OnNewMessage(callback func(c *Client, message string)) {
s.onNewMessage = callback
} | go | func (s *server) OnNewMessage(callback func(c *Client, message string)) {
s.onNewMessage = callback
} | [
"func",
"(",
"s",
"*",
"server",
")",
"OnNewMessage",
"(",
"callback",
"func",
"(",
"c",
"*",
"Client",
",",
"message",
"string",
")",
")",
"{",
"s",
".",
"onNewMessage",
"=",
"callback",
"\n",
"}"
] | // Called when Client receives new message | [
"Called",
"when",
"Client",
"receives",
"new",
"message"
] | b7a05ff2879d47e69dadf22f9149a86544d7efeb | https://github.com/firstrow/tcp_server/blob/b7a05ff2879d47e69dadf22f9149a86544d7efeb/tcp_server.go#L71-L73 |
152,210 | firstrow/tcp_server | tcp_server.go | Listen | func (s *server) Listen() {
var listener net.Listener
var err error
if s.config == nil {
listener, err = net.Listen("tcp", s.address)
} else {
listener, err = tls.Listen("tcp", s.address, s.config)
}
if err != nil {
log.Fatal("Error starting TCP server.")
}
defer listener.Close()
for {
conn, _ := listener.Accept()
client := &Client{
conn: conn,
Server: s,
}
go client.listen()
}
} | go | func (s *server) Listen() {
var listener net.Listener
var err error
if s.config == nil {
listener, err = net.Listen("tcp", s.address)
} else {
listener, err = tls.Listen("tcp", s.address, s.config)
}
if err != nil {
log.Fatal("Error starting TCP server.")
}
defer listener.Close()
for {
conn, _ := listener.Accept()
client := &Client{
conn: conn,
Server: s,
}
go client.listen()
}
} | [
"func",
"(",
"s",
"*",
"server",
")",
"Listen",
"(",
")",
"{",
"var",
"listener",
"net",
".",
"Listener",
"\n",
"var",
"err",
"error",
"\n",
"if",
"s",
".",
"config",
"==",
"nil",
"{",
"listener",
",",
"err",
"=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"s",
".",
"address",
")",
"\n",
"}",
"else",
"{",
"listener",
",",
"err",
"=",
"tls",
".",
"Listen",
"(",
"\"",
"\"",
",",
"s",
".",
"address",
",",
"s",
".",
"config",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"listener",
".",
"Close",
"(",
")",
"\n\n",
"for",
"{",
"conn",
",",
"_",
":=",
"listener",
".",
"Accept",
"(",
")",
"\n",
"client",
":=",
"&",
"Client",
"{",
"conn",
":",
"conn",
",",
"Server",
":",
"s",
",",
"}",
"\n",
"go",
"client",
".",
"listen",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // Listen starts network server | [
"Listen",
"starts",
"network",
"server"
] | b7a05ff2879d47e69dadf22f9149a86544d7efeb | https://github.com/firstrow/tcp_server/blob/b7a05ff2879d47e69dadf22f9149a86544d7efeb/tcp_server.go#L76-L97 |
152,211 | firstrow/tcp_server | tcp_server.go | New | func New(address string) *server {
log.Println("Creating server with address", address)
server := &server{
address: address,
config: nil,
}
server.OnNewClient(func(c *Client) {})
server.OnNewMessage(func(c *Client, message string) {})
server.OnClientConnectionClosed(func(c *Client, err error) {})
return server
} | go | func New(address string) *server {
log.Println("Creating server with address", address)
server := &server{
address: address,
config: nil,
}
server.OnNewClient(func(c *Client) {})
server.OnNewMessage(func(c *Client, message string) {})
server.OnClientConnectionClosed(func(c *Client, err error) {})
return server
} | [
"func",
"New",
"(",
"address",
"string",
")",
"*",
"server",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"address",
")",
"\n",
"server",
":=",
"&",
"server",
"{",
"address",
":",
"address",
",",
"config",
":",
"nil",
",",
"}",
"\n\n",
"server",
".",
"OnNewClient",
"(",
"func",
"(",
"c",
"*",
"Client",
")",
"{",
"}",
")",
"\n",
"server",
".",
"OnNewMessage",
"(",
"func",
"(",
"c",
"*",
"Client",
",",
"message",
"string",
")",
"{",
"}",
")",
"\n",
"server",
".",
"OnClientConnectionClosed",
"(",
"func",
"(",
"c",
"*",
"Client",
",",
"err",
"error",
")",
"{",
"}",
")",
"\n\n",
"return",
"server",
"\n",
"}"
] | // Creates new tcp server instance | [
"Creates",
"new",
"tcp",
"server",
"instance"
] | b7a05ff2879d47e69dadf22f9149a86544d7efeb | https://github.com/firstrow/tcp_server/blob/b7a05ff2879d47e69dadf22f9149a86544d7efeb/tcp_server.go#L100-L112 |
152,212 | rethinkdb/rethinkdb-go | cursor.go | Profile | func (c *Cursor) Profile() interface{} {
if c == nil {
return nil
}
c.mu.RLock()
defer c.mu.RUnlock()
return c.profile
} | go | func (c *Cursor) Profile() interface{} {
if c == nil {
return nil
}
c.mu.RLock()
defer c.mu.RUnlock()
return c.profile
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Profile",
"(",
")",
"interface",
"{",
"}",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"c",
".",
"profile",
"\n",
"}"
] | // Profile returns the information returned from the query profiler. | [
"Profile",
"returns",
"the",
"information",
"returned",
"from",
"the",
"query",
"profiler",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L86-L95 |
152,213 | rethinkdb/rethinkdb-go | cursor.go | Close | func (c *Cursor) Close() error {
if c == nil {
return errNilCursor
}
c.mu.Lock()
defer c.mu.Unlock()
var err error
// If cursor is already closed return immediately
closed := c.closed
if closed {
return nil
}
// Get connection and check its valid, don't need to lock as this is only
// set when the cursor is created
conn := c.conn
if conn == nil {
return nil
}
if conn.Conn == nil {
return nil
}
// Stop any unfinished queries
if !c.finished {
_, _, err = conn.Query(c.ctx, newStopQuery(c.token))
}
if c.releaseConn != nil {
if err := c.releaseConn(); err != nil {
return err
}
}
if span := opentracing.SpanFromContext(c.ctx); span != nil {
span.Finish()
}
c.closed = true
c.conn = nil
c.buffer = nil
c.responses = nil
return err
} | go | func (c *Cursor) Close() error {
if c == nil {
return errNilCursor
}
c.mu.Lock()
defer c.mu.Unlock()
var err error
// If cursor is already closed return immediately
closed := c.closed
if closed {
return nil
}
// Get connection and check its valid, don't need to lock as this is only
// set when the cursor is created
conn := c.conn
if conn == nil {
return nil
}
if conn.Conn == nil {
return nil
}
// Stop any unfinished queries
if !c.finished {
_, _, err = conn.Query(c.ctx, newStopQuery(c.token))
}
if c.releaseConn != nil {
if err := c.releaseConn(); err != nil {
return err
}
}
if span := opentracing.SpanFromContext(c.ctx); span != nil {
span.Finish()
}
c.closed = true
c.conn = nil
c.buffer = nil
c.responses = nil
return err
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"errNilCursor",
"\n",
"}",
"\n\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n\n",
"// If cursor is already closed return immediately",
"closed",
":=",
"c",
".",
"closed",
"\n",
"if",
"closed",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Get connection and check its valid, don't need to lock as this is only",
"// set when the cursor is created",
"conn",
":=",
"c",
".",
"conn",
"\n",
"if",
"conn",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"conn",
".",
"Conn",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"// Stop any unfinished queries",
"if",
"!",
"c",
".",
"finished",
"{",
"_",
",",
"_",
",",
"err",
"=",
"conn",
".",
"Query",
"(",
"c",
".",
"ctx",
",",
"newStopQuery",
"(",
"c",
".",
"token",
")",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"releaseConn",
"!=",
"nil",
"{",
"if",
"err",
":=",
"c",
".",
"releaseConn",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"span",
":=",
"opentracing",
".",
"SpanFromContext",
"(",
"c",
".",
"ctx",
")",
";",
"span",
"!=",
"nil",
"{",
"span",
".",
"Finish",
"(",
")",
"\n",
"}",
"\n\n",
"c",
".",
"closed",
"=",
"true",
"\n",
"c",
".",
"conn",
"=",
"nil",
"\n",
"c",
".",
"buffer",
"=",
"nil",
"\n",
"c",
".",
"responses",
"=",
"nil",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Close closes the cursor, preventing further enumeration. If the end is
// encountered, the cursor is closed automatically. Close is idempotent. | [
"Close",
"closes",
"the",
"cursor",
"preventing",
"further",
"enumeration",
".",
"If",
"the",
"end",
"is",
"encountered",
"the",
"cursor",
"is",
"closed",
"automatically",
".",
"Close",
"is",
"idempotent",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L124-L171 |
152,214 | rethinkdb/rethinkdb-go | cursor.go | Next | func (c *Cursor) Next(dest interface{}) bool {
if c == nil {
return false
}
c.mu.Lock()
if c.closed {
c.mu.Unlock()
return false
}
hasMore, err := c.nextLocked(dest, true)
if c.handleErrorLocked(err) != nil {
c.mu.Unlock()
c.Close()
return false
}
c.mu.Unlock()
if !hasMore {
c.Close()
}
return hasMore
} | go | func (c *Cursor) Next(dest interface{}) bool {
if c == nil {
return false
}
c.mu.Lock()
if c.closed {
c.mu.Unlock()
return false
}
hasMore, err := c.nextLocked(dest, true)
if c.handleErrorLocked(err) != nil {
c.mu.Unlock()
c.Close()
return false
}
c.mu.Unlock()
if !hasMore {
c.Close()
}
return hasMore
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Next",
"(",
"dest",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"c",
".",
"closed",
"{",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"hasMore",
",",
"err",
":=",
"c",
".",
"nextLocked",
"(",
"dest",
",",
"true",
")",
"\n",
"if",
"c",
".",
"handleErrorLocked",
"(",
"err",
")",
"!=",
"nil",
"{",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"Close",
"(",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"!",
"hasMore",
"{",
"c",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"hasMore",
"\n",
"}"
] | // Next retrieves the next document from the result set, blocking if necessary.
// This method will also automatically retrieve another batch of documents from
// the server when the current one is exhausted, or before that in background
// if possible.
//
// Next returns true if a document was successfully unmarshalled onto result,
// and false at the end of the result set or if an error happened.
// When Next returns false, the Err method should be called to verify if
// there was an error during iteration.
//
// Also note that you are able to reuse the same variable multiple times as
// `Next` zeroes the value before scanning in the result. | [
"Next",
"retrieves",
"the",
"next",
"document",
"from",
"the",
"result",
"set",
"blocking",
"if",
"necessary",
".",
"This",
"method",
"will",
"also",
"automatically",
"retrieve",
"another",
"batch",
"of",
"documents",
"from",
"the",
"server",
"when",
"the",
"current",
"one",
"is",
"exhausted",
"or",
"before",
"that",
"in",
"background",
"if",
"possible",
".",
"Next",
"returns",
"true",
"if",
"a",
"document",
"was",
"successfully",
"unmarshalled",
"onto",
"result",
"and",
"false",
"at",
"the",
"end",
"of",
"the",
"result",
"set",
"or",
"if",
"an",
"error",
"happened",
".",
"When",
"Next",
"returns",
"false",
"the",
"Err",
"method",
"should",
"be",
"called",
"to",
"verify",
"if",
"there",
"was",
"an",
"error",
"during",
"iteration",
".",
"Also",
"note",
"that",
"you",
"are",
"able",
"to",
"reuse",
"the",
"same",
"variable",
"multiple",
"times",
"as",
"Next",
"zeroes",
"the",
"value",
"before",
"scanning",
"in",
"the",
"result",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L185-L209 |
152,215 | rethinkdb/rethinkdb-go | cursor.go | Skip | func (c *Cursor) Skip() {
if c == nil {
return
}
c.mu.Lock()
defer c.mu.Unlock()
c.pendingSkips++
} | go | func (c *Cursor) Skip() {
if c == nil {
return
}
c.mu.Lock()
defer c.mu.Unlock()
c.pendingSkips++
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Skip",
"(",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"pendingSkips",
"++",
"\n",
"}"
] | // Skip progresses the cursor by one record. It is useful after a successful
// Peek to avoid duplicate decoding work. | [
"Skip",
"progresses",
"the",
"cursor",
"by",
"one",
"record",
".",
"It",
"is",
"useful",
"after",
"a",
"successful",
"Peek",
"to",
"avoid",
"duplicate",
"decoding",
"work",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L288-L296 |
152,216 | rethinkdb/rethinkdb-go | cursor.go | All | func (c *Cursor) All(result interface{}) error {
if c == nil {
return errNilCursor
}
resultv := reflect.ValueOf(result)
if resultv.Kind() != reflect.Ptr || resultv.Elem().Kind() != reflect.Slice {
panic("result argument must be a slice address")
}
slicev := resultv.Elem()
slicev = slicev.Slice(0, slicev.Cap())
elemt := slicev.Type().Elem()
i := 0
for {
if slicev.Len() == i {
elemp := reflect.New(elemt)
if !c.Next(elemp.Interface()) {
break
}
slicev = reflect.Append(slicev, elemp.Elem())
slicev = slicev.Slice(0, slicev.Cap())
} else {
if !c.Next(slicev.Index(i).Addr().Interface()) {
break
}
}
i++
}
resultv.Elem().Set(slicev.Slice(0, i))
if err := c.Err(); err != nil {
c.Close()
return err
}
if err := c.Close(); err != nil {
return err
}
return nil
} | go | func (c *Cursor) All(result interface{}) error {
if c == nil {
return errNilCursor
}
resultv := reflect.ValueOf(result)
if resultv.Kind() != reflect.Ptr || resultv.Elem().Kind() != reflect.Slice {
panic("result argument must be a slice address")
}
slicev := resultv.Elem()
slicev = slicev.Slice(0, slicev.Cap())
elemt := slicev.Type().Elem()
i := 0
for {
if slicev.Len() == i {
elemp := reflect.New(elemt)
if !c.Next(elemp.Interface()) {
break
}
slicev = reflect.Append(slicev, elemp.Elem())
slicev = slicev.Slice(0, slicev.Cap())
} else {
if !c.Next(slicev.Index(i).Addr().Interface()) {
break
}
}
i++
}
resultv.Elem().Set(slicev.Slice(0, i))
if err := c.Err(); err != nil {
c.Close()
return err
}
if err := c.Close(); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"All",
"(",
"result",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"errNilCursor",
"\n",
"}",
"\n\n",
"resultv",
":=",
"reflect",
".",
"ValueOf",
"(",
"result",
")",
"\n",
"if",
"resultv",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"||",
"resultv",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Slice",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"slicev",
":=",
"resultv",
".",
"Elem",
"(",
")",
"\n",
"slicev",
"=",
"slicev",
".",
"Slice",
"(",
"0",
",",
"slicev",
".",
"Cap",
"(",
")",
")",
"\n",
"elemt",
":=",
"slicev",
".",
"Type",
"(",
")",
".",
"Elem",
"(",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"{",
"if",
"slicev",
".",
"Len",
"(",
")",
"==",
"i",
"{",
"elemp",
":=",
"reflect",
".",
"New",
"(",
"elemt",
")",
"\n",
"if",
"!",
"c",
".",
"Next",
"(",
"elemp",
".",
"Interface",
"(",
")",
")",
"{",
"break",
"\n",
"}",
"\n",
"slicev",
"=",
"reflect",
".",
"Append",
"(",
"slicev",
",",
"elemp",
".",
"Elem",
"(",
")",
")",
"\n",
"slicev",
"=",
"slicev",
".",
"Slice",
"(",
"0",
",",
"slicev",
".",
"Cap",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"if",
"!",
"c",
".",
"Next",
"(",
"slicev",
".",
"Index",
"(",
"i",
")",
".",
"Addr",
"(",
")",
".",
"Interface",
"(",
")",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"resultv",
".",
"Elem",
"(",
")",
".",
"Set",
"(",
"slicev",
".",
"Slice",
"(",
"0",
",",
"i",
")",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"Close",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // All retrieves all documents from the result set into the provided slice
// and closes the cursor.
//
// The result argument must necessarily be the address for a slice. The slice
// may be nil or previously allocated.
//
// Also note that you are able to reuse the same variable multiple times as
// `All` zeroes the value before scanning in the result. It also attempts
// to reuse the existing slice without allocating any more space by either
// resizing or returning a selection of the slice if necessary. | [
"All",
"retrieves",
"all",
"documents",
"from",
"the",
"result",
"set",
"into",
"the",
"provided",
"slice",
"and",
"closes",
"the",
"cursor",
".",
"The",
"result",
"argument",
"must",
"necessarily",
"be",
"the",
"address",
"for",
"a",
"slice",
".",
"The",
"slice",
"may",
"be",
"nil",
"or",
"previously",
"allocated",
".",
"Also",
"note",
"that",
"you",
"are",
"able",
"to",
"reuse",
"the",
"same",
"variable",
"multiple",
"times",
"as",
"All",
"zeroes",
"the",
"value",
"before",
"scanning",
"in",
"the",
"result",
".",
"It",
"also",
"attempts",
"to",
"reuse",
"the",
"existing",
"slice",
"without",
"allocating",
"any",
"more",
"space",
"by",
"either",
"resizing",
"or",
"returning",
"a",
"selection",
"of",
"the",
"slice",
"if",
"necessary",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L359-L399 |
152,217 | rethinkdb/rethinkdb-go | cursor.go | One | func (c *Cursor) One(result interface{}) error {
if c == nil {
return errNilCursor
}
if c.IsNil() {
c.Close()
return ErrEmptyResult
}
hasResult := c.Next(result)
if err := c.Err(); err != nil {
c.Close()
return err
}
if err := c.Close(); err != nil {
return err
}
if !hasResult {
return ErrEmptyResult
}
return nil
} | go | func (c *Cursor) One(result interface{}) error {
if c == nil {
return errNilCursor
}
if c.IsNil() {
c.Close()
return ErrEmptyResult
}
hasResult := c.Next(result)
if err := c.Err(); err != nil {
c.Close()
return err
}
if err := c.Close(); err != nil {
return err
}
if !hasResult {
return ErrEmptyResult
}
return nil
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"One",
"(",
"result",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"errNilCursor",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"IsNil",
"(",
")",
"{",
"c",
".",
"Close",
"(",
")",
"\n",
"return",
"ErrEmptyResult",
"\n",
"}",
"\n\n",
"hasResult",
":=",
"c",
".",
"Next",
"(",
"result",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"Close",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"hasResult",
"{",
"return",
"ErrEmptyResult",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // One retrieves a single document from the result set into the provided
// slice and closes the cursor.
//
// Also note that you are able to reuse the same variable multiple times as
// `One` zeroes the value before scanning in the result. | [
"One",
"retrieves",
"a",
"single",
"document",
"from",
"the",
"result",
"set",
"into",
"the",
"provided",
"slice",
"and",
"closes",
"the",
"cursor",
".",
"Also",
"note",
"that",
"you",
"are",
"able",
"to",
"reuse",
"the",
"same",
"variable",
"multiple",
"times",
"as",
"One",
"zeroes",
"the",
"value",
"before",
"scanning",
"in",
"the",
"result",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L406-L432 |
152,218 | rethinkdb/rethinkdb-go | cursor.go | IsNil | func (c *Cursor) IsNil() bool {
if c == nil {
return true
}
c.mu.RLock()
defer c.mu.RUnlock()
if len(c.buffer) > 0 {
return c.buffer[0] == nil
}
if len(c.responses) > 0 {
response := c.responses[0]
if response == nil {
return true
}
if string(response) == "null" {
return true
}
return false
}
return true
} | go | func (c *Cursor) IsNil() bool {
if c == nil {
return true
}
c.mu.RLock()
defer c.mu.RUnlock()
if len(c.buffer) > 0 {
return c.buffer[0] == nil
}
if len(c.responses) > 0 {
response := c.responses[0]
if response == nil {
return true
}
if string(response) == "null" {
return true
}
return false
}
return true
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"IsNil",
"(",
")",
"bool",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"len",
"(",
"c",
".",
"buffer",
")",
">",
"0",
"{",
"return",
"c",
".",
"buffer",
"[",
"0",
"]",
"==",
"nil",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"c",
".",
"responses",
")",
">",
"0",
"{",
"response",
":=",
"c",
".",
"responses",
"[",
"0",
"]",
"\n",
"if",
"response",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"string",
"(",
"response",
")",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // IsNil tests if the current row is nil. | [
"IsNil",
"tests",
"if",
"the",
"current",
"row",
"is",
"nil",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L507-L533 |
152,219 | rethinkdb/rethinkdb-go | cursor.go | fetchMore | func (c *Cursor) fetchMore() error {
var err error
if !c.fetching {
c.fetching = true
if c.closed {
return errCursorClosed
}
q := Query{
Type: p.Query_CONTINUE,
Token: c.token,
}
c.mu.Unlock()
_, _, err = c.conn.Query(c.ctx, q)
c.mu.Lock()
}
return err
} | go | func (c *Cursor) fetchMore() error {
var err error
if !c.fetching {
c.fetching = true
if c.closed {
return errCursorClosed
}
q := Query{
Type: p.Query_CONTINUE,
Token: c.token,
}
c.mu.Unlock()
_, _, err = c.conn.Query(c.ctx, q)
c.mu.Lock()
}
return err
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"fetchMore",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"!",
"c",
".",
"fetching",
"{",
"c",
".",
"fetching",
"=",
"true",
"\n\n",
"if",
"c",
".",
"closed",
"{",
"return",
"errCursorClosed",
"\n",
"}",
"\n\n",
"q",
":=",
"Query",
"{",
"Type",
":",
"p",
".",
"Query_CONTINUE",
",",
"Token",
":",
"c",
".",
"token",
",",
"}",
"\n\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"_",
",",
"_",
",",
"err",
"=",
"c",
".",
"conn",
".",
"Query",
"(",
"c",
".",
"ctx",
",",
"q",
")",
"\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // fetchMore fetches more rows from the database.
//
// If wait is true then it will wait for the database to reply otherwise it
// will return after sending the continue query. | [
"fetchMore",
"fetches",
"more",
"rows",
"from",
"the",
"database",
".",
"If",
"wait",
"is",
"true",
"then",
"it",
"will",
"wait",
"for",
"the",
"database",
"to",
"reply",
"otherwise",
"it",
"will",
"return",
"after",
"sending",
"the",
"continue",
"query",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L539-L560 |
152,220 | rethinkdb/rethinkdb-go | cursor.go | handleError | func (c *Cursor) handleError(err error) error {
c.mu.Lock()
defer c.mu.Unlock()
return c.handleErrorLocked(err)
} | go | func (c *Cursor) handleError(err error) error {
c.mu.Lock()
defer c.mu.Unlock()
return c.handleErrorLocked(err)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"handleError",
"(",
"err",
"error",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"c",
".",
"handleErrorLocked",
"(",
"err",
")",
"\n",
"}"
] | // handleError sets the value of lastErr to err if lastErr is not yet set. | [
"handleError",
"sets",
"the",
"value",
"of",
"lastErr",
"to",
"err",
"if",
"lastErr",
"is",
"not",
"yet",
"set",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L563-L568 |
152,221 | rethinkdb/rethinkdb-go | cursor.go | extend | func (c *Cursor) extend(response *Response) {
c.mu.Lock()
defer c.mu.Unlock()
c.extendLocked(response)
} | go | func (c *Cursor) extend(response *Response) {
c.mu.Lock()
defer c.mu.Unlock()
c.extendLocked(response)
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"extend",
"(",
"response",
"*",
"Response",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"c",
".",
"extendLocked",
"(",
"response",
")",
"\n",
"}"
] | // extend adds the result of a continue query to the cursor. | [
"extend",
"adds",
"the",
"result",
"of",
"a",
"continue",
"query",
"to",
"the",
"cursor",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L579-L584 |
152,222 | rethinkdb/rethinkdb-go | cursor.go | seekCursor | func (c *Cursor) seekCursor(bufferResponse bool) error {
if c.lastErr != nil {
return c.lastErr
}
if len(c.buffer) == 0 && len(c.responses) == 0 && c.closed {
return errCursorClosed
}
// Loop over loading data, applying skips as necessary and loading more data as needed
// until either the cursor is closed or finished, or we have applied all outstanding
// skips and data is available
for {
c.applyPendingSkips(bufferResponse) // if we are buffering the responses, skip can drain from the buffer
if bufferResponse && len(c.buffer) == 0 && len(c.responses) > 0 {
if err := c.bufferNextResponse(); err != nil {
return err
}
continue // go around the loop again to re-apply pending skips
} else if len(c.buffer) == 0 && len(c.responses) == 0 && !c.finished {
// We skipped all of our data, load some more
if err := c.fetchMore(); err != nil {
return err
}
if c.closed {
return nil
}
continue // go around the loop again to re-apply pending skips
}
return nil
}
} | go | func (c *Cursor) seekCursor(bufferResponse bool) error {
if c.lastErr != nil {
return c.lastErr
}
if len(c.buffer) == 0 && len(c.responses) == 0 && c.closed {
return errCursorClosed
}
// Loop over loading data, applying skips as necessary and loading more data as needed
// until either the cursor is closed or finished, or we have applied all outstanding
// skips and data is available
for {
c.applyPendingSkips(bufferResponse) // if we are buffering the responses, skip can drain from the buffer
if bufferResponse && len(c.buffer) == 0 && len(c.responses) > 0 {
if err := c.bufferNextResponse(); err != nil {
return err
}
continue // go around the loop again to re-apply pending skips
} else if len(c.buffer) == 0 && len(c.responses) == 0 && !c.finished {
// We skipped all of our data, load some more
if err := c.fetchMore(); err != nil {
return err
}
if c.closed {
return nil
}
continue // go around the loop again to re-apply pending skips
}
return nil
}
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"seekCursor",
"(",
"bufferResponse",
"bool",
")",
"error",
"{",
"if",
"c",
".",
"lastErr",
"!=",
"nil",
"{",
"return",
"c",
".",
"lastErr",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"c",
".",
"buffer",
")",
"==",
"0",
"&&",
"len",
"(",
"c",
".",
"responses",
")",
"==",
"0",
"&&",
"c",
".",
"closed",
"{",
"return",
"errCursorClosed",
"\n",
"}",
"\n\n",
"// Loop over loading data, applying skips as necessary and loading more data as needed",
"// until either the cursor is closed or finished, or we have applied all outstanding",
"// skips and data is available",
"for",
"{",
"c",
".",
"applyPendingSkips",
"(",
"bufferResponse",
")",
"// if we are buffering the responses, skip can drain from the buffer",
"\n\n",
"if",
"bufferResponse",
"&&",
"len",
"(",
"c",
".",
"buffer",
")",
"==",
"0",
"&&",
"len",
"(",
"c",
".",
"responses",
")",
">",
"0",
"{",
"if",
"err",
":=",
"c",
".",
"bufferNextResponse",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"continue",
"// go around the loop again to re-apply pending skips",
"\n",
"}",
"else",
"if",
"len",
"(",
"c",
".",
"buffer",
")",
"==",
"0",
"&&",
"len",
"(",
"c",
".",
"responses",
")",
"==",
"0",
"&&",
"!",
"c",
".",
"finished",
"{",
"// We skipped all of our data, load some more",
"if",
"err",
":=",
"c",
".",
"fetchMore",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"c",
".",
"closed",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"continue",
"// go around the loop again to re-apply pending skips",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // seekCursor takes care of loading more data if needed and applying pending skips
//
// bufferResponse determines whether the response will be parsed into the buffer | [
"seekCursor",
"takes",
"care",
"of",
"loading",
"more",
"data",
"if",
"needed",
"and",
"applying",
"pending",
"skips",
"bufferResponse",
"determines",
"whether",
"the",
"response",
"will",
"be",
"parsed",
"into",
"the",
"buffer"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L596-L628 |
152,223 | rethinkdb/rethinkdb-go | cursor.go | applyPendingSkips | func (c *Cursor) applyPendingSkips(drainFromBuffer bool) (stillPending bool) {
if c.pendingSkips == 0 {
return false
}
if drainFromBuffer {
if len(c.buffer) > c.pendingSkips {
c.buffer = c.buffer[c.pendingSkips:]
c.pendingSkips = 0
return false
}
c.pendingSkips -= len(c.buffer)
c.buffer = c.buffer[:0]
return c.pendingSkips > 0
}
if len(c.responses) > c.pendingSkips {
c.responses = c.responses[c.pendingSkips:]
c.pendingSkips = 0
return false
}
c.pendingSkips -= len(c.responses)
c.responses = c.responses[:0]
return c.pendingSkips > 0
} | go | func (c *Cursor) applyPendingSkips(drainFromBuffer bool) (stillPending bool) {
if c.pendingSkips == 0 {
return false
}
if drainFromBuffer {
if len(c.buffer) > c.pendingSkips {
c.buffer = c.buffer[c.pendingSkips:]
c.pendingSkips = 0
return false
}
c.pendingSkips -= len(c.buffer)
c.buffer = c.buffer[:0]
return c.pendingSkips > 0
}
if len(c.responses) > c.pendingSkips {
c.responses = c.responses[c.pendingSkips:]
c.pendingSkips = 0
return false
}
c.pendingSkips -= len(c.responses)
c.responses = c.responses[:0]
return c.pendingSkips > 0
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"applyPendingSkips",
"(",
"drainFromBuffer",
"bool",
")",
"(",
"stillPending",
"bool",
")",
"{",
"if",
"c",
".",
"pendingSkips",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"drainFromBuffer",
"{",
"if",
"len",
"(",
"c",
".",
"buffer",
")",
">",
"c",
".",
"pendingSkips",
"{",
"c",
".",
"buffer",
"=",
"c",
".",
"buffer",
"[",
"c",
".",
"pendingSkips",
":",
"]",
"\n",
"c",
".",
"pendingSkips",
"=",
"0",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"c",
".",
"pendingSkips",
"-=",
"len",
"(",
"c",
".",
"buffer",
")",
"\n",
"c",
".",
"buffer",
"=",
"c",
".",
"buffer",
"[",
":",
"0",
"]",
"\n",
"return",
"c",
".",
"pendingSkips",
">",
"0",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"c",
".",
"responses",
")",
">",
"c",
".",
"pendingSkips",
"{",
"c",
".",
"responses",
"=",
"c",
".",
"responses",
"[",
"c",
".",
"pendingSkips",
":",
"]",
"\n",
"c",
".",
"pendingSkips",
"=",
"0",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"c",
".",
"pendingSkips",
"-=",
"len",
"(",
"c",
".",
"responses",
")",
"\n",
"c",
".",
"responses",
"=",
"c",
".",
"responses",
"[",
":",
"0",
"]",
"\n",
"return",
"c",
".",
"pendingSkips",
">",
"0",
"\n",
"}"
] | // applyPendingSkips applies all pending skips to the buffer and
// returns whether there are more pending skips to be applied
//
// if drainFromBuffer is true, we will drain from the buffer, otherwise
// we drain from the responses | [
"applyPendingSkips",
"applies",
"all",
"pending",
"skips",
"to",
"the",
"buffer",
"and",
"returns",
"whether",
"there",
"are",
"more",
"pending",
"skips",
"to",
"be",
"applied",
"if",
"drainFromBuffer",
"is",
"true",
"we",
"will",
"drain",
"from",
"the",
"buffer",
"otherwise",
"we",
"drain",
"from",
"the",
"responses"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L635-L661 |
152,224 | rethinkdb/rethinkdb-go | cursor.go | bufferNextResponse | func (c *Cursor) bufferNextResponse() error {
if c.closed {
return errCursorClosed
}
// If there are no responses, nothing to do
if len(c.responses) == 0 {
return nil
}
response := c.responses[0]
c.responses = c.responses[1:]
var value interface{}
decoder := json.NewDecoder(bytes.NewBuffer(response))
if c.connOpts.UseJSONNumber {
decoder.UseNumber()
}
err := decoder.Decode(&value)
if err != nil {
return err
}
value, err = recursivelyConvertPseudotype(value, c.opts)
if err != nil {
return err
}
// If response is an ATOM then try and convert to an array
if data, ok := value.([]interface{}); ok && c.isAtom {
c.buffer = append(c.buffer, data...)
} else if value == nil {
c.buffer = append(c.buffer, nil)
} else {
c.buffer = append(c.buffer, value)
// If this is the only value in the response and the response was an
// atom then set the single value flag
if c.isAtom {
c.isSingleValue = true
}
}
return nil
} | go | func (c *Cursor) bufferNextResponse() error {
if c.closed {
return errCursorClosed
}
// If there are no responses, nothing to do
if len(c.responses) == 0 {
return nil
}
response := c.responses[0]
c.responses = c.responses[1:]
var value interface{}
decoder := json.NewDecoder(bytes.NewBuffer(response))
if c.connOpts.UseJSONNumber {
decoder.UseNumber()
}
err := decoder.Decode(&value)
if err != nil {
return err
}
value, err = recursivelyConvertPseudotype(value, c.opts)
if err != nil {
return err
}
// If response is an ATOM then try and convert to an array
if data, ok := value.([]interface{}); ok && c.isAtom {
c.buffer = append(c.buffer, data...)
} else if value == nil {
c.buffer = append(c.buffer, nil)
} else {
c.buffer = append(c.buffer, value)
// If this is the only value in the response and the response was an
// atom then set the single value flag
if c.isAtom {
c.isSingleValue = true
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"bufferNextResponse",
"(",
")",
"error",
"{",
"if",
"c",
".",
"closed",
"{",
"return",
"errCursorClosed",
"\n",
"}",
"\n",
"// If there are no responses, nothing to do",
"if",
"len",
"(",
"c",
".",
"responses",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"response",
":=",
"c",
".",
"responses",
"[",
"0",
"]",
"\n",
"c",
".",
"responses",
"=",
"c",
".",
"responses",
"[",
"1",
":",
"]",
"\n\n",
"var",
"value",
"interface",
"{",
"}",
"\n",
"decoder",
":=",
"json",
".",
"NewDecoder",
"(",
"bytes",
".",
"NewBuffer",
"(",
"response",
")",
")",
"\n",
"if",
"c",
".",
"connOpts",
".",
"UseJSONNumber",
"{",
"decoder",
".",
"UseNumber",
"(",
")",
"\n",
"}",
"\n",
"err",
":=",
"decoder",
".",
"Decode",
"(",
"&",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"value",
",",
"err",
"=",
"recursivelyConvertPseudotype",
"(",
"value",
",",
"c",
".",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// If response is an ATOM then try and convert to an array",
"if",
"data",
",",
"ok",
":=",
"value",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
";",
"ok",
"&&",
"c",
".",
"isAtom",
"{",
"c",
".",
"buffer",
"=",
"append",
"(",
"c",
".",
"buffer",
",",
"data",
"...",
")",
"\n",
"}",
"else",
"if",
"value",
"==",
"nil",
"{",
"c",
".",
"buffer",
"=",
"append",
"(",
"c",
".",
"buffer",
",",
"nil",
")",
"\n",
"}",
"else",
"{",
"c",
".",
"buffer",
"=",
"append",
"(",
"c",
".",
"buffer",
",",
"value",
")",
"\n\n",
"// If this is the only value in the response and the response was an",
"// atom then set the single value flag",
"if",
"c",
".",
"isAtom",
"{",
"c",
".",
"isSingleValue",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // bufferResponse reads a single response and stores the result into the buffer
// if the response is from an atomic response, it will check if the
// response contains multiple records and store them all into the buffer | [
"bufferResponse",
"reads",
"a",
"single",
"response",
"and",
"stores",
"the",
"result",
"into",
"the",
"buffer",
"if",
"the",
"response",
"is",
"from",
"an",
"atomic",
"response",
"it",
"will",
"check",
"if",
"the",
"response",
"contains",
"multiple",
"records",
"and",
"store",
"them",
"all",
"into",
"the",
"buffer"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cursor.go#L666-L708 |
152,225 | rethinkdb/rethinkdb-go | query_manipulation.go | Field | func (t Term) Field(args ...interface{}) Term {
return constructMethodTerm(t, "Field", p.Term_GET_FIELD, args, map[string]interface{}{})
} | go | func (t Term) Field(args ...interface{}) Term {
return constructMethodTerm(t, "Field", p.Term_GET_FIELD, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Field",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_GET_FIELD",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Field gets a single field from an object. If called on a sequence, gets that field
// from every object in the sequence, skipping objects that lack it. | [
"Field",
"gets",
"a",
"single",
"field",
"from",
"an",
"object",
".",
"If",
"called",
"on",
"a",
"sequence",
"gets",
"that",
"field",
"from",
"every",
"object",
"in",
"the",
"sequence",
"skipping",
"objects",
"that",
"lack",
"it",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L22-L24 |
152,226 | rethinkdb/rethinkdb-go | query_manipulation.go | Without | func (t Term) Without(args ...interface{}) Term {
return constructMethodTerm(t, "Without", p.Term_WITHOUT, args, map[string]interface{}{})
} | go | func (t Term) Without(args ...interface{}) Term {
return constructMethodTerm(t, "Without", p.Term_WITHOUT, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Without",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_WITHOUT",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Without is the opposite of pluck; takes an object or a sequence of objects, and returns
// them with the specified paths removed. | [
"Without",
"is",
"the",
"opposite",
"of",
"pluck",
";",
"takes",
"an",
"object",
"or",
"a",
"sequence",
"of",
"objects",
"and",
"returns",
"them",
"with",
"the",
"specified",
"paths",
"removed",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L41-L43 |
152,227 | rethinkdb/rethinkdb-go | query_manipulation.go | Merge | func (t Term) Merge(args ...interface{}) Term {
return constructMethodTerm(t, "Merge", p.Term_MERGE, funcWrapArgs(args), map[string]interface{}{})
} | go | func (t Term) Merge(args ...interface{}) Term {
return constructMethodTerm(t, "Merge", p.Term_MERGE, funcWrapArgs(args), map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Merge",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_MERGE",
",",
"funcWrapArgs",
"(",
"args",
")",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Merge merges two objects together to construct a new object with properties from both.
// Gives preference to attributes from other when there is a conflict. | [
"Merge",
"merges",
"two",
"objects",
"together",
"to",
"construct",
"a",
"new",
"object",
"with",
"properties",
"from",
"both",
".",
"Gives",
"preference",
"to",
"attributes",
"from",
"other",
"when",
"there",
"is",
"a",
"conflict",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L47-L49 |
152,228 | rethinkdb/rethinkdb-go | query_manipulation.go | Append | func (t Term) Append(args ...interface{}) Term {
return constructMethodTerm(t, "Append", p.Term_APPEND, args, map[string]interface{}{})
} | go | func (t Term) Append(args ...interface{}) Term {
return constructMethodTerm(t, "Append", p.Term_APPEND, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Append",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_APPEND",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Append appends a value to an array. | [
"Append",
"appends",
"a",
"value",
"to",
"an",
"array",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L52-L54 |
152,229 | rethinkdb/rethinkdb-go | query_manipulation.go | Prepend | func (t Term) Prepend(args ...interface{}) Term {
return constructMethodTerm(t, "Prepend", p.Term_PREPEND, args, map[string]interface{}{})
} | go | func (t Term) Prepend(args ...interface{}) Term {
return constructMethodTerm(t, "Prepend", p.Term_PREPEND, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Prepend",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_PREPEND",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Prepend prepends a value to an array. | [
"Prepend",
"prepends",
"a",
"value",
"to",
"an",
"array",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L57-L59 |
152,230 | rethinkdb/rethinkdb-go | query_manipulation.go | Difference | func (t Term) Difference(args ...interface{}) Term {
return constructMethodTerm(t, "Difference", p.Term_DIFFERENCE, args, map[string]interface{}{})
} | go | func (t Term) Difference(args ...interface{}) Term {
return constructMethodTerm(t, "Difference", p.Term_DIFFERENCE, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Difference",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_DIFFERENCE",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Difference removes the elements of one array from another array. | [
"Difference",
"removes",
"the",
"elements",
"of",
"one",
"array",
"from",
"another",
"array",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L62-L64 |
152,231 | rethinkdb/rethinkdb-go | query_manipulation.go | InsertAt | func (t Term) InsertAt(args ...interface{}) Term {
return constructMethodTerm(t, "InsertAt", p.Term_INSERT_AT, args, map[string]interface{}{})
} | go | func (t Term) InsertAt(args ...interface{}) Term {
return constructMethodTerm(t, "InsertAt", p.Term_INSERT_AT, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"InsertAt",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_INSERT_AT",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // InsertAt inserts a value in to an array at a given index. Returns the modified array. | [
"InsertAt",
"inserts",
"a",
"value",
"in",
"to",
"an",
"array",
"at",
"a",
"given",
"index",
".",
"Returns",
"the",
"modified",
"array",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L90-L92 |
152,232 | rethinkdb/rethinkdb-go | query_manipulation.go | SpliceAt | func (t Term) SpliceAt(args ...interface{}) Term {
return constructMethodTerm(t, "SpliceAt", p.Term_SPLICE_AT, args, map[string]interface{}{})
} | go | func (t Term) SpliceAt(args ...interface{}) Term {
return constructMethodTerm(t, "SpliceAt", p.Term_SPLICE_AT, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"SpliceAt",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_SPLICE_AT",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // SpliceAt inserts several values in to an array at a given index. Returns the modified array. | [
"SpliceAt",
"inserts",
"several",
"values",
"in",
"to",
"an",
"array",
"at",
"a",
"given",
"index",
".",
"Returns",
"the",
"modified",
"array",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L95-L97 |
152,233 | rethinkdb/rethinkdb-go | query_manipulation.go | DeleteAt | func (t Term) DeleteAt(args ...interface{}) Term {
return constructMethodTerm(t, "DeleteAt", p.Term_DELETE_AT, args, map[string]interface{}{})
} | go | func (t Term) DeleteAt(args ...interface{}) Term {
return constructMethodTerm(t, "DeleteAt", p.Term_DELETE_AT, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"DeleteAt",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_DELETE_AT",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // DeleteAt removes an element from an array at a given index. Returns the modified array. | [
"DeleteAt",
"removes",
"an",
"element",
"from",
"an",
"array",
"at",
"a",
"given",
"index",
".",
"Returns",
"the",
"modified",
"array",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L100-L102 |
152,234 | rethinkdb/rethinkdb-go | query_manipulation.go | ChangeAt | func (t Term) ChangeAt(args ...interface{}) Term {
return constructMethodTerm(t, "ChangeAt", p.Term_CHANGE_AT, args, map[string]interface{}{})
} | go | func (t Term) ChangeAt(args ...interface{}) Term {
return constructMethodTerm(t, "ChangeAt", p.Term_CHANGE_AT, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"ChangeAt",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_CHANGE_AT",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // ChangeAt changes a value in an array at a given index. Returns the modified array. | [
"ChangeAt",
"changes",
"a",
"value",
"in",
"an",
"array",
"at",
"a",
"given",
"index",
".",
"Returns",
"the",
"modified",
"array",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L105-L107 |
152,235 | rethinkdb/rethinkdb-go | query_manipulation.go | Keys | func (t Term) Keys(args ...interface{}) Term {
return constructMethodTerm(t, "Keys", p.Term_KEYS, args, map[string]interface{}{})
} | go | func (t Term) Keys(args ...interface{}) Term {
return constructMethodTerm(t, "Keys", p.Term_KEYS, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Keys",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_KEYS",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Keys returns an array containing all of the object's keys. | [
"Keys",
"returns",
"an",
"array",
"containing",
"all",
"of",
"the",
"object",
"s",
"keys",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_manipulation.go#L110-L112 |
152,236 | rethinkdb/rethinkdb-go | pseudotypes.go | reqlTimeToNativeTime | func reqlTimeToNativeTime(timestamp float64, timezone string) (time.Time, error) {
sec, ms := math.Modf(timestamp)
// Convert to native time rounding to milliseconds
t := time.Unix(int64(sec), int64(math.Floor(ms*1000+0.5))*1000*1000)
// Caclulate the timezone
if timezone != "" {
hours, err := strconv.Atoi(timezone[1:3])
if err != nil {
return time.Time{}, err
}
minutes, err := strconv.Atoi(timezone[4:6])
if err != nil {
return time.Time{}, err
}
tzOffset := ((hours * 60) + minutes) * 60
if timezone[:1] == "-" {
tzOffset = 0 - tzOffset
}
t = t.In(time.FixedZone(timezone, tzOffset))
}
return t, nil
} | go | func reqlTimeToNativeTime(timestamp float64, timezone string) (time.Time, error) {
sec, ms := math.Modf(timestamp)
// Convert to native time rounding to milliseconds
t := time.Unix(int64(sec), int64(math.Floor(ms*1000+0.5))*1000*1000)
// Caclulate the timezone
if timezone != "" {
hours, err := strconv.Atoi(timezone[1:3])
if err != nil {
return time.Time{}, err
}
minutes, err := strconv.Atoi(timezone[4:6])
if err != nil {
return time.Time{}, err
}
tzOffset := ((hours * 60) + minutes) * 60
if timezone[:1] == "-" {
tzOffset = 0 - tzOffset
}
t = t.In(time.FixedZone(timezone, tzOffset))
}
return t, nil
} | [
"func",
"reqlTimeToNativeTime",
"(",
"timestamp",
"float64",
",",
"timezone",
"string",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"sec",
",",
"ms",
":=",
"math",
".",
"Modf",
"(",
"timestamp",
")",
"\n\n",
"// Convert to native time rounding to milliseconds",
"t",
":=",
"time",
".",
"Unix",
"(",
"int64",
"(",
"sec",
")",
",",
"int64",
"(",
"math",
".",
"Floor",
"(",
"ms",
"*",
"1000",
"+",
"0.5",
")",
")",
"*",
"1000",
"*",
"1000",
")",
"\n\n",
"// Caclulate the timezone",
"if",
"timezone",
"!=",
"\"",
"\"",
"{",
"hours",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"timezone",
"[",
"1",
":",
"3",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"minutes",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"timezone",
"[",
"4",
":",
"6",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"tzOffset",
":=",
"(",
"(",
"hours",
"*",
"60",
")",
"+",
"minutes",
")",
"*",
"60",
"\n",
"if",
"timezone",
"[",
":",
"1",
"]",
"==",
"\"",
"\"",
"{",
"tzOffset",
"=",
"0",
"-",
"tzOffset",
"\n",
"}",
"\n\n",
"t",
"=",
"t",
".",
"In",
"(",
"time",
".",
"FixedZone",
"(",
"timezone",
",",
"tzOffset",
")",
")",
"\n",
"}",
"\n\n",
"return",
"t",
",",
"nil",
"\n",
"}"
] | // Pseudo-type helper functions | [
"Pseudo",
"-",
"type",
"helper",
"functions"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/pseudotypes.go#L128-L153 |
152,237 | rethinkdb/rethinkdb-go | query_write.go | Insert | func (t Term) Insert(arg interface{}, optArgs ...InsertOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Insert", p.Term_INSERT, []interface{}{Expr(arg)}, opts)
} | go | func (t Term) Insert(arg interface{}, optArgs ...InsertOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Insert", p.Term_INSERT, []interface{}{Expr(arg)}, opts)
} | [
"func",
"(",
"t",
"Term",
")",
"Insert",
"(",
"arg",
"interface",
"{",
"}",
",",
"optArgs",
"...",
"InsertOpts",
")",
"Term",
"{",
"opts",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"len",
"(",
"optArgs",
")",
">=",
"1",
"{",
"opts",
"=",
"optArgs",
"[",
"0",
"]",
".",
"toMap",
"(",
")",
"\n",
"}",
"\n",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_INSERT",
",",
"[",
"]",
"interface",
"{",
"}",
"{",
"Expr",
"(",
"arg",
")",
"}",
",",
"opts",
")",
"\n",
"}"
] | // Insert documents into a table. Accepts a single document or an array
// of documents. | [
"Insert",
"documents",
"into",
"a",
"table",
".",
"Accepts",
"a",
"single",
"document",
"or",
"an",
"array",
"of",
"documents",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_write.go#L20-L26 |
152,238 | rethinkdb/rethinkdb-go | query_write.go | Update | func (t Term) Update(arg interface{}, optArgs ...UpdateOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Update", p.Term_UPDATE, []interface{}{funcWrap(arg)}, opts)
} | go | func (t Term) Update(arg interface{}, optArgs ...UpdateOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Update", p.Term_UPDATE, []interface{}{funcWrap(arg)}, opts)
} | [
"func",
"(",
"t",
"Term",
")",
"Update",
"(",
"arg",
"interface",
"{",
"}",
",",
"optArgs",
"...",
"UpdateOpts",
")",
"Term",
"{",
"opts",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"len",
"(",
"optArgs",
")",
">=",
"1",
"{",
"opts",
"=",
"optArgs",
"[",
"0",
"]",
".",
"toMap",
"(",
")",
"\n",
"}",
"\n",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_UPDATE",
",",
"[",
"]",
"interface",
"{",
"}",
"{",
"funcWrap",
"(",
"arg",
")",
"}",
",",
"opts",
")",
"\n",
"}"
] | // Update JSON documents in a table. Accepts a JSON document, a ReQL expression,
// or a combination of the two. You can pass options like returnChanges that will
// return the old and new values of the row you have modified. | [
"Update",
"JSON",
"documents",
"in",
"a",
"table",
".",
"Accepts",
"a",
"JSON",
"document",
"a",
"ReQL",
"expression",
"or",
"a",
"combination",
"of",
"the",
"two",
".",
"You",
"can",
"pass",
"options",
"like",
"returnChanges",
"that",
"will",
"return",
"the",
"old",
"and",
"new",
"values",
"of",
"the",
"row",
"you",
"have",
"modified",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_write.go#L43-L49 |
152,239 | rethinkdb/rethinkdb-go | query_write.go | Replace | func (t Term) Replace(arg interface{}, optArgs ...ReplaceOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Replace", p.Term_REPLACE, []interface{}{funcWrap(arg)}, opts)
} | go | func (t Term) Replace(arg interface{}, optArgs ...ReplaceOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Replace", p.Term_REPLACE, []interface{}{funcWrap(arg)}, opts)
} | [
"func",
"(",
"t",
"Term",
")",
"Replace",
"(",
"arg",
"interface",
"{",
"}",
",",
"optArgs",
"...",
"ReplaceOpts",
")",
"Term",
"{",
"opts",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"len",
"(",
"optArgs",
")",
">=",
"1",
"{",
"opts",
"=",
"optArgs",
"[",
"0",
"]",
".",
"toMap",
"(",
")",
"\n",
"}",
"\n",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_REPLACE",
",",
"[",
"]",
"interface",
"{",
"}",
"{",
"funcWrap",
"(",
"arg",
")",
"}",
",",
"opts",
")",
"\n",
"}"
] | // Replace documents in a table. Accepts a JSON document or a ReQL expression,
// and replaces the original document with the new one. The new document must
// have the same primary key as the original document. | [
"Replace",
"documents",
"in",
"a",
"table",
".",
"Accepts",
"a",
"JSON",
"document",
"or",
"a",
"ReQL",
"expression",
"and",
"replaces",
"the",
"original",
"document",
"with",
"the",
"new",
"one",
".",
"The",
"new",
"document",
"must",
"have",
"the",
"same",
"primary",
"key",
"as",
"the",
"original",
"document",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_write.go#L65-L71 |
152,240 | rethinkdb/rethinkdb-go | query_write.go | Delete | func (t Term) Delete(optArgs ...DeleteOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Delete", p.Term_DELETE, []interface{}{}, opts)
} | go | func (t Term) Delete(optArgs ...DeleteOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "Delete", p.Term_DELETE, []interface{}{}, opts)
} | [
"func",
"(",
"t",
"Term",
")",
"Delete",
"(",
"optArgs",
"...",
"DeleteOpts",
")",
"Term",
"{",
"opts",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"len",
"(",
"optArgs",
")",
">=",
"1",
"{",
"opts",
"=",
"optArgs",
"[",
"0",
"]",
".",
"toMap",
"(",
")",
"\n",
"}",
"\n",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_DELETE",
",",
"[",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"opts",
")",
"\n",
"}"
] | // Delete one or more documents from a table. | [
"Delete",
"one",
"or",
"more",
"documents",
"from",
"a",
"table",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_write.go#L84-L90 |
152,241 | rethinkdb/rethinkdb-go | query_write.go | Sync | func (t Term) Sync(args ...interface{}) Term {
return constructMethodTerm(t, "Sync", p.Term_SYNC, args, map[string]interface{}{})
} | go | func (t Term) Sync(args ...interface{}) Term {
return constructMethodTerm(t, "Sync", p.Term_SYNC, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Sync",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_SYNC",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Sync ensures that writes on a given table are written to permanent storage.
// Queries that specify soft durability do not give such guarantees, so Sync
// can be used to ensure the state of these queries. A call to Sync does not
// return until all previous writes to the table are persisted. | [
"Sync",
"ensures",
"that",
"writes",
"on",
"a",
"given",
"table",
"are",
"written",
"to",
"permanent",
"storage",
".",
"Queries",
"that",
"specify",
"soft",
"durability",
"do",
"not",
"give",
"such",
"guarantees",
"so",
"Sync",
"can",
"be",
"used",
"to",
"ensure",
"the",
"state",
"of",
"these",
"queries",
".",
"A",
"call",
"to",
"Sync",
"does",
"not",
"return",
"until",
"all",
"previous",
"writes",
"to",
"the",
"table",
"are",
"persisted",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_write.go#L96-L98 |
152,242 | rethinkdb/rethinkdb-go | connection.go | NewConnection | func NewConnection(address string, opts *ConnectOpts) (*Connection, error) {
keepAlivePeriod := defaultKeepAlivePeriod
if opts.KeepAlivePeriod > 0 {
keepAlivePeriod = opts.KeepAlivePeriod
}
// Connect to Server
var err error
var conn net.Conn
nd := net.Dialer{Timeout: opts.Timeout, KeepAlive: keepAlivePeriod}
if opts.TLSConfig == nil {
conn, err = nd.Dial("tcp", address)
} else {
conn, err = tls.DialWithDialer(&nd, "tcp", address, opts.TLSConfig)
}
if err != nil {
return nil, RQLConnectionError{rqlError(err.Error())}
}
c := newConnection(conn, address, opts)
// Send handshake
handshake, err := c.handshake(opts.HandshakeVersion)
if err != nil {
return nil, err
}
if err = handshake.Send(); err != nil {
return nil, err
}
c.runConnection()
return c, nil
} | go | func NewConnection(address string, opts *ConnectOpts) (*Connection, error) {
keepAlivePeriod := defaultKeepAlivePeriod
if opts.KeepAlivePeriod > 0 {
keepAlivePeriod = opts.KeepAlivePeriod
}
// Connect to Server
var err error
var conn net.Conn
nd := net.Dialer{Timeout: opts.Timeout, KeepAlive: keepAlivePeriod}
if opts.TLSConfig == nil {
conn, err = nd.Dial("tcp", address)
} else {
conn, err = tls.DialWithDialer(&nd, "tcp", address, opts.TLSConfig)
}
if err != nil {
return nil, RQLConnectionError{rqlError(err.Error())}
}
c := newConnection(conn, address, opts)
// Send handshake
handshake, err := c.handshake(opts.HandshakeVersion)
if err != nil {
return nil, err
}
if err = handshake.Send(); err != nil {
return nil, err
}
c.runConnection()
return c, nil
} | [
"func",
"NewConnection",
"(",
"address",
"string",
",",
"opts",
"*",
"ConnectOpts",
")",
"(",
"*",
"Connection",
",",
"error",
")",
"{",
"keepAlivePeriod",
":=",
"defaultKeepAlivePeriod",
"\n",
"if",
"opts",
".",
"KeepAlivePeriod",
">",
"0",
"{",
"keepAlivePeriod",
"=",
"opts",
".",
"KeepAlivePeriod",
"\n",
"}",
"\n\n",
"// Connect to Server",
"var",
"err",
"error",
"\n",
"var",
"conn",
"net",
".",
"Conn",
"\n",
"nd",
":=",
"net",
".",
"Dialer",
"{",
"Timeout",
":",
"opts",
".",
"Timeout",
",",
"KeepAlive",
":",
"keepAlivePeriod",
"}",
"\n",
"if",
"opts",
".",
"TLSConfig",
"==",
"nil",
"{",
"conn",
",",
"err",
"=",
"nd",
".",
"Dial",
"(",
"\"",
"\"",
",",
"address",
")",
"\n",
"}",
"else",
"{",
"conn",
",",
"err",
"=",
"tls",
".",
"DialWithDialer",
"(",
"&",
"nd",
",",
"\"",
"\"",
",",
"address",
",",
"opts",
".",
"TLSConfig",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"RQLConnectionError",
"{",
"rqlError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"}",
"\n",
"}",
"\n\n",
"c",
":=",
"newConnection",
"(",
"conn",
",",
"address",
",",
"opts",
")",
"\n\n",
"// Send handshake",
"handshake",
",",
"err",
":=",
"c",
".",
"handshake",
"(",
"opts",
".",
"HandshakeVersion",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"handshake",
".",
"Send",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"runConnection",
"(",
")",
"\n\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // NewConnection creates a new connection to the database server | [
"NewConnection",
"creates",
"a",
"new",
"connection",
"to",
"the",
"database",
"server"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/connection.go#L82-L116 |
152,243 | rethinkdb/rethinkdb-go | connection.go | Close | func (c *Connection) Close() error {
var err error
c.mu.Lock()
defer c.mu.Unlock()
if !c.isClosed() {
c.setClosed()
close(c.stopReadChan)
err = c.Conn.Close()
}
return err
} | go | func (c *Connection) Close() error {
var err error
c.mu.Lock()
defer c.mu.Unlock()
if !c.isClosed() {
c.setClosed()
close(c.stopReadChan)
err = c.Conn.Close()
}
return err
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Close",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"!",
"c",
".",
"isClosed",
"(",
")",
"{",
"c",
".",
"setClosed",
"(",
")",
"\n",
"close",
"(",
"c",
".",
"stopReadChan",
")",
"\n",
"err",
"=",
"c",
".",
"Conn",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Close closes the underlying net.Conn | [
"Close",
"closes",
"the",
"underlying",
"net",
".",
"Conn"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/connection.go#L139-L152 |
152,244 | rethinkdb/rethinkdb-go | connection.go | Query | func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, error) {
if c == nil {
return nil, nil, ErrConnectionClosed
}
if c.Conn == nil || c.isClosed() {
c.setBad()
return nil, nil, ErrConnectionClosed
}
if ctx == nil {
ctx = c.contextFromConnectionOpts()
}
// Add token if query is a START/NOREPLY_WAIT
if q.Type == p.Query_START || q.Type == p.Query_NOREPLY_WAIT || q.Type == p.Query_SERVER_INFO {
q.Token = c.nextToken()
}
if q.Type == p.Query_START || q.Type == p.Query_NOREPLY_WAIT {
if c.opts.Database != "" {
var err error
q.Opts["db"], err = DB(c.opts.Database).Build()
if err != nil {
return nil, nil, RQLDriverError{rqlError(err.Error())}
}
}
}
var fetchingSpan opentracing.Span
if c.opts.UseOpentracing {
parentSpan := opentracing.SpanFromContext(ctx)
if parentSpan != nil {
if q.Type == p.Query_START {
querySpan := c.startTracingSpan(parentSpan, &q) // will be Finished when cursor closed
parentSpan = querySpan
ctx = opentracing.ContextWithSpan(ctx, querySpan)
}
fetchingSpan = c.startTracingSpan(parentSpan, &q) // will be Finished when response arrived
}
}
err := c.sendQuery(q)
if err != nil {
if fetchingSpan != nil {
ext.Error.Set(fetchingSpan, true)
fetchingSpan.LogFields(log.Error(err))
fetchingSpan.Finish()
if q.Type == p.Query_START {
opentracing.SpanFromContext(ctx).Finish()
}
}
return nil, nil, err
}
if noreply, ok := q.Opts["noreply"]; ok && noreply.(bool) {
return nil, nil, nil
}
promise := make(chan responseAndCursor, 1)
select {
case c.readRequestsChan <- tokenAndPromise{ctx: ctx, query: &q, span: fetchingSpan, promise: promise}:
case <-ctx.Done():
return c.stopQuery(&q)
}
select {
case future := <-promise:
return future.response, future.cursor, future.err
case <-ctx.Done():
return c.stopQuery(&q)
}
} | go | func (c *Connection) Query(ctx context.Context, q Query) (*Response, *Cursor, error) {
if c == nil {
return nil, nil, ErrConnectionClosed
}
if c.Conn == nil || c.isClosed() {
c.setBad()
return nil, nil, ErrConnectionClosed
}
if ctx == nil {
ctx = c.contextFromConnectionOpts()
}
// Add token if query is a START/NOREPLY_WAIT
if q.Type == p.Query_START || q.Type == p.Query_NOREPLY_WAIT || q.Type == p.Query_SERVER_INFO {
q.Token = c.nextToken()
}
if q.Type == p.Query_START || q.Type == p.Query_NOREPLY_WAIT {
if c.opts.Database != "" {
var err error
q.Opts["db"], err = DB(c.opts.Database).Build()
if err != nil {
return nil, nil, RQLDriverError{rqlError(err.Error())}
}
}
}
var fetchingSpan opentracing.Span
if c.opts.UseOpentracing {
parentSpan := opentracing.SpanFromContext(ctx)
if parentSpan != nil {
if q.Type == p.Query_START {
querySpan := c.startTracingSpan(parentSpan, &q) // will be Finished when cursor closed
parentSpan = querySpan
ctx = opentracing.ContextWithSpan(ctx, querySpan)
}
fetchingSpan = c.startTracingSpan(parentSpan, &q) // will be Finished when response arrived
}
}
err := c.sendQuery(q)
if err != nil {
if fetchingSpan != nil {
ext.Error.Set(fetchingSpan, true)
fetchingSpan.LogFields(log.Error(err))
fetchingSpan.Finish()
if q.Type == p.Query_START {
opentracing.SpanFromContext(ctx).Finish()
}
}
return nil, nil, err
}
if noreply, ok := q.Opts["noreply"]; ok && noreply.(bool) {
return nil, nil, nil
}
promise := make(chan responseAndCursor, 1)
select {
case c.readRequestsChan <- tokenAndPromise{ctx: ctx, query: &q, span: fetchingSpan, promise: promise}:
case <-ctx.Done():
return c.stopQuery(&q)
}
select {
case future := <-promise:
return future.response, future.cursor, future.err
case <-ctx.Done():
return c.stopQuery(&q)
}
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Query",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"Query",
")",
"(",
"*",
"Response",
",",
"*",
"Cursor",
",",
"error",
")",
"{",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"ErrConnectionClosed",
"\n",
"}",
"\n",
"if",
"c",
".",
"Conn",
"==",
"nil",
"||",
"c",
".",
"isClosed",
"(",
")",
"{",
"c",
".",
"setBad",
"(",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"ErrConnectionClosed",
"\n",
"}",
"\n",
"if",
"ctx",
"==",
"nil",
"{",
"ctx",
"=",
"c",
".",
"contextFromConnectionOpts",
"(",
")",
"\n",
"}",
"\n\n",
"// Add token if query is a START/NOREPLY_WAIT",
"if",
"q",
".",
"Type",
"==",
"p",
".",
"Query_START",
"||",
"q",
".",
"Type",
"==",
"p",
".",
"Query_NOREPLY_WAIT",
"||",
"q",
".",
"Type",
"==",
"p",
".",
"Query_SERVER_INFO",
"{",
"q",
".",
"Token",
"=",
"c",
".",
"nextToken",
"(",
")",
"\n",
"}",
"\n",
"if",
"q",
".",
"Type",
"==",
"p",
".",
"Query_START",
"||",
"q",
".",
"Type",
"==",
"p",
".",
"Query_NOREPLY_WAIT",
"{",
"if",
"c",
".",
"opts",
".",
"Database",
"!=",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"q",
".",
"Opts",
"[",
"\"",
"\"",
"]",
",",
"err",
"=",
"DB",
"(",
"c",
".",
"opts",
".",
"Database",
")",
".",
"Build",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"RQLDriverError",
"{",
"rqlError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"fetchingSpan",
"opentracing",
".",
"Span",
"\n",
"if",
"c",
".",
"opts",
".",
"UseOpentracing",
"{",
"parentSpan",
":=",
"opentracing",
".",
"SpanFromContext",
"(",
"ctx",
")",
"\n",
"if",
"parentSpan",
"!=",
"nil",
"{",
"if",
"q",
".",
"Type",
"==",
"p",
".",
"Query_START",
"{",
"querySpan",
":=",
"c",
".",
"startTracingSpan",
"(",
"parentSpan",
",",
"&",
"q",
")",
"// will be Finished when cursor closed",
"\n",
"parentSpan",
"=",
"querySpan",
"\n",
"ctx",
"=",
"opentracing",
".",
"ContextWithSpan",
"(",
"ctx",
",",
"querySpan",
")",
"\n",
"}",
"\n\n",
"fetchingSpan",
"=",
"c",
".",
"startTracingSpan",
"(",
"parentSpan",
",",
"&",
"q",
")",
"// will be Finished when response arrived",
"\n",
"}",
"\n",
"}",
"\n\n",
"err",
":=",
"c",
".",
"sendQuery",
"(",
"q",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"fetchingSpan",
"!=",
"nil",
"{",
"ext",
".",
"Error",
".",
"Set",
"(",
"fetchingSpan",
",",
"true",
")",
"\n",
"fetchingSpan",
".",
"LogFields",
"(",
"log",
".",
"Error",
"(",
"err",
")",
")",
"\n",
"fetchingSpan",
".",
"Finish",
"(",
")",
"\n",
"if",
"q",
".",
"Type",
"==",
"p",
".",
"Query_START",
"{",
"opentracing",
".",
"SpanFromContext",
"(",
"ctx",
")",
".",
"Finish",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"noreply",
",",
"ok",
":=",
"q",
".",
"Opts",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"noreply",
".",
"(",
"bool",
")",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"promise",
":=",
"make",
"(",
"chan",
"responseAndCursor",
",",
"1",
")",
"\n",
"select",
"{",
"case",
"c",
".",
"readRequestsChan",
"<-",
"tokenAndPromise",
"{",
"ctx",
":",
"ctx",
",",
"query",
":",
"&",
"q",
",",
"span",
":",
"fetchingSpan",
",",
"promise",
":",
"promise",
"}",
":",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"c",
".",
"stopQuery",
"(",
"&",
"q",
")",
"\n",
"}",
"\n\n",
"select",
"{",
"case",
"future",
":=",
"<-",
"promise",
":",
"return",
"future",
".",
"response",
",",
"future",
".",
"cursor",
",",
"future",
".",
"err",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"c",
".",
"stopQuery",
"(",
"&",
"q",
")",
"\n",
"}",
"\n",
"}"
] | // Query sends a Query to the database, returning both the raw Response and a
// Cursor which should be used to view the query's response.
//
// This function is used internally by Run which should be used for most queries. | [
"Query",
"sends",
"a",
"Query",
"to",
"the",
"database",
"returning",
"both",
"the",
"raw",
"Response",
"and",
"a",
"Cursor",
"which",
"should",
"be",
"used",
"to",
"view",
"the",
"query",
"s",
"response",
".",
"This",
"function",
"is",
"used",
"internally",
"by",
"Run",
"which",
"should",
"be",
"used",
"for",
"most",
"queries",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/connection.go#L158-L228 |
152,245 | rethinkdb/rethinkdb-go | connection.go | sendQuery | func (c *Connection) sendQuery(q Query) error {
buf := &bytes.Buffer{}
buf.Grow(respHeaderLen)
buf.Write(buf.Bytes()[:respHeaderLen]) // reserve for header
enc := json.NewEncoder(buf)
// Build query
err := enc.Encode(q.Build())
if err != nil {
return RQLDriverError{rqlError(fmt.Sprintf("Error building query: %s", err.Error()))}
}
b := buf.Bytes()
// Write header
binary.LittleEndian.PutUint64(b, uint64(q.Token))
binary.LittleEndian.PutUint32(b[8:], uint32(len(b)-respHeaderLen))
// Set timeout
if c.opts.WriteTimeout != 0 {
c.Conn.SetWriteDeadline(time.Now().Add(c.opts.WriteTimeout))
}
// Send the JSON encoding of the query itself.
if err = c.writeData(b); err != nil {
c.setBad()
return RQLConnectionError{rqlError(err.Error())}
}
return nil
} | go | func (c *Connection) sendQuery(q Query) error {
buf := &bytes.Buffer{}
buf.Grow(respHeaderLen)
buf.Write(buf.Bytes()[:respHeaderLen]) // reserve for header
enc := json.NewEncoder(buf)
// Build query
err := enc.Encode(q.Build())
if err != nil {
return RQLDriverError{rqlError(fmt.Sprintf("Error building query: %s", err.Error()))}
}
b := buf.Bytes()
// Write header
binary.LittleEndian.PutUint64(b, uint64(q.Token))
binary.LittleEndian.PutUint32(b[8:], uint32(len(b)-respHeaderLen))
// Set timeout
if c.opts.WriteTimeout != 0 {
c.Conn.SetWriteDeadline(time.Now().Add(c.opts.WriteTimeout))
}
// Send the JSON encoding of the query itself.
if err = c.writeData(b); err != nil {
c.setBad()
return RQLConnectionError{rqlError(err.Error())}
}
return nil
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"sendQuery",
"(",
"q",
"Query",
")",
"error",
"{",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"buf",
".",
"Grow",
"(",
"respHeaderLen",
")",
"\n",
"buf",
".",
"Write",
"(",
"buf",
".",
"Bytes",
"(",
")",
"[",
":",
"respHeaderLen",
"]",
")",
"// reserve for header",
"\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"buf",
")",
"\n\n",
"// Build query",
"err",
":=",
"enc",
".",
"Encode",
"(",
"q",
".",
"Build",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"RQLDriverError",
"{",
"rqlError",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
")",
"}",
"\n",
"}",
"\n\n",
"b",
":=",
"buf",
".",
"Bytes",
"(",
")",
"\n\n",
"// Write header",
"binary",
".",
"LittleEndian",
".",
"PutUint64",
"(",
"b",
",",
"uint64",
"(",
"q",
".",
"Token",
")",
")",
"\n",
"binary",
".",
"LittleEndian",
".",
"PutUint32",
"(",
"b",
"[",
"8",
":",
"]",
",",
"uint32",
"(",
"len",
"(",
"b",
")",
"-",
"respHeaderLen",
")",
")",
"\n\n",
"// Set timeout",
"if",
"c",
".",
"opts",
".",
"WriteTimeout",
"!=",
"0",
"{",
"c",
".",
"Conn",
".",
"SetWriteDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"c",
".",
"opts",
".",
"WriteTimeout",
")",
")",
"\n",
"}",
"\n\n",
"// Send the JSON encoding of the query itself.",
"if",
"err",
"=",
"c",
".",
"writeData",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"setBad",
"(",
")",
"\n",
"return",
"RQLConnectionError",
"{",
"rqlError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // sendQuery marshals the Query and sends the JSON to the server. | [
"sendQuery",
"marshals",
"the",
"Query",
"and",
"sends",
"the",
"JSON",
"to",
"the",
"server",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/connection.go#L363-L393 |
152,246 | rethinkdb/rethinkdb-go | connection.go | readResponse | func (c *Connection) readResponse() (*Response, error) {
// Set timeout
if c.opts.ReadTimeout != 0 {
c.Conn.SetReadDeadline(time.Now().Add(c.opts.ReadTimeout))
}
// Read response header (token+length)
headerBuf := [respHeaderLen]byte{}
if _, err := c.read(headerBuf[:]); err != nil {
c.setBad()
return nil, RQLConnectionError{rqlError(err.Error())}
}
responseToken := int64(binary.LittleEndian.Uint64(headerBuf[:8]))
messageLength := binary.LittleEndian.Uint32(headerBuf[8:])
// Read the JSON encoding of the Response itself.
b := make([]byte, int(messageLength))
if _, err := c.read(b); err != nil {
c.setBad()
return nil, RQLConnectionError{rqlError(err.Error())}
}
// Decode the response
var response = new(Response)
if err := json.Unmarshal(b, response); err != nil {
c.setBad()
return nil, RQLDriverError{rqlError(err.Error())}
}
response.Token = responseToken
return response, nil
} | go | func (c *Connection) readResponse() (*Response, error) {
// Set timeout
if c.opts.ReadTimeout != 0 {
c.Conn.SetReadDeadline(time.Now().Add(c.opts.ReadTimeout))
}
// Read response header (token+length)
headerBuf := [respHeaderLen]byte{}
if _, err := c.read(headerBuf[:]); err != nil {
c.setBad()
return nil, RQLConnectionError{rqlError(err.Error())}
}
responseToken := int64(binary.LittleEndian.Uint64(headerBuf[:8]))
messageLength := binary.LittleEndian.Uint32(headerBuf[8:])
// Read the JSON encoding of the Response itself.
b := make([]byte, int(messageLength))
if _, err := c.read(b); err != nil {
c.setBad()
return nil, RQLConnectionError{rqlError(err.Error())}
}
// Decode the response
var response = new(Response)
if err := json.Unmarshal(b, response); err != nil {
c.setBad()
return nil, RQLDriverError{rqlError(err.Error())}
}
response.Token = responseToken
return response, nil
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"readResponse",
"(",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"// Set timeout",
"if",
"c",
".",
"opts",
".",
"ReadTimeout",
"!=",
"0",
"{",
"c",
".",
"Conn",
".",
"SetReadDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"c",
".",
"opts",
".",
"ReadTimeout",
")",
")",
"\n",
"}",
"\n\n",
"// Read response header (token+length)",
"headerBuf",
":=",
"[",
"respHeaderLen",
"]",
"byte",
"{",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"c",
".",
"read",
"(",
"headerBuf",
"[",
":",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"setBad",
"(",
")",
"\n",
"return",
"nil",
",",
"RQLConnectionError",
"{",
"rqlError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"}",
"\n",
"}",
"\n\n",
"responseToken",
":=",
"int64",
"(",
"binary",
".",
"LittleEndian",
".",
"Uint64",
"(",
"headerBuf",
"[",
":",
"8",
"]",
")",
")",
"\n",
"messageLength",
":=",
"binary",
".",
"LittleEndian",
".",
"Uint32",
"(",
"headerBuf",
"[",
"8",
":",
"]",
")",
"\n\n",
"// Read the JSON encoding of the Response itself.",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"int",
"(",
"messageLength",
")",
")",
"\n\n",
"if",
"_",
",",
"err",
":=",
"c",
".",
"read",
"(",
"b",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"setBad",
"(",
")",
"\n",
"return",
"nil",
",",
"RQLConnectionError",
"{",
"rqlError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"}",
"\n",
"}",
"\n\n",
"// Decode the response",
"var",
"response",
"=",
"new",
"(",
"Response",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"response",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"setBad",
"(",
")",
"\n",
"return",
"nil",
",",
"RQLDriverError",
"{",
"rqlError",
"(",
"err",
".",
"Error",
"(",
")",
")",
"}",
"\n",
"}",
"\n",
"response",
".",
"Token",
"=",
"responseToken",
"\n\n",
"return",
"response",
",",
"nil",
"\n",
"}"
] | // readResponse attempts to read a Response from the server, if no response
// could be read then an error is returned. | [
"readResponse",
"attempts",
"to",
"read",
"a",
"Response",
"from",
"the",
"server",
"if",
"no",
"response",
"could",
"be",
"read",
"then",
"an",
"error",
"is",
"returned",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/connection.go#L404-L437 |
152,247 | rethinkdb/rethinkdb-go | connection.go | processResponse | func (c *Connection) processResponse(ctx context.Context, q Query, response *Response, span opentracing.Span) (r *Response, cur *Cursor, err error) {
if span != nil {
defer func() {
if err != nil {
ext.Error.Set(span, true)
span.LogFields(log.Error(err))
}
span.Finish()
}()
}
switch response.Type {
case p.Response_CLIENT_ERROR:
return response, c.processErrorResponse(response), createClientError(response, q.Term)
case p.Response_COMPILE_ERROR:
return response, c.processErrorResponse(response), createCompileError(response, q.Term)
case p.Response_RUNTIME_ERROR:
return response, c.processErrorResponse(response), createRuntimeError(response.ErrorType, response, q.Term)
case p.Response_SUCCESS_ATOM, p.Response_SERVER_INFO:
return c.processAtomResponse(ctx, q, response)
case p.Response_SUCCESS_PARTIAL:
return c.processPartialResponse(ctx, q, response)
case p.Response_SUCCESS_SEQUENCE:
return c.processSequenceResponse(ctx, q, response)
case p.Response_WAIT_COMPLETE:
return c.processWaitResponse(response)
default:
return nil, nil, RQLDriverError{rqlError("Unexpected response type: %v")}
}
} | go | func (c *Connection) processResponse(ctx context.Context, q Query, response *Response, span opentracing.Span) (r *Response, cur *Cursor, err error) {
if span != nil {
defer func() {
if err != nil {
ext.Error.Set(span, true)
span.LogFields(log.Error(err))
}
span.Finish()
}()
}
switch response.Type {
case p.Response_CLIENT_ERROR:
return response, c.processErrorResponse(response), createClientError(response, q.Term)
case p.Response_COMPILE_ERROR:
return response, c.processErrorResponse(response), createCompileError(response, q.Term)
case p.Response_RUNTIME_ERROR:
return response, c.processErrorResponse(response), createRuntimeError(response.ErrorType, response, q.Term)
case p.Response_SUCCESS_ATOM, p.Response_SERVER_INFO:
return c.processAtomResponse(ctx, q, response)
case p.Response_SUCCESS_PARTIAL:
return c.processPartialResponse(ctx, q, response)
case p.Response_SUCCESS_SEQUENCE:
return c.processSequenceResponse(ctx, q, response)
case p.Response_WAIT_COMPLETE:
return c.processWaitResponse(response)
default:
return nil, nil, RQLDriverError{rqlError("Unexpected response type: %v")}
}
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"processResponse",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"Query",
",",
"response",
"*",
"Response",
",",
"span",
"opentracing",
".",
"Span",
")",
"(",
"r",
"*",
"Response",
",",
"cur",
"*",
"Cursor",
",",
"err",
"error",
")",
"{",
"if",
"span",
"!=",
"nil",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"ext",
".",
"Error",
".",
"Set",
"(",
"span",
",",
"true",
")",
"\n",
"span",
".",
"LogFields",
"(",
"log",
".",
"Error",
"(",
"err",
")",
")",
"\n",
"}",
"\n",
"span",
".",
"Finish",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n\n",
"switch",
"response",
".",
"Type",
"{",
"case",
"p",
".",
"Response_CLIENT_ERROR",
":",
"return",
"response",
",",
"c",
".",
"processErrorResponse",
"(",
"response",
")",
",",
"createClientError",
"(",
"response",
",",
"q",
".",
"Term",
")",
"\n",
"case",
"p",
".",
"Response_COMPILE_ERROR",
":",
"return",
"response",
",",
"c",
".",
"processErrorResponse",
"(",
"response",
")",
",",
"createCompileError",
"(",
"response",
",",
"q",
".",
"Term",
")",
"\n",
"case",
"p",
".",
"Response_RUNTIME_ERROR",
":",
"return",
"response",
",",
"c",
".",
"processErrorResponse",
"(",
"response",
")",
",",
"createRuntimeError",
"(",
"response",
".",
"ErrorType",
",",
"response",
",",
"q",
".",
"Term",
")",
"\n",
"case",
"p",
".",
"Response_SUCCESS_ATOM",
",",
"p",
".",
"Response_SERVER_INFO",
":",
"return",
"c",
".",
"processAtomResponse",
"(",
"ctx",
",",
"q",
",",
"response",
")",
"\n",
"case",
"p",
".",
"Response_SUCCESS_PARTIAL",
":",
"return",
"c",
".",
"processPartialResponse",
"(",
"ctx",
",",
"q",
",",
"response",
")",
"\n",
"case",
"p",
".",
"Response_SUCCESS_SEQUENCE",
":",
"return",
"c",
".",
"processSequenceResponse",
"(",
"ctx",
",",
"q",
",",
"response",
")",
"\n",
"case",
"p",
".",
"Response_WAIT_COMPLETE",
":",
"return",
"c",
".",
"processWaitResponse",
"(",
"response",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"nil",
",",
"RQLDriverError",
"{",
"rqlError",
"(",
"\"",
"\"",
")",
"}",
"\n",
"}",
"\n",
"}"
] | // Called to fill response for the query | [
"Called",
"to",
"fill",
"response",
"for",
"the",
"query"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/connection.go#L440-L469 |
152,248 | rethinkdb/rethinkdb-go | query_geospatial.go | ToGeoJSON | func (t Term) ToGeoJSON(args ...interface{}) Term {
return constructMethodTerm(t, "ToGeoJSON", p.Term_TO_GEOJSON, args, map[string]interface{}{})
} | go | func (t Term) ToGeoJSON(args ...interface{}) Term {
return constructMethodTerm(t, "ToGeoJSON", p.Term_TO_GEOJSON, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"ToGeoJSON",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_TO_GEOJSON",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // ToGeoJSON converts a ReQL geometry object to a GeoJSON object. | [
"ToGeoJSON",
"converts",
"a",
"ReQL",
"geometry",
"object",
"to",
"a",
"GeoJSON",
"object",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_geospatial.go#L76-L78 |
152,249 | rethinkdb/rethinkdb-go | query_geospatial.go | GetIntersecting | func (t Term) GetIntersecting(args interface{}, optArgs ...GetIntersectingOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "GetIntersecting", p.Term_GET_INTERSECTING, []interface{}{args}, opts)
} | go | func (t Term) GetIntersecting(args interface{}, optArgs ...GetIntersectingOpts) Term {
opts := map[string]interface{}{}
if len(optArgs) >= 1 {
opts = optArgs[0].toMap()
}
return constructMethodTerm(t, "GetIntersecting", p.Term_GET_INTERSECTING, []interface{}{args}, opts)
} | [
"func",
"(",
"t",
"Term",
")",
"GetIntersecting",
"(",
"args",
"interface",
"{",
"}",
",",
"optArgs",
"...",
"GetIntersectingOpts",
")",
"Term",
"{",
"opts",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"len",
"(",
"optArgs",
")",
">=",
"1",
"{",
"opts",
"=",
"optArgs",
"[",
"0",
"]",
".",
"toMap",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_GET_INTERSECTING",
",",
"[",
"]",
"interface",
"{",
"}",
"{",
"args",
"}",
",",
"opts",
")",
"\n",
"}"
] | // GetIntersecting gets all documents where the given geometry object intersects
// the geometry object of the requested geospatial index. | [
"GetIntersecting",
"gets",
"all",
"documents",
"where",
"the",
"given",
"geometry",
"object",
"intersects",
"the",
"geometry",
"object",
"of",
"the",
"requested",
"geospatial",
"index",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_geospatial.go#L91-L98 |
152,250 | rethinkdb/rethinkdb-go | query_geospatial.go | Includes | func (t Term) Includes(args ...interface{}) Term {
return constructMethodTerm(t, "Includes", p.Term_INCLUDES, args, map[string]interface{}{})
} | go | func (t Term) Includes(args ...interface{}) Term {
return constructMethodTerm(t, "Includes", p.Term_INCLUDES, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Includes",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_INCLUDES",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Includes tests whether a geometry object is completely contained within another.
// When applied to a sequence of geometry objects, includes acts as a filter,
// returning a sequence of objects from the sequence that include the argument. | [
"Includes",
"tests",
"whether",
"a",
"geometry",
"object",
"is",
"completely",
"contained",
"within",
"another",
".",
"When",
"applied",
"to",
"a",
"sequence",
"of",
"geometry",
"objects",
"includes",
"acts",
"as",
"a",
"filter",
"returning",
"a",
"sequence",
"of",
"objects",
"from",
"the",
"sequence",
"that",
"include",
"the",
"argument",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_geospatial.go#L127-L129 |
152,251 | rethinkdb/rethinkdb-go | query_geospatial.go | Intersects | func (t Term) Intersects(args ...interface{}) Term {
return constructMethodTerm(t, "Intersects", p.Term_INTERSECTS, args, map[string]interface{}{})
} | go | func (t Term) Intersects(args ...interface{}) Term {
return constructMethodTerm(t, "Intersects", p.Term_INTERSECTS, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Intersects",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_INTERSECTS",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Intersects tests whether two geometry objects intersect with one another.
// When applied to a sequence of geometry objects, intersects acts as a filter,
// returning a sequence of objects from the sequence that intersect with the
// argument. | [
"Intersects",
"tests",
"whether",
"two",
"geometry",
"objects",
"intersect",
"with",
"one",
"another",
".",
"When",
"applied",
"to",
"a",
"sequence",
"of",
"geometry",
"objects",
"intersects",
"acts",
"as",
"a",
"filter",
"returning",
"a",
"sequence",
"of",
"objects",
"from",
"the",
"sequence",
"that",
"intersect",
"with",
"the",
"argument",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_geospatial.go#L135-L137 |
152,252 | rethinkdb/rethinkdb-go | query_select.go | Get | func (t Term) Get(args ...interface{}) Term {
return constructMethodTerm(t, "Get", p.Term_GET, args, map[string]interface{}{})
} | go | func (t Term) Get(args ...interface{}) Term {
return constructMethodTerm(t, "Get", p.Term_GET, args, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Get",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_GET",
",",
"args",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Get gets a document by primary key. If nothing was found, RethinkDB will return a nil value. | [
"Get",
"gets",
"a",
"document",
"by",
"primary",
"key",
".",
"If",
"nothing",
"was",
"found",
"RethinkDB",
"will",
"return",
"a",
"nil",
"value",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_select.go#L60-L62 |
152,253 | rethinkdb/rethinkdb-go | query_select.go | GetAll | func (t Term) GetAll(keys ...interface{}) Term {
return constructMethodTerm(t, "GetAll", p.Term_GET_ALL, keys, map[string]interface{}{})
} | go | func (t Term) GetAll(keys ...interface{}) Term {
return constructMethodTerm(t, "GetAll", p.Term_GET_ALL, keys, map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"GetAll",
"(",
"keys",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_GET_ALL",
",",
"keys",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // GetAll gets all documents where the given value matches the value of the primary
// index. Multiple values can be passed this function if you want to select multiple
// documents. If the documents you are fetching have composite keys then each
// argument should be a slice. For more information see the examples. | [
"GetAll",
"gets",
"all",
"documents",
"where",
"the",
"given",
"value",
"matches",
"the",
"value",
"of",
"the",
"primary",
"index",
".",
"Multiple",
"values",
"can",
"be",
"passed",
"this",
"function",
"if",
"you",
"want",
"to",
"select",
"multiple",
"documents",
".",
"If",
"the",
"documents",
"you",
"are",
"fetching",
"have",
"composite",
"keys",
"then",
"each",
"argument",
"should",
"be",
"a",
"slice",
".",
"For",
"more",
"information",
"see",
"the",
"examples",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_select.go#L77-L79 |
152,254 | rethinkdb/rethinkdb-go | query_select.go | GetAllByIndex | func (t Term) GetAllByIndex(index interface{}, keys ...interface{}) Term {
return constructMethodTerm(t, "GetAll", p.Term_GET_ALL, keys, map[string]interface{}{"index": index})
} | go | func (t Term) GetAllByIndex(index interface{}, keys ...interface{}) Term {
return constructMethodTerm(t, "GetAll", p.Term_GET_ALL, keys, map[string]interface{}{"index": index})
} | [
"func",
"(",
"t",
"Term",
")",
"GetAllByIndex",
"(",
"index",
"interface",
"{",
"}",
",",
"keys",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_GET_ALL",
",",
"keys",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"index",
"}",
")",
"\n",
"}"
] | // GetAllByIndex gets all documents where the given value matches the value of
// the requested index. | [
"GetAllByIndex",
"gets",
"all",
"documents",
"where",
"the",
"given",
"value",
"matches",
"the",
"value",
"of",
"the",
"requested",
"index",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_select.go#L83-L85 |
152,255 | rethinkdb/rethinkdb-go | cluster.go | NewCluster | func NewCluster(hosts []Host, opts *ConnectOpts) (*Cluster, error) {
c := &Cluster{
hp: hostpool.NewEpsilonGreedy([]string{}, opts.HostDecayDuration, &hostpool.LinearEpsilonValueCalculator{}),
seeds: hosts,
opts: opts,
}
// Attempt to connect to each host and discover any additional hosts if host
// discovery is enabled
if err := c.connectNodes(c.getSeeds()); err != nil {
return nil, err
}
if !c.IsConnected() {
return nil, ErrNoConnectionsStarted
}
if opts.DiscoverHosts {
go c.discover()
}
return c, nil
} | go | func NewCluster(hosts []Host, opts *ConnectOpts) (*Cluster, error) {
c := &Cluster{
hp: hostpool.NewEpsilonGreedy([]string{}, opts.HostDecayDuration, &hostpool.LinearEpsilonValueCalculator{}),
seeds: hosts,
opts: opts,
}
// Attempt to connect to each host and discover any additional hosts if host
// discovery is enabled
if err := c.connectNodes(c.getSeeds()); err != nil {
return nil, err
}
if !c.IsConnected() {
return nil, ErrNoConnectionsStarted
}
if opts.DiscoverHosts {
go c.discover()
}
return c, nil
} | [
"func",
"NewCluster",
"(",
"hosts",
"[",
"]",
"Host",
",",
"opts",
"*",
"ConnectOpts",
")",
"(",
"*",
"Cluster",
",",
"error",
")",
"{",
"c",
":=",
"&",
"Cluster",
"{",
"hp",
":",
"hostpool",
".",
"NewEpsilonGreedy",
"(",
"[",
"]",
"string",
"{",
"}",
",",
"opts",
".",
"HostDecayDuration",
",",
"&",
"hostpool",
".",
"LinearEpsilonValueCalculator",
"{",
"}",
")",
",",
"seeds",
":",
"hosts",
",",
"opts",
":",
"opts",
",",
"}",
"\n\n",
"// Attempt to connect to each host and discover any additional hosts if host",
"// discovery is enabled",
"if",
"err",
":=",
"c",
".",
"connectNodes",
"(",
"c",
".",
"getSeeds",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"c",
".",
"IsConnected",
"(",
")",
"{",
"return",
"nil",
",",
"ErrNoConnectionsStarted",
"\n",
"}",
"\n\n",
"if",
"opts",
".",
"DiscoverHosts",
"{",
"go",
"c",
".",
"discover",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // NewCluster creates a new cluster by connecting to the given hosts. | [
"NewCluster",
"creates",
"a",
"new",
"cluster",
"by",
"connecting",
"to",
"the",
"given",
"hosts",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cluster.go#L36-L58 |
152,256 | rethinkdb/rethinkdb-go | cluster.go | Query | func (c *Cluster) Query(ctx context.Context, q Query) (cursor *Cursor, err error) {
for i := 0; i < c.numRetries(); i++ {
var node *Node
var hpr hostpool.HostPoolResponse
node, hpr, err = c.GetNextNode()
if err != nil {
return nil, err
}
cursor, err = node.Query(ctx, q)
hpr.Mark(err)
if !shouldRetryQuery(q, err) {
break
}
}
return cursor, err
} | go | func (c *Cluster) Query(ctx context.Context, q Query) (cursor *Cursor, err error) {
for i := 0; i < c.numRetries(); i++ {
var node *Node
var hpr hostpool.HostPoolResponse
node, hpr, err = c.GetNextNode()
if err != nil {
return nil, err
}
cursor, err = node.Query(ctx, q)
hpr.Mark(err)
if !shouldRetryQuery(q, err) {
break
}
}
return cursor, err
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"Query",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"Query",
")",
"(",
"cursor",
"*",
"Cursor",
",",
"err",
"error",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"c",
".",
"numRetries",
"(",
")",
";",
"i",
"++",
"{",
"var",
"node",
"*",
"Node",
"\n",
"var",
"hpr",
"hostpool",
".",
"HostPoolResponse",
"\n\n",
"node",
",",
"hpr",
",",
"err",
"=",
"c",
".",
"GetNextNode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"cursor",
",",
"err",
"=",
"node",
".",
"Query",
"(",
"ctx",
",",
"q",
")",
"\n",
"hpr",
".",
"Mark",
"(",
"err",
")",
"\n\n",
"if",
"!",
"shouldRetryQuery",
"(",
"q",
",",
"err",
")",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"cursor",
",",
"err",
"\n",
"}"
] | // Query executes a ReQL query using the cluster to connect to the database | [
"Query",
"executes",
"a",
"ReQL",
"query",
"using",
"the",
"cluster",
"to",
"connect",
"to",
"the",
"database"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cluster.go#L61-L80 |
152,257 | rethinkdb/rethinkdb-go | cluster.go | Close | func (c *Cluster) Close(optArgs ...CloseOpts) error {
if c.closed {
return nil
}
for _, node := range c.GetNodes() {
err := node.Close(optArgs...)
if err != nil {
return err
}
}
c.hp.Close()
c.closed = true
return nil
} | go | func (c *Cluster) Close(optArgs ...CloseOpts) error {
if c.closed {
return nil
}
for _, node := range c.GetNodes() {
err := node.Close(optArgs...)
if err != nil {
return err
}
}
c.hp.Close()
c.closed = true
return nil
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"Close",
"(",
"optArgs",
"...",
"CloseOpts",
")",
"error",
"{",
"if",
"c",
".",
"closed",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"node",
":=",
"range",
"c",
".",
"GetNodes",
"(",
")",
"{",
"err",
":=",
"node",
".",
"Close",
"(",
"optArgs",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"hp",
".",
"Close",
"(",
")",
"\n",
"c",
".",
"closed",
"=",
"true",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Close closes the cluster | [
"Close",
"closes",
"the",
"cluster"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cluster.go#L150-L166 |
152,258 | rethinkdb/rethinkdb-go | cluster.go | discover | func (c *Cluster) discover() {
// Keep retrying with exponential backoff.
b := backoff.NewExponentialBackOff()
// Never finish retrying (max interval is still 60s)
b.MaxElapsedTime = 0
// Keep trying to discover new nodes
for {
backoff.RetryNotify(func() error {
// If no hosts try seeding nodes
if len(c.GetNodes()) == 0 {
c.connectNodes(c.getSeeds())
}
return c.listenForNodeChanges()
}, b, func(err error, wait time.Duration) {
Log.Debugf("Error discovering hosts %s, waiting: %s", err, wait)
})
}
} | go | func (c *Cluster) discover() {
// Keep retrying with exponential backoff.
b := backoff.NewExponentialBackOff()
// Never finish retrying (max interval is still 60s)
b.MaxElapsedTime = 0
// Keep trying to discover new nodes
for {
backoff.RetryNotify(func() error {
// If no hosts try seeding nodes
if len(c.GetNodes()) == 0 {
c.connectNodes(c.getSeeds())
}
return c.listenForNodeChanges()
}, b, func(err error, wait time.Duration) {
Log.Debugf("Error discovering hosts %s, waiting: %s", err, wait)
})
}
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"discover",
"(",
")",
"{",
"// Keep retrying with exponential backoff.",
"b",
":=",
"backoff",
".",
"NewExponentialBackOff",
"(",
")",
"\n",
"// Never finish retrying (max interval is still 60s)",
"b",
".",
"MaxElapsedTime",
"=",
"0",
"\n\n",
"// Keep trying to discover new nodes",
"for",
"{",
"backoff",
".",
"RetryNotify",
"(",
"func",
"(",
")",
"error",
"{",
"// If no hosts try seeding nodes",
"if",
"len",
"(",
"c",
".",
"GetNodes",
"(",
")",
")",
"==",
"0",
"{",
"c",
".",
"connectNodes",
"(",
"c",
".",
"getSeeds",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"listenForNodeChanges",
"(",
")",
"\n",
"}",
",",
"b",
",",
"func",
"(",
"err",
"error",
",",
"wait",
"time",
".",
"Duration",
")",
"{",
"Log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
",",
"wait",
")",
"\n",
"}",
")",
"\n",
"}",
"\n",
"}"
] | // discover attempts to find new nodes in the cluster using the current nodes | [
"discover",
"attempts",
"to",
"find",
"new",
"nodes",
"in",
"the",
"cluster",
"using",
"the",
"current",
"nodes"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cluster.go#L169-L188 |
152,259 | rethinkdb/rethinkdb-go | cluster.go | listenForNodeChanges | func (c *Cluster) listenForNodeChanges() error {
// Start listening to changes from a random active node
node, hpr, err := c.GetNextNode()
if err != nil {
return err
}
q, err := newQuery(
DB("rethinkdb").Table("server_status").Changes(),
map[string]interface{}{},
c.opts,
)
if err != nil {
return fmt.Errorf("Error building query: %s", err)
}
cursor, err := node.Query(context.Background(), q) // no need for timeout due to Changes()
if err != nil {
hpr.Mark(err)
return err
}
// Keep reading node status updates from changefeed
var result struct {
NewVal nodeStatus `rethinkdb:"new_val"`
OldVal nodeStatus `rethinkdb:"old_val"`
}
for cursor.Next(&result) {
addr := fmt.Sprintf("%s:%d", result.NewVal.Network.Hostname, result.NewVal.Network.ReqlPort)
addr = strings.ToLower(addr)
switch result.NewVal.Status {
case "connected":
// Connect to node using exponential backoff (give up after waiting 5s)
// to give the node time to start-up.
b := backoff.NewExponentialBackOff()
b.MaxElapsedTime = time.Second * 5
backoff.Retry(func() error {
node, err := c.connectNodeWithStatus(result.NewVal)
if err == nil {
if !c.nodeExists(node) {
c.addNode(node)
Log.WithFields(logrus.Fields{
"id": node.ID,
"host": node.Host.String(),
}).Debug("Connected to node")
}
}
return err
}, b)
}
}
err = cursor.Err()
hpr.Mark(err)
return err
} | go | func (c *Cluster) listenForNodeChanges() error {
// Start listening to changes from a random active node
node, hpr, err := c.GetNextNode()
if err != nil {
return err
}
q, err := newQuery(
DB("rethinkdb").Table("server_status").Changes(),
map[string]interface{}{},
c.opts,
)
if err != nil {
return fmt.Errorf("Error building query: %s", err)
}
cursor, err := node.Query(context.Background(), q) // no need for timeout due to Changes()
if err != nil {
hpr.Mark(err)
return err
}
// Keep reading node status updates from changefeed
var result struct {
NewVal nodeStatus `rethinkdb:"new_val"`
OldVal nodeStatus `rethinkdb:"old_val"`
}
for cursor.Next(&result) {
addr := fmt.Sprintf("%s:%d", result.NewVal.Network.Hostname, result.NewVal.Network.ReqlPort)
addr = strings.ToLower(addr)
switch result.NewVal.Status {
case "connected":
// Connect to node using exponential backoff (give up after waiting 5s)
// to give the node time to start-up.
b := backoff.NewExponentialBackOff()
b.MaxElapsedTime = time.Second * 5
backoff.Retry(func() error {
node, err := c.connectNodeWithStatus(result.NewVal)
if err == nil {
if !c.nodeExists(node) {
c.addNode(node)
Log.WithFields(logrus.Fields{
"id": node.ID,
"host": node.Host.String(),
}).Debug("Connected to node")
}
}
return err
}, b)
}
}
err = cursor.Err()
hpr.Mark(err)
return err
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"listenForNodeChanges",
"(",
")",
"error",
"{",
"// Start listening to changes from a random active node",
"node",
",",
"hpr",
",",
"err",
":=",
"c",
".",
"GetNextNode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"q",
",",
"err",
":=",
"newQuery",
"(",
"DB",
"(",
"\"",
"\"",
")",
".",
"Table",
"(",
"\"",
"\"",
")",
".",
"Changes",
"(",
")",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
",",
"c",
".",
"opts",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"cursor",
",",
"err",
":=",
"node",
".",
"Query",
"(",
"context",
".",
"Background",
"(",
")",
",",
"q",
")",
"// no need for timeout due to Changes()",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"hpr",
".",
"Mark",
"(",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Keep reading node status updates from changefeed",
"var",
"result",
"struct",
"{",
"NewVal",
"nodeStatus",
"`rethinkdb:\"new_val\"`",
"\n",
"OldVal",
"nodeStatus",
"`rethinkdb:\"old_val\"`",
"\n",
"}",
"\n",
"for",
"cursor",
".",
"Next",
"(",
"&",
"result",
")",
"{",
"addr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"result",
".",
"NewVal",
".",
"Network",
".",
"Hostname",
",",
"result",
".",
"NewVal",
".",
"Network",
".",
"ReqlPort",
")",
"\n",
"addr",
"=",
"strings",
".",
"ToLower",
"(",
"addr",
")",
"\n\n",
"switch",
"result",
".",
"NewVal",
".",
"Status",
"{",
"case",
"\"",
"\"",
":",
"// Connect to node using exponential backoff (give up after waiting 5s)",
"// to give the node time to start-up.",
"b",
":=",
"backoff",
".",
"NewExponentialBackOff",
"(",
")",
"\n",
"b",
".",
"MaxElapsedTime",
"=",
"time",
".",
"Second",
"*",
"5",
"\n\n",
"backoff",
".",
"Retry",
"(",
"func",
"(",
")",
"error",
"{",
"node",
",",
"err",
":=",
"c",
".",
"connectNodeWithStatus",
"(",
"result",
".",
"NewVal",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"if",
"!",
"c",
".",
"nodeExists",
"(",
"node",
")",
"{",
"c",
".",
"addNode",
"(",
"node",
")",
"\n\n",
"Log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"node",
".",
"ID",
",",
"\"",
"\"",
":",
"node",
".",
"Host",
".",
"String",
"(",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}",
",",
"b",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"err",
"=",
"cursor",
".",
"Err",
"(",
")",
"\n",
"hpr",
".",
"Mark",
"(",
"err",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // listenForNodeChanges listens for changes to node status using change feeds.
// This function will block until the query fails | [
"listenForNodeChanges",
"listens",
"for",
"changes",
"to",
"node",
"status",
"using",
"change",
"feeds",
".",
"This",
"function",
"will",
"block",
"until",
"the",
"query",
"fails"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cluster.go#L192-L251 |
152,260 | rethinkdb/rethinkdb-go | cluster.go | AddSeeds | func (c *Cluster) AddSeeds(hosts []Host) {
c.mu.Lock()
c.seeds = append(c.seeds, hosts...)
c.mu.Unlock()
} | go | func (c *Cluster) AddSeeds(hosts []Host) {
c.mu.Lock()
c.seeds = append(c.seeds, hosts...)
c.mu.Unlock()
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"AddSeeds",
"(",
"hosts",
"[",
"]",
"Host",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"seeds",
"=",
"append",
"(",
"c",
".",
"seeds",
",",
"hosts",
"...",
")",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // AddSeeds adds new seed hosts to the cluster. | [
"AddSeeds",
"adds",
"new",
"seed",
"hosts",
"to",
"the",
"cluster",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cluster.go#L403-L407 |
152,261 | rethinkdb/rethinkdb-go | cluster.go | GetNextNode | func (c *Cluster) GetNextNode() (*Node, hostpool.HostPoolResponse, error) {
if !c.IsConnected() {
return nil, nil, ErrNoConnections
}
c.mu.RLock()
defer c.mu.RUnlock()
nodes := c.nodes
hpr := c.hp.Get()
if n, ok := nodes[hpr.Host()]; ok {
if !n.Closed() {
return n, hpr, nil
}
}
return nil, nil, ErrNoConnections
} | go | func (c *Cluster) GetNextNode() (*Node, hostpool.HostPoolResponse, error) {
if !c.IsConnected() {
return nil, nil, ErrNoConnections
}
c.mu.RLock()
defer c.mu.RUnlock()
nodes := c.nodes
hpr := c.hp.Get()
if n, ok := nodes[hpr.Host()]; ok {
if !n.Closed() {
return n, hpr, nil
}
}
return nil, nil, ErrNoConnections
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"GetNextNode",
"(",
")",
"(",
"*",
"Node",
",",
"hostpool",
".",
"HostPoolResponse",
",",
"error",
")",
"{",
"if",
"!",
"c",
".",
"IsConnected",
"(",
")",
"{",
"return",
"nil",
",",
"nil",
",",
"ErrNoConnections",
"\n",
"}",
"\n",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"nodes",
":=",
"c",
".",
"nodes",
"\n",
"hpr",
":=",
"c",
".",
"hp",
".",
"Get",
"(",
")",
"\n",
"if",
"n",
",",
"ok",
":=",
"nodes",
"[",
"hpr",
".",
"Host",
"(",
")",
"]",
";",
"ok",
"{",
"if",
"!",
"n",
".",
"Closed",
"(",
")",
"{",
"return",
"n",
",",
"hpr",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
",",
"ErrNoConnections",
"\n",
"}"
] | // GetNextNode returns a random node on the cluster | [
"GetNextNode",
"returns",
"a",
"random",
"node",
"on",
"the",
"cluster"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cluster.go#L418-L434 |
152,262 | rethinkdb/rethinkdb-go | cluster.go | GetNodes | func (c *Cluster) GetNodes() []*Node {
c.mu.RLock()
nodes := make([]*Node, 0, len(c.nodes))
for _, n := range c.nodes {
nodes = append(nodes, n)
}
c.mu.RUnlock()
return nodes
} | go | func (c *Cluster) GetNodes() []*Node {
c.mu.RLock()
nodes := make([]*Node, 0, len(c.nodes))
for _, n := range c.nodes {
nodes = append(nodes, n)
}
c.mu.RUnlock()
return nodes
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"GetNodes",
"(",
")",
"[",
"]",
"*",
"Node",
"{",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"nodes",
":=",
"make",
"(",
"[",
"]",
"*",
"Node",
",",
"0",
",",
"len",
"(",
"c",
".",
"nodes",
")",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"c",
".",
"nodes",
"{",
"nodes",
"=",
"append",
"(",
"nodes",
",",
"n",
")",
"\n",
"}",
"\n",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"nodes",
"\n",
"}"
] | // GetNodes returns a list of all nodes in the cluster | [
"GetNodes",
"returns",
"a",
"list",
"of",
"all",
"nodes",
"in",
"the",
"cluster"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/cluster.go#L437-L446 |
152,263 | rethinkdb/rethinkdb-go | session.go | IsConnected | func (s *Session) IsConnected() bool {
s.mu.RLock()
defer s.mu.RUnlock()
if s.cluster == nil || s.closed {
return false
}
return s.cluster.IsConnected()
} | go | func (s *Session) IsConnected() bool {
s.mu.RLock()
defer s.mu.RUnlock()
if s.cluster == nil || s.closed {
return false
}
return s.cluster.IsConnected()
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"IsConnected",
"(",
")",
"bool",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"cluster",
"==",
"nil",
"||",
"s",
".",
"closed",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"s",
".",
"cluster",
".",
"IsConnected",
"(",
")",
"\n",
"}"
] | // IsConnected returns true if session has a valid connection. | [
"IsConnected",
"returns",
"true",
"if",
"session",
"has",
"a",
"valid",
"connection",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/session.go#L178-L186 |
152,264 | rethinkdb/rethinkdb-go | session.go | Reconnect | func (s *Session) Reconnect(optArgs ...CloseOpts) error {
var err error
if err = s.Close(optArgs...); err != nil {
return err
}
s.mu.Lock()
s.cluster, err = NewCluster(s.hosts, s.opts)
if err != nil {
s.mu.Unlock()
return err
}
s.closed = false
s.mu.Unlock()
return nil
} | go | func (s *Session) Reconnect(optArgs ...CloseOpts) error {
var err error
if err = s.Close(optArgs...); err != nil {
return err
}
s.mu.Lock()
s.cluster, err = NewCluster(s.hosts, s.opts)
if err != nil {
s.mu.Unlock()
return err
}
s.closed = false
s.mu.Unlock()
return nil
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Reconnect",
"(",
"optArgs",
"...",
"CloseOpts",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"err",
"=",
"s",
".",
"Close",
"(",
"optArgs",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"s",
".",
"cluster",
",",
"err",
"=",
"NewCluster",
"(",
"s",
".",
"hosts",
",",
"s",
".",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"s",
".",
"closed",
"=",
"false",
"\n",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Reconnect closes and re-opens a session. | [
"Reconnect",
"closes",
"and",
"re",
"-",
"opens",
"a",
"session",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/session.go#L189-L207 |
152,265 | rethinkdb/rethinkdb-go | session.go | Use | func (s *Session) Use(database string) {
s.mu.Lock()
defer s.mu.Unlock()
s.opts.Database = database
} | go | func (s *Session) Use(database string) {
s.mu.Lock()
defer s.mu.Unlock()
s.opts.Database = database
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Use",
"(",
"database",
"string",
")",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
".",
"opts",
".",
"Database",
"=",
"database",
"\n",
"}"
] | // Use changes the default database used | [
"Use",
"changes",
"the",
"default",
"database",
"used"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/session.go#L280-L285 |
152,266 | rethinkdb/rethinkdb-go | session.go | Database | func (s *Session) Database() string {
s.mu.RLock()
defer s.mu.RUnlock()
return s.opts.Database
} | go | func (s *Session) Database() string {
s.mu.RLock()
defer s.mu.RUnlock()
return s.opts.Database
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Database",
"(",
")",
"string",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"s",
".",
"opts",
".",
"Database",
"\n",
"}"
] | // Database returns the selected database set by Use | [
"Database",
"returns",
"the",
"selected",
"database",
"set",
"by",
"Use"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/session.go#L288-L293 |
152,267 | rethinkdb/rethinkdb-go | session.go | Query | func (s *Session) Query(ctx context.Context, q Query) (*Cursor, error) {
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return nil, ErrConnectionClosed
}
return s.cluster.Query(ctx, q)
} | go | func (s *Session) Query(ctx context.Context, q Query) (*Cursor, error) {
s.mu.RLock()
defer s.mu.RUnlock()
if s.closed {
return nil, ErrConnectionClosed
}
return s.cluster.Query(ctx, q)
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"Query",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"Query",
")",
"(",
"*",
"Cursor",
",",
"error",
")",
"{",
"s",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"closed",
"{",
"return",
"nil",
",",
"ErrConnectionClosed",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"cluster",
".",
"Query",
"(",
"ctx",
",",
"q",
")",
"\n",
"}"
] | // Query executes a ReQL query using the session to connect to the database | [
"Query",
"executes",
"a",
"ReQL",
"query",
"using",
"the",
"session",
"to",
"connect",
"to",
"the",
"database"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/session.go#L296-L305 |
152,268 | rethinkdb/rethinkdb-go | session.go | SetHosts | func (s *Session) SetHosts(hosts []Host) {
s.mu.Lock()
defer s.mu.Unlock()
s.hosts = hosts
} | go | func (s *Session) SetHosts(hosts []Host) {
s.mu.Lock()
defer s.mu.Unlock()
s.hosts = hosts
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"SetHosts",
"(",
"hosts",
"[",
"]",
"Host",
")",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"s",
".",
"hosts",
"=",
"hosts",
"\n",
"}"
] | // SetHosts resets the hosts used when connecting to the RethinkDB cluster | [
"SetHosts",
"resets",
"the",
"hosts",
"used",
"when",
"connecting",
"to",
"the",
"RethinkDB",
"cluster"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/session.go#L325-L330 |
152,269 | rethinkdb/rethinkdb-go | pool.go | NewPool | func NewPool(host Host, opts *ConnectOpts) (*Pool, error) {
initialCap := opts.InitialCap
if initialCap <= 0 {
// Fallback to MaxIdle if InitialCap is zero, this should be removed
// when MaxIdle is removed
initialCap = opts.MaxIdle
}
maxOpen := opts.MaxOpen
if maxOpen <= 0 {
maxOpen = 2
}
p, err := pool.NewChannelPool(initialCap, maxOpen, func() (net.Conn, error) {
conn, err := NewConnection(host.String(), opts)
if err != nil {
return nil, err
}
return conn, err
})
if err != nil {
return nil, err
}
return &Pool{
pool: p,
host: host,
opts: opts,
}, nil
} | go | func NewPool(host Host, opts *ConnectOpts) (*Pool, error) {
initialCap := opts.InitialCap
if initialCap <= 0 {
// Fallback to MaxIdle if InitialCap is zero, this should be removed
// when MaxIdle is removed
initialCap = opts.MaxIdle
}
maxOpen := opts.MaxOpen
if maxOpen <= 0 {
maxOpen = 2
}
p, err := pool.NewChannelPool(initialCap, maxOpen, func() (net.Conn, error) {
conn, err := NewConnection(host.String(), opts)
if err != nil {
return nil, err
}
return conn, err
})
if err != nil {
return nil, err
}
return &Pool{
pool: p,
host: host,
opts: opts,
}, nil
} | [
"func",
"NewPool",
"(",
"host",
"Host",
",",
"opts",
"*",
"ConnectOpts",
")",
"(",
"*",
"Pool",
",",
"error",
")",
"{",
"initialCap",
":=",
"opts",
".",
"InitialCap",
"\n",
"if",
"initialCap",
"<=",
"0",
"{",
"// Fallback to MaxIdle if InitialCap is zero, this should be removed",
"// when MaxIdle is removed",
"initialCap",
"=",
"opts",
".",
"MaxIdle",
"\n",
"}",
"\n\n",
"maxOpen",
":=",
"opts",
".",
"MaxOpen",
"\n",
"if",
"maxOpen",
"<=",
"0",
"{",
"maxOpen",
"=",
"2",
"\n",
"}",
"\n\n",
"p",
",",
"err",
":=",
"pool",
".",
"NewChannelPool",
"(",
"initialCap",
",",
"maxOpen",
",",
"func",
"(",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"NewConnection",
"(",
"host",
".",
"String",
"(",
")",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"conn",
",",
"err",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"Pool",
"{",
"pool",
":",
"p",
",",
"host",
":",
"host",
",",
"opts",
":",
"opts",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewPool creates a new connection pool for the given host | [
"NewPool",
"creates",
"a",
"new",
"connection",
"pool",
"for",
"the",
"given",
"host"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/pool.go#L29-L59 |
152,270 | rethinkdb/rethinkdb-go | pool.go | Close | func (p *Pool) Close() error {
p.mu.RLock()
defer p.mu.RUnlock()
if p.closed {
return nil
}
p.pool.Close()
return nil
} | go | func (p *Pool) Close() error {
p.mu.RLock()
defer p.mu.RUnlock()
if p.closed {
return nil
}
p.pool.Close()
return nil
} | [
"func",
"(",
"p",
"*",
"Pool",
")",
"Close",
"(",
")",
"error",
"{",
"p",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"if",
"p",
".",
"closed",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"p",
".",
"pool",
".",
"Close",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Close closes the database, releasing any open resources.
//
// It is rare to Close a Pool, as the Pool handle is meant to be
// long-lived and shared between many goroutines. | [
"Close",
"closes",
"the",
"database",
"releasing",
"any",
"open",
"resources",
".",
"It",
"is",
"rare",
"to",
"Close",
"a",
"Pool",
"as",
"the",
"Pool",
"handle",
"is",
"meant",
"to",
"be",
"long",
"-",
"lived",
"and",
"shared",
"between",
"many",
"goroutines",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/pool.go#L75-L85 |
152,271 | rethinkdb/rethinkdb-go | pool.go | Exec | func (p *Pool) Exec(ctx context.Context, q Query) error {
c, pc, err := p.conn()
if err != nil {
return err
}
defer pc.Close()
_, _, err = c.Query(ctx, q)
if c.isBad() {
pc.MarkUnusable()
}
return err
} | go | func (p *Pool) Exec(ctx context.Context, q Query) error {
c, pc, err := p.conn()
if err != nil {
return err
}
defer pc.Close()
_, _, err = c.Query(ctx, q)
if c.isBad() {
pc.MarkUnusable()
}
return err
} | [
"func",
"(",
"p",
"*",
"Pool",
")",
"Exec",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"Query",
")",
"error",
"{",
"c",
",",
"pc",
",",
"err",
":=",
"p",
".",
"conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"pc",
".",
"Close",
"(",
")",
"\n\n",
"_",
",",
"_",
",",
"err",
"=",
"c",
".",
"Query",
"(",
"ctx",
",",
"q",
")",
"\n\n",
"if",
"c",
".",
"isBad",
"(",
")",
"{",
"pc",
".",
"MarkUnusable",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Query execution functions
// Exec executes a query without waiting for any response. | [
"Query",
"execution",
"functions",
"Exec",
"executes",
"a",
"query",
"without",
"waiting",
"for",
"any",
"response",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/pool.go#L140-L154 |
152,272 | rethinkdb/rethinkdb-go | pool.go | Query | func (p *Pool) Query(ctx context.Context, q Query) (*Cursor, error) {
c, pc, err := p.conn()
if err != nil {
return nil, err
}
_, cursor, err := c.Query(ctx, q)
if err == nil {
cursor.releaseConn = releaseConn(c, pc)
} else {
if c.isBad() {
pc.MarkUnusable()
}
pc.Close()
}
return cursor, err
} | go | func (p *Pool) Query(ctx context.Context, q Query) (*Cursor, error) {
c, pc, err := p.conn()
if err != nil {
return nil, err
}
_, cursor, err := c.Query(ctx, q)
if err == nil {
cursor.releaseConn = releaseConn(c, pc)
} else {
if c.isBad() {
pc.MarkUnusable()
}
pc.Close()
}
return cursor, err
} | [
"func",
"(",
"p",
"*",
"Pool",
")",
"Query",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"Query",
")",
"(",
"*",
"Cursor",
",",
"error",
")",
"{",
"c",
",",
"pc",
",",
"err",
":=",
"p",
".",
"conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"cursor",
",",
"err",
":=",
"c",
".",
"Query",
"(",
"ctx",
",",
"q",
")",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"cursor",
".",
"releaseConn",
"=",
"releaseConn",
"(",
"c",
",",
"pc",
")",
"\n",
"}",
"else",
"{",
"if",
"c",
".",
"isBad",
"(",
")",
"{",
"pc",
".",
"MarkUnusable",
"(",
")",
"\n",
"}",
"\n",
"pc",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"cursor",
",",
"err",
"\n",
"}"
] | // Query executes a query and waits for the response | [
"Query",
"executes",
"a",
"query",
"and",
"waits",
"for",
"the",
"response"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/pool.go#L157-L175 |
152,273 | rethinkdb/rethinkdb-go | rethinkdb.go | SetVerbose | func SetVerbose(verbose bool) {
if verbose {
Log.Level = logrus.DebugLevel
return
}
Log.Level = logrus.InfoLevel
} | go | func SetVerbose(verbose bool) {
if verbose {
Log.Level = logrus.DebugLevel
return
}
Log.Level = logrus.InfoLevel
} | [
"func",
"SetVerbose",
"(",
"verbose",
"bool",
")",
"{",
"if",
"verbose",
"{",
"Log",
".",
"Level",
"=",
"logrus",
".",
"DebugLevel",
"\n",
"return",
"\n",
"}",
"\n\n",
"Log",
".",
"Level",
"=",
"logrus",
".",
"InfoLevel",
"\n",
"}"
] | // SetVerbose allows the driver logging level to be set. If true is passed then
// the log level is set to Debug otherwise it defaults to Info. | [
"SetVerbose",
"allows",
"the",
"driver",
"logging",
"level",
"to",
"be",
"set",
".",
"If",
"true",
"is",
"passed",
"then",
"the",
"log",
"level",
"is",
"set",
"to",
"Debug",
"otherwise",
"it",
"defaults",
"to",
"Info",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/rethinkdb.go#L43-L50 |
152,274 | rethinkdb/rethinkdb-go | query.go | Build | func (t Term) Build() (interface{}, error) {
var err error
if t.lastErr != nil {
return nil, t.lastErr
}
if t.rawQuery {
return t.data, nil
}
switch t.termType {
case p.Term_DATUM:
return t.data, nil
case p.Term_MAKE_OBJ:
res := map[string]interface{}{}
for k, v := range t.optArgs {
res[k], err = v.Build()
if err != nil {
return nil, err
}
}
return res, nil
case p.Term_BINARY:
if len(t.args) == 0 {
return map[string]interface{}{
"$reql_type$": "BINARY",
"data": t.data,
}, nil
}
}
args := make([]interface{}, len(t.args))
optArgs := make(map[string]interface{}, len(t.optArgs))
for i, v := range t.args {
arg, err := v.Build()
if err != nil {
return nil, err
}
args[i] = arg
}
for k, v := range t.optArgs {
optArgs[k], err = v.Build()
if err != nil {
return nil, err
}
}
ret := []interface{}{int(t.termType)}
if len(args) > 0 {
ret = append(ret, args)
}
if len(optArgs) > 0 {
ret = append(ret, optArgs)
}
return ret, nil
} | go | func (t Term) Build() (interface{}, error) {
var err error
if t.lastErr != nil {
return nil, t.lastErr
}
if t.rawQuery {
return t.data, nil
}
switch t.termType {
case p.Term_DATUM:
return t.data, nil
case p.Term_MAKE_OBJ:
res := map[string]interface{}{}
for k, v := range t.optArgs {
res[k], err = v.Build()
if err != nil {
return nil, err
}
}
return res, nil
case p.Term_BINARY:
if len(t.args) == 0 {
return map[string]interface{}{
"$reql_type$": "BINARY",
"data": t.data,
}, nil
}
}
args := make([]interface{}, len(t.args))
optArgs := make(map[string]interface{}, len(t.optArgs))
for i, v := range t.args {
arg, err := v.Build()
if err != nil {
return nil, err
}
args[i] = arg
}
for k, v := range t.optArgs {
optArgs[k], err = v.Build()
if err != nil {
return nil, err
}
}
ret := []interface{}{int(t.termType)}
if len(args) > 0 {
ret = append(ret, args)
}
if len(optArgs) > 0 {
ret = append(ret, optArgs)
}
return ret, nil
} | [
"func",
"(",
"t",
"Term",
")",
"Build",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"t",
".",
"lastErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"t",
".",
"lastErr",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"rawQuery",
"{",
"return",
"t",
".",
"data",
",",
"nil",
"\n",
"}",
"\n\n",
"switch",
"t",
".",
"termType",
"{",
"case",
"p",
".",
"Term_DATUM",
":",
"return",
"t",
".",
"data",
",",
"nil",
"\n",
"case",
"p",
".",
"Term_MAKE_OBJ",
":",
"res",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"t",
".",
"optArgs",
"{",
"res",
"[",
"k",
"]",
",",
"err",
"=",
"v",
".",
"Build",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"case",
"p",
".",
"Term_BINARY",
":",
"if",
"len",
"(",
"t",
".",
"args",
")",
"==",
"0",
"{",
"return",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"t",
".",
"data",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"args",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"t",
".",
"args",
")",
")",
"\n",
"optArgs",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"len",
"(",
"t",
".",
"optArgs",
")",
")",
"\n\n",
"for",
"i",
",",
"v",
":=",
"range",
"t",
".",
"args",
"{",
"arg",
",",
"err",
":=",
"v",
".",
"Build",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"args",
"[",
"i",
"]",
"=",
"arg",
"\n",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"t",
".",
"optArgs",
"{",
"optArgs",
"[",
"k",
"]",
",",
"err",
"=",
"v",
".",
"Build",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"ret",
":=",
"[",
"]",
"interface",
"{",
"}",
"{",
"int",
"(",
"t",
".",
"termType",
")",
"}",
"\n\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"args",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"optArgs",
")",
">",
"0",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"optArgs",
")",
"\n",
"}",
"\n\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // build takes the query tree and prepares it to be sent as a JSON
// expression | [
"build",
"takes",
"the",
"query",
"tree",
"and",
"prepares",
"it",
"to",
"be",
"sent",
"as",
"a",
"JSON",
"expression"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query.go#L128-L188 |
152,275 | rethinkdb/rethinkdb-go | query.go | String | func (t Term) String() string {
if t.isMockAnything {
return "r.MockAnything()"
}
switch t.termType {
case p.Term_MAKE_ARRAY:
return fmt.Sprintf("[%s]", strings.Join(argsToStringSlice(t.args), ", "))
case p.Term_MAKE_OBJ:
return fmt.Sprintf("{%s}", strings.Join(optArgsToStringSlice(t.optArgs), ", "))
case p.Term_FUNC:
// Get string representation of each argument
args := []string{}
for _, v := range t.args[0].args {
args = append(args, fmt.Sprintf("var_%d", v.data))
}
return fmt.Sprintf("func(%s r.Term) r.Term { return %s }",
strings.Join(args, ", "),
t.args[1].String(),
)
case p.Term_VAR:
return fmt.Sprintf("var_%s", t.args[0])
case p.Term_IMPLICIT_VAR:
return "r.Row"
case p.Term_DATUM:
switch v := t.data.(type) {
case string:
return strconv.Quote(v)
default:
return fmt.Sprintf("%v", v)
}
case p.Term_BINARY:
if len(t.args) == 0 {
return fmt.Sprintf("r.binary(<data>)")
}
}
if t.rootTerm {
return fmt.Sprintf("r.%s(%s)", t.name, strings.Join(allArgsToStringSlice(t.args, t.optArgs), ", "))
}
if t.args == nil {
return "r"
}
return fmt.Sprintf("%s.%s(%s)", t.args[0].String(), t.name, strings.Join(allArgsToStringSlice(t.args[1:], t.optArgs), ", "))
} | go | func (t Term) String() string {
if t.isMockAnything {
return "r.MockAnything()"
}
switch t.termType {
case p.Term_MAKE_ARRAY:
return fmt.Sprintf("[%s]", strings.Join(argsToStringSlice(t.args), ", "))
case p.Term_MAKE_OBJ:
return fmt.Sprintf("{%s}", strings.Join(optArgsToStringSlice(t.optArgs), ", "))
case p.Term_FUNC:
// Get string representation of each argument
args := []string{}
for _, v := range t.args[0].args {
args = append(args, fmt.Sprintf("var_%d", v.data))
}
return fmt.Sprintf("func(%s r.Term) r.Term { return %s }",
strings.Join(args, ", "),
t.args[1].String(),
)
case p.Term_VAR:
return fmt.Sprintf("var_%s", t.args[0])
case p.Term_IMPLICIT_VAR:
return "r.Row"
case p.Term_DATUM:
switch v := t.data.(type) {
case string:
return strconv.Quote(v)
default:
return fmt.Sprintf("%v", v)
}
case p.Term_BINARY:
if len(t.args) == 0 {
return fmt.Sprintf("r.binary(<data>)")
}
}
if t.rootTerm {
return fmt.Sprintf("r.%s(%s)", t.name, strings.Join(allArgsToStringSlice(t.args, t.optArgs), ", "))
}
if t.args == nil {
return "r"
}
return fmt.Sprintf("%s.%s(%s)", t.args[0].String(), t.name, strings.Join(allArgsToStringSlice(t.args[1:], t.optArgs), ", "))
} | [
"func",
"(",
"t",
"Term",
")",
"String",
"(",
")",
"string",
"{",
"if",
"t",
".",
"isMockAnything",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"switch",
"t",
".",
"termType",
"{",
"case",
"p",
".",
"Term_MAKE_ARRAY",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"argsToStringSlice",
"(",
"t",
".",
"args",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"case",
"p",
".",
"Term_MAKE_OBJ",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"optArgsToStringSlice",
"(",
"t",
".",
"optArgs",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"case",
"p",
".",
"Term_FUNC",
":",
"// Get string representation of each argument",
"args",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"t",
".",
"args",
"[",
"0",
"]",
".",
"args",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
".",
"data",
")",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"args",
",",
"\"",
"\"",
")",
",",
"t",
".",
"args",
"[",
"1",
"]",
".",
"String",
"(",
")",
",",
")",
"\n",
"case",
"p",
".",
"Term_VAR",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"args",
"[",
"0",
"]",
")",
"\n",
"case",
"p",
".",
"Term_IMPLICIT_VAR",
":",
"return",
"\"",
"\"",
"\n",
"case",
"p",
".",
"Term_DATUM",
":",
"switch",
"v",
":=",
"t",
".",
"data",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"return",
"strconv",
".",
"Quote",
"(",
"v",
")",
"\n",
"default",
":",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
")",
"\n",
"}",
"\n",
"case",
"p",
".",
"Term_BINARY",
":",
"if",
"len",
"(",
"t",
".",
"args",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"rootTerm",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"name",
",",
"strings",
".",
"Join",
"(",
"allArgsToStringSlice",
"(",
"t",
".",
"args",
",",
"t",
".",
"optArgs",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"args",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
".",
"args",
"[",
"0",
"]",
".",
"String",
"(",
")",
",",
"t",
".",
"name",
",",
"strings",
".",
"Join",
"(",
"allArgsToStringSlice",
"(",
"t",
".",
"args",
"[",
"1",
":",
"]",
",",
"t",
".",
"optArgs",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // String returns a string representation of the query tree | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"query",
"tree"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query.go#L191-L238 |
152,276 | rethinkdb/rethinkdb-go | query.go | ReadOne | func (t Term) ReadOne(dest interface{}, s QueryExecutor, optArgs ...RunOpts) error {
res, err := t.Run(s, optArgs...)
if err != nil {
return err
}
return res.One(dest)
} | go | func (t Term) ReadOne(dest interface{}, s QueryExecutor, optArgs ...RunOpts) error {
res, err := t.Run(s, optArgs...)
if err != nil {
return err
}
return res.One(dest)
} | [
"func",
"(",
"t",
"Term",
")",
"ReadOne",
"(",
"dest",
"interface",
"{",
"}",
",",
"s",
"QueryExecutor",
",",
"optArgs",
"...",
"RunOpts",
")",
"error",
"{",
"res",
",",
"err",
":=",
"t",
".",
"Run",
"(",
"s",
",",
"optArgs",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"res",
".",
"One",
"(",
"dest",
")",
"\n",
"}"
] | // ReadOne is a shortcut method that runs the query on the given connection
// and reads one response from the cursor before closing it.
//
// It returns any errors encountered from running the query or reading the response | [
"ReadOne",
"is",
"a",
"shortcut",
"method",
"that",
"runs",
"the",
"query",
"on",
"the",
"given",
"connection",
"and",
"reads",
"one",
"response",
"from",
"the",
"cursor",
"before",
"closing",
"it",
".",
"It",
"returns",
"any",
"errors",
"encountered",
"from",
"running",
"the",
"query",
"or",
"reading",
"the",
"response"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query.go#L387-L393 |
152,277 | rethinkdb/rethinkdb-go | query.go | ReadAll | func (t Term) ReadAll(dest interface{}, s QueryExecutor, optArgs ...RunOpts) error {
res, err := t.Run(s, optArgs...)
if err != nil {
return err
}
return res.All(dest)
} | go | func (t Term) ReadAll(dest interface{}, s QueryExecutor, optArgs ...RunOpts) error {
res, err := t.Run(s, optArgs...)
if err != nil {
return err
}
return res.All(dest)
} | [
"func",
"(",
"t",
"Term",
")",
"ReadAll",
"(",
"dest",
"interface",
"{",
"}",
",",
"s",
"QueryExecutor",
",",
"optArgs",
"...",
"RunOpts",
")",
"error",
"{",
"res",
",",
"err",
":=",
"t",
".",
"Run",
"(",
"s",
",",
"optArgs",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"res",
".",
"All",
"(",
"dest",
")",
"\n",
"}"
] | // ReadAll is a shortcut method that runs the query on the given connection
// and reads all of the responses from the cursor before closing it.
//
// It returns any errors encountered from running the query or reading the responses | [
"ReadAll",
"is",
"a",
"shortcut",
"method",
"that",
"runs",
"the",
"query",
"on",
"the",
"given",
"connection",
"and",
"reads",
"all",
"of",
"the",
"responses",
"from",
"the",
"cursor",
"before",
"closing",
"it",
".",
"It",
"returns",
"any",
"errors",
"encountered",
"from",
"running",
"the",
"query",
"or",
"reading",
"the",
"responses"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query.go#L399-L405 |
152,278 | rethinkdb/rethinkdb-go | errors.go | IsConflictErr | func IsConflictErr(err error) bool {
if err == nil {
return false
}
return strings.HasPrefix(err.Error(), "Duplicate primary key")
} | go | func IsConflictErr(err error) bool {
if err == nil {
return false
}
return strings.HasPrefix(err.Error(), "Duplicate primary key")
} | [
"func",
"IsConflictErr",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"HasPrefix",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Error type helpers
// IsConflictErr returns true if the error is non-nil and the query failed
// due to a duplicate primary key. | [
"Error",
"type",
"helpers",
"IsConflictErr",
"returns",
"true",
"if",
"the",
"error",
"is",
"non",
"-",
"nil",
"and",
"the",
"query",
"failed",
"due",
"to",
"a",
"duplicate",
"primary",
"key",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/errors.go#L176-L182 |
152,279 | rethinkdb/rethinkdb-go | mock.go | MockAnything | func MockAnything() Term {
t := constructRootTerm("MockAnything", p.Term_DATUM, nil, nil)
t.isMockAnything = true
return t
} | go | func MockAnything() Term {
t := constructRootTerm("MockAnything", p.Term_DATUM, nil, nil)
t.isMockAnything = true
return t
} | [
"func",
"MockAnything",
"(",
")",
"Term",
"{",
"t",
":=",
"constructRootTerm",
"(",
"\"",
"\"",
",",
"p",
".",
"Term_DATUM",
",",
"nil",
",",
"nil",
")",
"\n",
"t",
".",
"isMockAnything",
"=",
"true",
"\n\n",
"return",
"t",
"\n",
"}"
] | // MockAnything can be used in place of any term, this is useful when you want
// mock similar queries or queries that you don't quite know the exact structure
// of. | [
"MockAnything",
"can",
"be",
"used",
"in",
"place",
"of",
"any",
"term",
"this",
"is",
"useful",
"when",
"you",
"want",
"mock",
"similar",
"queries",
"or",
"queries",
"that",
"you",
"don",
"t",
"quite",
"know",
"the",
"exact",
"structure",
"of",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/mock.go#L26-L31 |
152,280 | rethinkdb/rethinkdb-go | mock.go | NewMock | func NewMock(opts ...ConnectOpts) *Mock {
m := &Mock{
ExpectedQueries: make([]*MockQuery, 0),
Queries: make([]MockQuery, 0),
}
if len(opts) > 0 {
m.opts = opts[0]
}
return m
} | go | func NewMock(opts ...ConnectOpts) *Mock {
m := &Mock{
ExpectedQueries: make([]*MockQuery, 0),
Queries: make([]MockQuery, 0),
}
if len(opts) > 0 {
m.opts = opts[0]
}
return m
} | [
"func",
"NewMock",
"(",
"opts",
"...",
"ConnectOpts",
")",
"*",
"Mock",
"{",
"m",
":=",
"&",
"Mock",
"{",
"ExpectedQueries",
":",
"make",
"(",
"[",
"]",
"*",
"MockQuery",
",",
"0",
")",
",",
"Queries",
":",
"make",
"(",
"[",
"]",
"MockQuery",
",",
"0",
")",
",",
"}",
"\n\n",
"if",
"len",
"(",
"opts",
")",
">",
"0",
"{",
"m",
".",
"opts",
"=",
"opts",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"return",
"m",
"\n",
"}"
] | // NewMock creates an instance of Mock, you can optionally pass ConnectOpts to
// the function, if passed any mocked query will be generated using those
// options. | [
"NewMock",
"creates",
"an",
"instance",
"of",
"Mock",
"you",
"can",
"optionally",
"pass",
"ConnectOpts",
"to",
"the",
"function",
"if",
"passed",
"any",
"mocked",
"query",
"will",
"be",
"generated",
"using",
"those",
"options",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/mock.go#L190-L201 |
152,281 | rethinkdb/rethinkdb-go | mock.go | AssertExpectations | func (m *Mock) AssertExpectations(t testingT) bool {
var somethingMissing bool
var failedExpectations int
// iterate through each expectation
expectedQueries := m.expectedQueries()
for _, expectedQuery := range expectedQueries {
if !m.queryWasExecuted(expectedQuery) && expectedQuery.executed == 0 {
somethingMissing = true
failedExpectations++
t.Logf("❌\t%s", expectedQuery.Query.Term.String())
} else {
m.mu.Lock()
if expectedQuery.Repeatability > 0 {
somethingMissing = true
failedExpectations++
} else {
t.Logf("✅\t%s", expectedQuery.Query.Term.String())
}
m.mu.Unlock()
}
}
if somethingMissing {
t.Errorf("FAIL: %d out of %d expectation(s) were met.\n\tThe query you are testing needs to be executed %d more times(s).", len(expectedQueries)-failedExpectations, len(expectedQueries), failedExpectations)
}
return !somethingMissing
} | go | func (m *Mock) AssertExpectations(t testingT) bool {
var somethingMissing bool
var failedExpectations int
// iterate through each expectation
expectedQueries := m.expectedQueries()
for _, expectedQuery := range expectedQueries {
if !m.queryWasExecuted(expectedQuery) && expectedQuery.executed == 0 {
somethingMissing = true
failedExpectations++
t.Logf("❌\t%s", expectedQuery.Query.Term.String())
} else {
m.mu.Lock()
if expectedQuery.Repeatability > 0 {
somethingMissing = true
failedExpectations++
} else {
t.Logf("✅\t%s", expectedQuery.Query.Term.String())
}
m.mu.Unlock()
}
}
if somethingMissing {
t.Errorf("FAIL: %d out of %d expectation(s) were met.\n\tThe query you are testing needs to be executed %d more times(s).", len(expectedQueries)-failedExpectations, len(expectedQueries), failedExpectations)
}
return !somethingMissing
} | [
"func",
"(",
"m",
"*",
"Mock",
")",
"AssertExpectations",
"(",
"t",
"testingT",
")",
"bool",
"{",
"var",
"somethingMissing",
"bool",
"\n",
"var",
"failedExpectations",
"int",
"\n\n",
"// iterate through each expectation",
"expectedQueries",
":=",
"m",
".",
"expectedQueries",
"(",
")",
"\n",
"for",
"_",
",",
"expectedQuery",
":=",
"range",
"expectedQueries",
"{",
"if",
"!",
"m",
".",
"queryWasExecuted",
"(",
"expectedQuery",
")",
"&&",
"expectedQuery",
".",
"executed",
"==",
"0",
"{",
"somethingMissing",
"=",
"true",
"\n",
"failedExpectations",
"++",
"\n",
"t",
".",
"Logf",
"(",
"\"",
"%s",
" ",
"e",
"pectedQuery.Q",
"u",
"ery.T",
"e",
"rm.S",
"t",
"ring()",
")",
"",
"",
"\n",
"}",
"else",
"{",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"expectedQuery",
".",
"Repeatability",
">",
"0",
"{",
"somethingMissing",
"=",
"true",
"\n",
"failedExpectations",
"++",
"\n",
"}",
"else",
"{",
"t",
".",
"Logf",
"(",
"\"",
"%s",
" ",
"e",
"pectedQuery.Q",
"u",
"ery.T",
"e",
"rm.S",
"t",
"ring()",
")",
"",
"",
"\n",
"}",
"\n",
"m",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"somethingMissing",
"{",
"t",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\t",
"\"",
",",
"len",
"(",
"expectedQueries",
")",
"-",
"failedExpectations",
",",
"len",
"(",
"expectedQueries",
")",
",",
"failedExpectations",
")",
"\n",
"}",
"\n\n",
"return",
"!",
"somethingMissing",
"\n",
"}"
] | // AssertExpectations asserts that everything specified with On and Return was
// in fact executed as expected. Queries may have been executed in any order. | [
"AssertExpectations",
"asserts",
"that",
"everything",
"specified",
"with",
"On",
"and",
"Return",
"was",
"in",
"fact",
"executed",
"as",
"expected",
".",
"Queries",
"may",
"have",
"been",
"executed",
"in",
"any",
"order",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/mock.go#L222-L250 |
152,282 | rethinkdb/rethinkdb-go | mock.go | AssertNumberOfExecutions | func (m *Mock) AssertNumberOfExecutions(t testingT, expectedQuery *MockQuery, expectedExecutions int) bool {
var actualExecutions int
for _, query := range m.queries() {
if query.Query.Term.compare(*expectedQuery.Query.Term, map[int64]int64{}) && query.Repeatability > -1 {
// if bytes.Equal(query.BuiltQuery, expectedQuery.BuiltQuery) {
actualExecutions++
}
}
if expectedExecutions != actualExecutions {
t.Errorf("Expected number of executions (%d) does not match the actual number of executions (%d).", expectedExecutions, actualExecutions)
return false
}
return true
} | go | func (m *Mock) AssertNumberOfExecutions(t testingT, expectedQuery *MockQuery, expectedExecutions int) bool {
var actualExecutions int
for _, query := range m.queries() {
if query.Query.Term.compare(*expectedQuery.Query.Term, map[int64]int64{}) && query.Repeatability > -1 {
// if bytes.Equal(query.BuiltQuery, expectedQuery.BuiltQuery) {
actualExecutions++
}
}
if expectedExecutions != actualExecutions {
t.Errorf("Expected number of executions (%d) does not match the actual number of executions (%d).", expectedExecutions, actualExecutions)
return false
}
return true
} | [
"func",
"(",
"m",
"*",
"Mock",
")",
"AssertNumberOfExecutions",
"(",
"t",
"testingT",
",",
"expectedQuery",
"*",
"MockQuery",
",",
"expectedExecutions",
"int",
")",
"bool",
"{",
"var",
"actualExecutions",
"int",
"\n",
"for",
"_",
",",
"query",
":=",
"range",
"m",
".",
"queries",
"(",
")",
"{",
"if",
"query",
".",
"Query",
".",
"Term",
".",
"compare",
"(",
"*",
"expectedQuery",
".",
"Query",
".",
"Term",
",",
"map",
"[",
"int64",
"]",
"int64",
"{",
"}",
")",
"&&",
"query",
".",
"Repeatability",
">",
"-",
"1",
"{",
"// if bytes.Equal(query.BuiltQuery, expectedQuery.BuiltQuery) {",
"actualExecutions",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"expectedExecutions",
"!=",
"actualExecutions",
"{",
"t",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"expectedExecutions",
",",
"actualExecutions",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] | // AssertNumberOfExecutions asserts that the query was executed expectedExecutions times. | [
"AssertNumberOfExecutions",
"asserts",
"that",
"the",
"query",
"was",
"executed",
"expectedExecutions",
"times",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/mock.go#L253-L268 |
152,283 | rethinkdb/rethinkdb-go | mock.go | AssertExecuted | func (m *Mock) AssertExecuted(t testingT, expectedQuery *MockQuery) bool {
if !m.queryWasExecuted(expectedQuery) {
t.Errorf("The query \"%s\" should have been executed, but was not.", expectedQuery.Query.Term.String())
return false
}
return true
} | go | func (m *Mock) AssertExecuted(t testingT, expectedQuery *MockQuery) bool {
if !m.queryWasExecuted(expectedQuery) {
t.Errorf("The query \"%s\" should have been executed, but was not.", expectedQuery.Query.Term.String())
return false
}
return true
} | [
"func",
"(",
"m",
"*",
"Mock",
")",
"AssertExecuted",
"(",
"t",
"testingT",
",",
"expectedQuery",
"*",
"MockQuery",
")",
"bool",
"{",
"if",
"!",
"m",
".",
"queryWasExecuted",
"(",
"expectedQuery",
")",
"{",
"t",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"expectedQuery",
".",
"Query",
".",
"Term",
".",
"String",
"(",
")",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // AssertExecuted asserts that the method was executed.
// It can produce a false result when an argument is a pointer type and the underlying value changed after executing the mocked method. | [
"AssertExecuted",
"asserts",
"that",
"the",
"method",
"was",
"executed",
".",
"It",
"can",
"produce",
"a",
"false",
"result",
"when",
"an",
"argument",
"is",
"a",
"pointer",
"type",
"and",
"the",
"underlying",
"value",
"changed",
"after",
"executing",
"the",
"mocked",
"method",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/mock.go#L272-L278 |
152,284 | rethinkdb/rethinkdb-go | encoding/decoder.go | decodeValue | func decodeValue(dv, sv reflect.Value, blank bool) error {
return valueDecoder(dv, sv, blank)(dv, sv)
} | go | func decodeValue(dv, sv reflect.Value, blank bool) error {
return valueDecoder(dv, sv, blank)(dv, sv)
} | [
"func",
"decodeValue",
"(",
"dv",
",",
"sv",
"reflect",
".",
"Value",
",",
"blank",
"bool",
")",
"error",
"{",
"return",
"valueDecoder",
"(",
"dv",
",",
"sv",
",",
"blank",
")",
"(",
"dv",
",",
"sv",
")",
"\n",
"}"
] | // decodeValue decodes the source value into the destination value | [
"decodeValue",
"decodes",
"the",
"source",
"value",
"into",
"the",
"destination",
"value"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/encoding/decoder.go#L61-L63 |
152,285 | rethinkdb/rethinkdb-go | encoding/decoder.go | indirect | func indirect(v reflect.Value, decodeNull bool) reflect.Value {
// If v is a named type and is addressable,
// start with its address, so that if the type has pointer methods,
// we find them.
if v.Kind() != reflect.Ptr && v.Type().Name() != "" && v.CanAddr() {
v = v.Addr()
}
for {
// Load value from interface, but only if the result will be
// usefully addressable.
if v.Kind() == reflect.Interface && !v.IsNil() {
e := v.Elem()
if e.Kind() == reflect.Ptr && !e.IsNil() && (!decodeNull || e.Elem().Kind() == reflect.Ptr) {
v = e
continue
}
}
if v.Kind() != reflect.Ptr {
break
}
if v.IsNil() {
v.Set(reflect.New(v.Type().Elem()))
}
v = v.Elem()
}
return v
} | go | func indirect(v reflect.Value, decodeNull bool) reflect.Value {
// If v is a named type and is addressable,
// start with its address, so that if the type has pointer methods,
// we find them.
if v.Kind() != reflect.Ptr && v.Type().Name() != "" && v.CanAddr() {
v = v.Addr()
}
for {
// Load value from interface, but only if the result will be
// usefully addressable.
if v.Kind() == reflect.Interface && !v.IsNil() {
e := v.Elem()
if e.Kind() == reflect.Ptr && !e.IsNil() && (!decodeNull || e.Elem().Kind() == reflect.Ptr) {
v = e
continue
}
}
if v.Kind() != reflect.Ptr {
break
}
if v.IsNil() {
v.Set(reflect.New(v.Type().Elem()))
}
v = v.Elem()
}
return v
} | [
"func",
"indirect",
"(",
"v",
"reflect",
".",
"Value",
",",
"decodeNull",
"bool",
")",
"reflect",
".",
"Value",
"{",
"// If v is a named type and is addressable,",
"// start with its address, so that if the type has pointer methods,",
"// we find them.",
"if",
"v",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"&&",
"v",
".",
"Type",
"(",
")",
".",
"Name",
"(",
")",
"!=",
"\"",
"\"",
"&&",
"v",
".",
"CanAddr",
"(",
")",
"{",
"v",
"=",
"v",
".",
"Addr",
"(",
")",
"\n",
"}",
"\n",
"for",
"{",
"// Load value from interface, but only if the result will be",
"// usefully addressable.",
"if",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Interface",
"&&",
"!",
"v",
".",
"IsNil",
"(",
")",
"{",
"e",
":=",
"v",
".",
"Elem",
"(",
")",
"\n",
"if",
"e",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"&&",
"!",
"e",
".",
"IsNil",
"(",
")",
"&&",
"(",
"!",
"decodeNull",
"||",
"e",
".",
"Elem",
"(",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
")",
"{",
"v",
"=",
"e",
"\n",
"continue",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"v",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"break",
"\n",
"}",
"\n\n",
"if",
"v",
".",
"IsNil",
"(",
")",
"{",
"v",
".",
"Set",
"(",
"reflect",
".",
"New",
"(",
"v",
".",
"Type",
"(",
")",
".",
"Elem",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"v",
"=",
"v",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"return",
"v",
"\n",
"}"
] | // indirect walks down v allocating pointers as needed,
// until it gets to a non-pointer. | [
"indirect",
"walks",
"down",
"v",
"allocating",
"pointers",
"as",
"needed",
"until",
"it",
"gets",
"to",
"a",
"non",
"-",
"pointer",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/encoding/decoder.go#L122-L150 |
152,286 | rethinkdb/rethinkdb-go | node.go | Closed | func (n *Node) Closed() bool {
n.mu.RLock()
defer n.mu.RUnlock()
return n.closed
} | go | func (n *Node) Closed() bool {
n.mu.RLock()
defer n.mu.RUnlock()
return n.closed
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"Closed",
"(",
")",
"bool",
"{",
"n",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"defer",
"n",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"n",
".",
"closed",
"\n",
"}"
] | // Closed returns true if the node is closed | [
"Closed",
"returns",
"true",
"if",
"the",
"node",
"is",
"closed"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/node.go#L36-L41 |
152,287 | rethinkdb/rethinkdb-go | node.go | Query | func (n *Node) Query(ctx context.Context, q Query) (cursor *Cursor, err error) {
if n.Closed() {
return nil, ErrInvalidNode
}
return n.pool.Query(ctx, q)
} | go | func (n *Node) Query(ctx context.Context, q Query) (cursor *Cursor, err error) {
if n.Closed() {
return nil, ErrInvalidNode
}
return n.pool.Query(ctx, q)
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"Query",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"Query",
")",
"(",
"cursor",
"*",
"Cursor",
",",
"err",
"error",
")",
"{",
"if",
"n",
".",
"Closed",
"(",
")",
"{",
"return",
"nil",
",",
"ErrInvalidNode",
"\n",
"}",
"\n\n",
"return",
"n",
".",
"pool",
".",
"Query",
"(",
"ctx",
",",
"q",
")",
"\n",
"}"
] | // Query executes a ReQL query using this nodes connection pool. | [
"Query",
"executes",
"a",
"ReQL",
"query",
"using",
"this",
"nodes",
"connection",
"pool",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/node.go#L93-L99 |
152,288 | rethinkdb/rethinkdb-go | node.go | Exec | func (n *Node) Exec(ctx context.Context, q Query) (err error) {
if n.Closed() {
return ErrInvalidNode
}
return n.pool.Exec(ctx, q)
} | go | func (n *Node) Exec(ctx context.Context, q Query) (err error) {
if n.Closed() {
return ErrInvalidNode
}
return n.pool.Exec(ctx, q)
} | [
"func",
"(",
"n",
"*",
"Node",
")",
"Exec",
"(",
"ctx",
"context",
".",
"Context",
",",
"q",
"Query",
")",
"(",
"err",
"error",
")",
"{",
"if",
"n",
".",
"Closed",
"(",
")",
"{",
"return",
"ErrInvalidNode",
"\n",
"}",
"\n\n",
"return",
"n",
".",
"pool",
".",
"Exec",
"(",
"ctx",
",",
"q",
")",
"\n",
"}"
] | // Exec executes a ReQL query using this nodes connection pool. | [
"Exec",
"executes",
"a",
"ReQL",
"query",
"using",
"this",
"nodes",
"connection",
"pool",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/node.go#L102-L108 |
152,289 | rethinkdb/rethinkdb-go | query_aggregation.go | Group | func (t Term) Group(fieldOrFunctions ...interface{}) Term {
return constructMethodTerm(t, "Group", p.Term_GROUP, funcWrapArgs(fieldOrFunctions), map[string]interface{}{})
} | go | func (t Term) Group(fieldOrFunctions ...interface{}) Term {
return constructMethodTerm(t, "Group", p.Term_GROUP, funcWrapArgs(fieldOrFunctions), map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Group",
"(",
"fieldOrFunctions",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_GROUP",
",",
"funcWrapArgs",
"(",
"fieldOrFunctions",
")",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Group takes a stream and partitions it into multiple groups based on the
// fields or functions provided. Commands chained after group will be
// called on each of these grouped sub-streams, producing grouped data. | [
"Group",
"takes",
"a",
"stream",
"and",
"partitions",
"it",
"into",
"multiple",
"groups",
"based",
"on",
"the",
"fields",
"or",
"functions",
"provided",
".",
"Commands",
"chained",
"after",
"group",
"will",
"be",
"called",
"on",
"each",
"of",
"these",
"grouped",
"sub",
"-",
"streams",
"producing",
"grouped",
"data",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_aggregation.go#L106-L108 |
152,290 | rethinkdb/rethinkdb-go | query_aggregation.go | Contains | func (t Term) Contains(args ...interface{}) Term {
return constructMethodTerm(t, "Contains", p.Term_CONTAINS, funcWrapArgs(args), map[string]interface{}{})
} | go | func (t Term) Contains(args ...interface{}) Term {
return constructMethodTerm(t, "Contains", p.Term_CONTAINS, funcWrapArgs(args), map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Contains",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_CONTAINS",
",",
"funcWrapArgs",
"(",
"args",
")",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Contains returns whether or not a sequence contains all the specified values,
// or if functions are provided instead, returns whether or not a sequence
// contains values matching all the specified functions. | [
"Contains",
"returns",
"whether",
"or",
"not",
"a",
"sequence",
"contains",
"all",
"the",
"specified",
"values",
"or",
"if",
"functions",
"are",
"provided",
"instead",
"returns",
"whether",
"or",
"not",
"a",
"sequence",
"contains",
"values",
"matching",
"all",
"the",
"specified",
"functions",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_aggregation.go#L167-L169 |
152,291 | rethinkdb/rethinkdb-go | query_aggregation.go | Count | func (t Term) Count(args ...interface{}) Term {
return constructMethodTerm(t, "Count", p.Term_COUNT, funcWrapArgs(args), map[string]interface{}{})
} | go | func (t Term) Count(args ...interface{}) Term {
return constructMethodTerm(t, "Count", p.Term_COUNT, funcWrapArgs(args), map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Count",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_COUNT",
",",
"funcWrapArgs",
"(",
"args",
")",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Count the number of elements in the sequence. With a single argument,
// count the number of elements equal to it. If the argument is a function,
// it is equivalent to calling filter before count. | [
"Count",
"the",
"number",
"of",
"elements",
"in",
"the",
"sequence",
".",
"With",
"a",
"single",
"argument",
"count",
"the",
"number",
"of",
"elements",
"equal",
"to",
"it",
".",
"If",
"the",
"argument",
"is",
"a",
"function",
"it",
"is",
"equivalent",
"to",
"calling",
"filter",
"before",
"count",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_aggregation.go#L184-L186 |
152,292 | rethinkdb/rethinkdb-go | query_aggregation.go | Sum | func (t Term) Sum(args ...interface{}) Term {
return constructMethodTerm(t, "Sum", p.Term_SUM, funcWrapArgs(args), map[string]interface{}{})
} | go | func (t Term) Sum(args ...interface{}) Term {
return constructMethodTerm(t, "Sum", p.Term_SUM, funcWrapArgs(args), map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Sum",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_SUM",
",",
"funcWrapArgs",
"(",
"args",
")",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Sum returns the sum of all the elements of a sequence. If called with a field
// name, sums all the values of that field in the sequence, skipping elements of
// the sequence that lack that field. If called with a function, calls that
// function on every element of the sequence and sums the results, skipping
// elements of the sequence where that function returns null or a non-existence
// error. | [
"Sum",
"returns",
"the",
"sum",
"of",
"all",
"the",
"elements",
"of",
"a",
"sequence",
".",
"If",
"called",
"with",
"a",
"field",
"name",
"sums",
"all",
"the",
"values",
"of",
"that",
"field",
"in",
"the",
"sequence",
"skipping",
"elements",
"of",
"the",
"sequence",
"that",
"lack",
"that",
"field",
".",
"If",
"called",
"with",
"a",
"function",
"calls",
"that",
"function",
"on",
"every",
"element",
"of",
"the",
"sequence",
"and",
"sums",
"the",
"results",
"skipping",
"elements",
"of",
"the",
"sequence",
"where",
"that",
"function",
"returns",
"null",
"or",
"a",
"non",
"-",
"existence",
"error",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_aggregation.go#L204-L206 |
152,293 | rethinkdb/rethinkdb-go | query_aggregation.go | Avg | func (t Term) Avg(args ...interface{}) Term {
return constructMethodTerm(t, "Avg", p.Term_AVG, funcWrapArgs(args), map[string]interface{}{})
} | go | func (t Term) Avg(args ...interface{}) Term {
return constructMethodTerm(t, "Avg", p.Term_AVG, funcWrapArgs(args), map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Avg",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_AVG",
",",
"funcWrapArgs",
"(",
"args",
")",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Avg returns the average of all the elements of a sequence. If called with a field
// name, averages all the values of that field in the sequence, skipping elements of
// the sequence that lack that field. If called with a function, calls that function
// on every element of the sequence and averages the results, skipping elements of the
// sequence where that function returns null or a non-existence error. | [
"Avg",
"returns",
"the",
"average",
"of",
"all",
"the",
"elements",
"of",
"a",
"sequence",
".",
"If",
"called",
"with",
"a",
"field",
"name",
"averages",
"all",
"the",
"values",
"of",
"that",
"field",
"in",
"the",
"sequence",
"skipping",
"elements",
"of",
"the",
"sequence",
"that",
"lack",
"that",
"field",
".",
"If",
"called",
"with",
"a",
"function",
"calls",
"that",
"function",
"on",
"every",
"element",
"of",
"the",
"sequence",
"and",
"averages",
"the",
"results",
"skipping",
"elements",
"of",
"the",
"sequence",
"where",
"that",
"function",
"returns",
"null",
"or",
"a",
"non",
"-",
"existence",
"error",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_aggregation.go#L222-L224 |
152,294 | rethinkdb/rethinkdb-go | query_aggregation.go | Min | func (t Term) Min(args ...interface{}) Term {
return constructMethodTerm(t, "Min", p.Term_MIN, funcWrapArgs(args), map[string]interface{}{})
} | go | func (t Term) Min(args ...interface{}) Term {
return constructMethodTerm(t, "Min", p.Term_MIN, funcWrapArgs(args), map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Min",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_MIN",
",",
"funcWrapArgs",
"(",
"args",
")",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Min finds the minimum of a sequence. If called with a field name, finds the element
// of that sequence with the smallest value in that field. If called with a function,
// calls that function on every element of the sequence and returns the element
// which produced the smallest value, ignoring any elements where the function
// returns null or produces a non-existence error. | [
"Min",
"finds",
"the",
"minimum",
"of",
"a",
"sequence",
".",
"If",
"called",
"with",
"a",
"field",
"name",
"finds",
"the",
"element",
"of",
"that",
"sequence",
"with",
"the",
"smallest",
"value",
"in",
"that",
"field",
".",
"If",
"called",
"with",
"a",
"function",
"calls",
"that",
"function",
"on",
"every",
"element",
"of",
"the",
"sequence",
"and",
"returns",
"the",
"element",
"which",
"produced",
"the",
"smallest",
"value",
"ignoring",
"any",
"elements",
"where",
"the",
"function",
"returns",
"null",
"or",
"produces",
"a",
"non",
"-",
"existence",
"error",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_aggregation.go#L249-L251 |
152,295 | rethinkdb/rethinkdb-go | query_aggregation.go | Max | func (t Term) Max(args ...interface{}) Term {
return constructMethodTerm(t, "Max", p.Term_MAX, funcWrapArgs(args), map[string]interface{}{})
} | go | func (t Term) Max(args ...interface{}) Term {
return constructMethodTerm(t, "Max", p.Term_MAX, funcWrapArgs(args), map[string]interface{}{})
} | [
"func",
"(",
"t",
"Term",
")",
"Max",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"constructMethodTerm",
"(",
"t",
",",
"\"",
"\"",
",",
"p",
".",
"Term_MAX",
",",
"funcWrapArgs",
"(",
"args",
")",
",",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
")",
"\n",
"}"
] | // Max finds the maximum of a sequence. If called with a field name, finds the element
// of that sequence with the largest value in that field. If called with a function,
// calls that function on every element of the sequence and returns the element
// which produced the largest value, ignoring any elements where the function
// returns null or produces a non-existence error. | [
"Max",
"finds",
"the",
"maximum",
"of",
"a",
"sequence",
".",
"If",
"called",
"with",
"a",
"field",
"name",
"finds",
"the",
"element",
"of",
"that",
"sequence",
"with",
"the",
"largest",
"value",
"in",
"that",
"field",
".",
"If",
"called",
"with",
"a",
"function",
"calls",
"that",
"function",
"on",
"every",
"element",
"of",
"the",
"sequence",
"and",
"returns",
"the",
"element",
"which",
"produced",
"the",
"largest",
"value",
"ignoring",
"any",
"elements",
"where",
"the",
"function",
"returns",
"null",
"or",
"produces",
"a",
"non",
"-",
"existence",
"error",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/query_aggregation.go#L298-L300 |
152,296 | rethinkdb/rethinkdb-go | utils.go | constructRootTerm | func constructRootTerm(name string, termType p.Term_TermType, args []interface{}, optArgs map[string]interface{}) Term {
return Term{
name: name,
rootTerm: true,
termType: termType,
args: convertTermList(args),
optArgs: convertTermObj(optArgs),
}
} | go | func constructRootTerm(name string, termType p.Term_TermType, args []interface{}, optArgs map[string]interface{}) Term {
return Term{
name: name,
rootTerm: true,
termType: termType,
args: convertTermList(args),
optArgs: convertTermObj(optArgs),
}
} | [
"func",
"constructRootTerm",
"(",
"name",
"string",
",",
"termType",
"p",
".",
"Term_TermType",
",",
"args",
"[",
"]",
"interface",
"{",
"}",
",",
"optArgs",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"Term",
"{",
"return",
"Term",
"{",
"name",
":",
"name",
",",
"rootTerm",
":",
"true",
",",
"termType",
":",
"termType",
",",
"args",
":",
"convertTermList",
"(",
"args",
")",
",",
"optArgs",
":",
"convertTermObj",
"(",
"optArgs",
")",
",",
"}",
"\n",
"}"
] | // Helper functions for constructing terms
// constructRootTerm is an alias for creating a new term. | [
"Helper",
"functions",
"for",
"constructing",
"terms",
"constructRootTerm",
"is",
"an",
"alias",
"for",
"creating",
"a",
"new",
"term",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/utils.go#L16-L24 |
152,297 | rethinkdb/rethinkdb-go | utils.go | constructMethodTerm | func constructMethodTerm(prevVal Term, name string, termType p.Term_TermType, args []interface{}, optArgs map[string]interface{}) Term {
args = append([]interface{}{prevVal}, args...)
return Term{
name: name,
rootTerm: false,
termType: termType,
args: convertTermList(args),
optArgs: convertTermObj(optArgs),
}
} | go | func constructMethodTerm(prevVal Term, name string, termType p.Term_TermType, args []interface{}, optArgs map[string]interface{}) Term {
args = append([]interface{}{prevVal}, args...)
return Term{
name: name,
rootTerm: false,
termType: termType,
args: convertTermList(args),
optArgs: convertTermObj(optArgs),
}
} | [
"func",
"constructMethodTerm",
"(",
"prevVal",
"Term",
",",
"name",
"string",
",",
"termType",
"p",
".",
"Term_TermType",
",",
"args",
"[",
"]",
"interface",
"{",
"}",
",",
"optArgs",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"Term",
"{",
"args",
"=",
"append",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"prevVal",
"}",
",",
"args",
"...",
")",
"\n\n",
"return",
"Term",
"{",
"name",
":",
"name",
",",
"rootTerm",
":",
"false",
",",
"termType",
":",
"termType",
",",
"args",
":",
"convertTermList",
"(",
"args",
")",
",",
"optArgs",
":",
"convertTermObj",
"(",
"optArgs",
")",
",",
"}",
"\n",
"}"
] | // constructMethodTerm is an alias for creating a new term. Unlike constructRootTerm
// this function adds the previous expression in the tree to the argument list to
// create a method term. | [
"constructMethodTerm",
"is",
"an",
"alias",
"for",
"creating",
"a",
"new",
"term",
".",
"Unlike",
"constructRootTerm",
"this",
"function",
"adds",
"the",
"previous",
"expression",
"in",
"the",
"tree",
"to",
"the",
"argument",
"list",
"to",
"create",
"a",
"method",
"term",
"."
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/utils.go#L29-L39 |
152,298 | rethinkdb/rethinkdb-go | utils.go | newQuery | func newQuery(t Term, qopts map[string]interface{}, copts *ConnectOpts) (q Query, err error) {
queryOpts := map[string]interface{}{}
for k, v := range qopts {
queryOpts[k], err = Expr(v).Build()
if err != nil {
return
}
}
if copts.Database != "" {
queryOpts["db"], err = DB(copts.Database).Build()
if err != nil {
return
}
}
builtTerm, err := t.Build()
if err != nil {
return q, err
}
// Construct query
return Query{
Type: p.Query_START,
Term: &t,
Opts: queryOpts,
builtTerm: builtTerm,
}, nil
} | go | func newQuery(t Term, qopts map[string]interface{}, copts *ConnectOpts) (q Query, err error) {
queryOpts := map[string]interface{}{}
for k, v := range qopts {
queryOpts[k], err = Expr(v).Build()
if err != nil {
return
}
}
if copts.Database != "" {
queryOpts["db"], err = DB(copts.Database).Build()
if err != nil {
return
}
}
builtTerm, err := t.Build()
if err != nil {
return q, err
}
// Construct query
return Query{
Type: p.Query_START,
Term: &t,
Opts: queryOpts,
builtTerm: builtTerm,
}, nil
} | [
"func",
"newQuery",
"(",
"t",
"Term",
",",
"qopts",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"copts",
"*",
"ConnectOpts",
")",
"(",
"q",
"Query",
",",
"err",
"error",
")",
"{",
"queryOpts",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"qopts",
"{",
"queryOpts",
"[",
"k",
"]",
",",
"err",
"=",
"Expr",
"(",
"v",
")",
".",
"Build",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"copts",
".",
"Database",
"!=",
"\"",
"\"",
"{",
"queryOpts",
"[",
"\"",
"\"",
"]",
",",
"err",
"=",
"DB",
"(",
"copts",
".",
"Database",
")",
".",
"Build",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"builtTerm",
",",
"err",
":=",
"t",
".",
"Build",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"q",
",",
"err",
"\n",
"}",
"\n\n",
"// Construct query",
"return",
"Query",
"{",
"Type",
":",
"p",
".",
"Query_START",
",",
"Term",
":",
"&",
"t",
",",
"Opts",
":",
"queryOpts",
",",
"builtTerm",
":",
"builtTerm",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Helper functions for creating internal RQL types | [
"Helper",
"functions",
"for",
"creating",
"internal",
"RQL",
"types"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/utils.go#L43-L70 |
152,299 | rethinkdb/rethinkdb-go | utils.go | makeArray | func makeArray(args termsList) Term {
return Term{
name: "[...]",
termType: p.Term_MAKE_ARRAY,
args: args,
}
} | go | func makeArray(args termsList) Term {
return Term{
name: "[...]",
termType: p.Term_MAKE_ARRAY,
args: args,
}
} | [
"func",
"makeArray",
"(",
"args",
"termsList",
")",
"Term",
"{",
"return",
"Term",
"{",
"name",
":",
"\"",
"\"",
",",
"termType",
":",
"p",
".",
"Term_MAKE_ARRAY",
",",
"args",
":",
"args",
",",
"}",
"\n",
"}"
] | // makeArray takes a slice of terms and produces a single MAKE_ARRAY term | [
"makeArray",
"takes",
"a",
"slice",
"of",
"terms",
"and",
"produces",
"a",
"single",
"MAKE_ARRAY",
"term"
] | 04a849766900ad9c936ba78770186640e3bede20 | https://github.com/rethinkdb/rethinkdb-go/blob/04a849766900ad9c936ba78770186640e3bede20/utils.go#L73-L79 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.