1
0
Fork 0
master
Philip O'Toole 9 months ago
parent 9c9e911caa
commit 5c5b226303

@ -8,7 +8,7 @@ import (
"sync"
"time"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/random"
)

@ -13,7 +13,7 @@ import (
"time"
"github.com/rqlite/rqlite/v8/auth"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/rtls"
"github.com/rqlite/rqlite/v8/tcp"
"github.com/rqlite/rqlite/v8/tcp/pool"

@ -9,7 +9,7 @@ import (
"time"
"github.com/rqlite/rqlite/v8/cluster/servicetest"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
"google.golang.org/protobuf/proto"
)

@ -6,7 +6,7 @@ import (
"os"
"time"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
)
var (

@ -1,7 +1,7 @@
syntax = "proto3";
package cluster;
import "command/command.proto";
import "command/proto/command.proto";
option go_package = "github.com/rqlite/rqlite/v8/cluster";

@ -5,7 +5,7 @@ import (
"os"
"time"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
)
const (

@ -15,7 +15,7 @@ import (
"time"
"github.com/rqlite/rqlite/v8/auth"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
"google.golang.org/protobuf/proto"
)

@ -10,8 +10,8 @@ import (
"testing"
"time"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/encoding"
command "github.com/rqlite/rqlite/v8/command/proto"
)
const shortWait = 1 * time.Second

@ -10,7 +10,7 @@ import (
"testing"
"time"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/testdata/x509"
)

@ -9,7 +9,7 @@ import (
"io"
"sync"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/proto"
)
const (
@ -70,7 +70,7 @@ func generateStreamID() string {
}
// Next returns the next LoadChunkRequest, or io.EOF if finished.
func (c *Chunker) Next() (*command.LoadChunkRequest, error) {
func (c *Chunker) Next() (*proto.LoadChunkRequest, error) {
c.statsMu.Lock()
defer c.statsMu.Unlock()
@ -126,7 +126,7 @@ func (c *Chunker) Next() (*command.LoadChunkRequest, error) {
return nil, io.EOF
}
// If previous chunks were sent, return a final empty chunk with IsLast = true
return &command.LoadChunkRequest{
return &proto.LoadChunkRequest{
StreamId: c.streamID,
SequenceNum: c.sequenceNum + 1,
IsLast: true,
@ -135,7 +135,7 @@ func (c *Chunker) Next() (*command.LoadChunkRequest, error) {
}
c.sequenceNum++
return &command.LoadChunkRequest{
return &proto.LoadChunkRequest{
StreamId: c.streamID,
SequenceNum: c.sequenceNum,
IsLast: totalRead < c.chunkSize,
@ -145,8 +145,8 @@ func (c *Chunker) Next() (*command.LoadChunkRequest, error) {
// Abort returns a LoadChunkRequest that signals the receiver to abort the
// given stream.
func (c *Chunker) Abort() *command.LoadChunkRequest {
return &command.LoadChunkRequest{
func (c *Chunker) Abort() *proto.LoadChunkRequest {
return &proto.LoadChunkRequest{
StreamId: c.streamID,
Abort: true,
}

@ -8,7 +8,7 @@ import (
"os"
"sync"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/proto"
)
// Dechunker is a writer that writes chunks to a file and returns the file path when
@ -34,7 +34,7 @@ func NewDechunker(dir string) (*Dechunker, error) {
// WriteChunk writes the chunk to the file. If the chunk is the last chunk, the
// the bool return value is true.
func (d *Dechunker) WriteChunk(chunk *command.LoadChunkRequest) (bool, error) {
func (d *Dechunker) WriteChunk(chunk *proto.LoadChunkRequest) (bool, error) {
if d.streamID == "" {
d.streamID = chunk.StreamId
} else if d.streamID != chunk.StreamId {

@ -10,12 +10,12 @@ import (
"strings"
"testing"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/proto"
)
func Test_SingleChunk(t *testing.T) {
data := []byte("Hello, World!")
chunk := &command.LoadChunkRequest{
chunk := &proto.LoadChunkRequest{
StreamId: "123",
SequenceNum: 1,
IsLast: true,
@ -58,14 +58,14 @@ func Test_SingleChunk(t *testing.T) {
func Test_MultiChunk(t *testing.T) {
data1 := []byte("Hello, World!")
chunk1 := &command.LoadChunkRequest{
chunk1 := &proto.LoadChunkRequest{
StreamId: "123",
SequenceNum: 1,
IsLast: false,
Data: mustCompressData(data1),
}
data2 := []byte("I'm OK")
chunk2 := &command.LoadChunkRequest{
chunk2 := &proto.LoadChunkRequest{
StreamId: "123",
SequenceNum: 2,
IsLast: true,
@ -83,7 +83,7 @@ func Test_MultiChunk(t *testing.T) {
t.Fatalf("failed to create Dechunker: %v", err)
}
for _, chunk := range []*command.LoadChunkRequest{chunk1, chunk2} {
for _, chunk := range []*proto.LoadChunkRequest{chunk1, chunk2} {
isLast, err := dechunker.WriteChunk(chunk)
if err != nil {
t.Fatalf("failed to write chunk: %v", err)
@ -110,20 +110,20 @@ func Test_MultiChunk(t *testing.T) {
func Test_MultiChunkNilData(t *testing.T) {
data1 := []byte("Hello, World!")
chunk1 := &command.LoadChunkRequest{
chunk1 := &proto.LoadChunkRequest{
StreamId: "123",
SequenceNum: 1,
IsLast: false,
Data: mustCompressData(data1),
}
data2 := []byte("I'm OK")
chunk2 := &command.LoadChunkRequest{
chunk2 := &proto.LoadChunkRequest{
StreamId: "123",
SequenceNum: 2,
IsLast: false,
Data: mustCompressData(data2),
}
chunk3 := &command.LoadChunkRequest{
chunk3 := &proto.LoadChunkRequest{
StreamId: "123",
SequenceNum: 3,
IsLast: true,
@ -141,7 +141,7 @@ func Test_MultiChunkNilData(t *testing.T) {
t.Fatalf("failed to create Dechunker: %v", err)
}
for _, chunk := range []*command.LoadChunkRequest{chunk1, chunk2, chunk3} {
for _, chunk := range []*proto.LoadChunkRequest{chunk1, chunk2, chunk3} {
isLast, err := dechunker.WriteChunk(chunk)
if err != nil {
t.Fatalf("failed to write chunk: %v", err)
@ -170,14 +170,14 @@ func Test_UnexpectedStreamID(t *testing.T) {
originalData := []byte("Hello, World!")
compressedData := mustCompressData(originalData)
chunk1 := &command.LoadChunkRequest{
chunk1 := &proto.LoadChunkRequest{
StreamId: "123",
SequenceNum: 1,
IsLast: false,
Data: compressedData,
}
chunk2 := &command.LoadChunkRequest{
chunk2 := &proto.LoadChunkRequest{
StreamId: "456",
SequenceNum: 2,
IsLast: true,
@ -214,14 +214,14 @@ func Test_ChunksOutOfOrder(t *testing.T) {
originalData := []byte("Hello, World!")
compressedData := mustCompressData(originalData)
chunk1 := &command.LoadChunkRequest{
chunk1 := &proto.LoadChunkRequest{
StreamId: "123",
SequenceNum: 1,
IsLast: false,
Data: compressedData,
}
chunk3 := &command.LoadChunkRequest{
chunk3 := &proto.LoadChunkRequest{
StreamId: "123",
SequenceNum: 3,
IsLast: true,
@ -283,7 +283,7 @@ func Test_ReassemblyOfLargeData(t *testing.T) {
end := start + chunkSize
isLast := i == numChunks-1
if _, err := d.WriteChunk(&command.LoadChunkRequest{
if _, err := d.WriteChunk(&proto.LoadChunkRequest{
StreamId: "1",
SequenceNum: int64(i + 1),
IsLast: isLast,

File diff suppressed because it is too large Load Diff

@ -6,7 +6,7 @@ import (
"errors"
"fmt"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/proto"
)
var (
@ -50,7 +50,7 @@ type ResultWithRows struct {
// NewResultRowsFromExecuteQueryResponse returns an API object from an
// ExecuteQueryResponse.
func NewResultRowsFromExecuteQueryResponse(e *command.ExecuteQueryResponse) (interface{}, error) {
func NewResultRowsFromExecuteQueryResponse(e *proto.ExecuteQueryResponse) (interface{}, error) {
if er := e.GetE(); er != nil {
return NewResultFromExecuteResult(er)
} else if qr := e.GetQ(); qr != nil {
@ -63,7 +63,7 @@ func NewResultRowsFromExecuteQueryResponse(e *command.ExecuteQueryResponse) (int
return nil, errors.New("no ExecuteResult, QueryRows, or Error")
}
func NewAssociativeResultRowsFromExecuteQueryResponse(e *command.ExecuteQueryResponse) (interface{}, error) {
func NewAssociativeResultRowsFromExecuteQueryResponse(e *proto.ExecuteQueryResponse) (interface{}, error) {
if er := e.GetE(); er != nil {
r, err := NewResultFromExecuteResult(er)
if err != nil {
@ -83,7 +83,7 @@ func NewAssociativeResultRowsFromExecuteQueryResponse(e *command.ExecuteQueryRes
}
// NewResultFromExecuteResult returns an API Result object from an ExecuteResult.
func NewResultFromExecuteResult(e *command.ExecuteResult) (*Result, error) {
func NewResultFromExecuteResult(e *proto.ExecuteResult) (*Result, error) {
return &Result{
LastInsertID: e.LastInsertId,
RowsAffected: e.RowsAffected,
@ -93,7 +93,7 @@ func NewResultFromExecuteResult(e *command.ExecuteResult) (*Result, error) {
}
// NewRowsFromQueryRows returns an API Rows object from a QueryRows
func NewRowsFromQueryRows(q *command.QueryRows) (*Rows, error) {
func NewRowsFromQueryRows(q *proto.QueryRows) (*Rows, error) {
if len(q.Columns) != len(q.Types) {
return nil, ErrTypesColumnsLengthViolation
}
@ -112,7 +112,7 @@ func NewRowsFromQueryRows(q *command.QueryRows) (*Rows, error) {
}
// NewAssociativeRowsFromQueryRows returns an associative API object from a QueryRows
func NewAssociativeRowsFromQueryRows(q *command.QueryRows) (*AssociativeRows, error) {
func NewAssociativeRowsFromQueryRows(q *proto.QueryRows) (*AssociativeRows, error) {
if len(q.Columns) != len(q.Types) {
return nil, ErrTypesColumnsLengthViolation
}
@ -145,7 +145,7 @@ func NewAssociativeRowsFromQueryRows(q *command.QueryRows) (*AssociativeRows, er
}
// NewValuesFromQueryValues sets Values from a QueryValue object.
func NewValuesFromQueryValues(dest [][]interface{}, v []*command.Values) error {
func NewValuesFromQueryValues(dest [][]interface{}, v []*proto.Values) error {
for n := range v {
vals := v[n]
if vals == nil {
@ -162,15 +162,15 @@ func NewValuesFromQueryValues(dest [][]interface{}, v []*command.Values) error {
rowValues := make([]interface{}, len(params))
for p := range params {
switch w := params[p].GetValue().(type) {
case *command.Parameter_I:
case *proto.Parameter_I:
rowValues[p] = w.I
case *command.Parameter_D:
case *proto.Parameter_D:
rowValues[p] = w.D
case *command.Parameter_B:
case *proto.Parameter_B:
rowValues[p] = w.B
case *command.Parameter_Y:
case *proto.Parameter_Y:
rowValues[p] = w.Y
case *command.Parameter_S:
case *proto.Parameter_S:
rowValues[p] = w.S
case nil:
rowValues[p] = nil
@ -223,13 +223,13 @@ type marshalFunc func(i interface{}) ([]byte, error)
func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) {
switch v := i.(type) {
case *command.ExecuteResult:
case *proto.ExecuteResult:
r, err := NewResultFromExecuteResult(v)
if err != nil {
return nil, err
}
return f(r)
case []*command.ExecuteResult:
case []*proto.ExecuteResult:
var err error
results := make([]*Result, len(v))
for j := range v {
@ -239,7 +239,7 @@ func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) {
}
}
return f(results)
case *command.QueryRows:
case *proto.QueryRows:
if assoc {
r, err := NewAssociativeRowsFromQueryRows(v)
if err != nil {
@ -253,13 +253,13 @@ func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) {
}
return f(r)
}
case *command.ExecuteQueryResponse:
case *proto.ExecuteQueryResponse:
r, err := NewResultRowsFromExecuteQueryResponse(v)
if err != nil {
return nil, err
}
return f(r)
case []*command.QueryRows:
case []*proto.QueryRows:
var err error
if assoc {
@ -281,7 +281,7 @@ func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) {
}
return f(rows)
}
case []*command.ExecuteQueryResponse:
case []*proto.ExecuteQueryResponse:
if assoc {
res := make([]interface{}, len(v))
for j := range v {
@ -303,7 +303,7 @@ func jsonMarshal(i interface{}, f marshalFunc, assoc bool) ([]byte, error) {
}
return f(res)
}
case []*command.Values:
case []*proto.Values:
values := make([][]interface{}, len(v))
if err := NewValuesFromQueryValues(values, v); err != nil {
return nil, err

@ -3,7 +3,7 @@ package encoding
import (
"testing"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/proto"
)
func Test_JSONNoEscaping(t *testing.T) {
@ -25,10 +25,10 @@ func Test_JSONNoEscaping(t *testing.T) {
func Test_MarshalExecuteResult(t *testing.T) {
var b []byte
var err error
var r *command.ExecuteResult
var r *proto.ExecuteResult
enc := Encoder{}
r = &command.ExecuteResult{
r = &proto.ExecuteResult{
LastInsertId: 1,
RowsAffected: 2,
Time: 1234,
@ -41,7 +41,7 @@ func Test_MarshalExecuteResult(t *testing.T) {
t.Fatalf("failed to marshal ExecuteResult: exp %s, got %s", exp, got)
}
r = &command.ExecuteResult{
r = &proto.ExecuteResult{
LastInsertId: 4,
RowsAffected: 5,
Error: "something went wrong",
@ -78,17 +78,17 @@ func Test_MarshalExecuteResults(t *testing.T) {
var err error
enc := Encoder{}
r1 := &command.ExecuteResult{
r1 := &proto.ExecuteResult{
LastInsertId: 1,
RowsAffected: 2,
Time: 1234,
}
r2 := &command.ExecuteResult{
r2 := &proto.ExecuteResult{
LastInsertId: 3,
RowsAffected: 4,
Time: 5678,
}
b, err = enc.JSONMarshal([]*command.ExecuteResult{r1, r2})
b, err = enc.JSONMarshal([]*proto.ExecuteResult{r1, r2})
if err != nil {
t.Fatalf("failed to marshal ExecuteResults: %s", err.Error())
}
@ -100,10 +100,10 @@ func Test_MarshalExecuteResults(t *testing.T) {
// Test_MarshalQueryRowsError tests error cases
func Test_MarshalQueryRowsError(t *testing.T) {
var err error
var r *command.QueryRows
var r *proto.QueryRows
enc := Encoder{}
r = &command.QueryRows{
r = &proto.QueryRows{
Columns: []string{"c1", "c2"},
Types: []string{"int", "float", "string"},
Time: 6789,
@ -125,32 +125,32 @@ func Test_MarshalQueryRowsError(t *testing.T) {
func Test_MarshalQueryRows(t *testing.T) {
var b []byte
var err error
var r *command.QueryRows
var r *proto.QueryRows
enc := Encoder{}
r = &command.QueryRows{
r = &proto.QueryRows{
Columns: []string{"c1", "c2", "c3"},
Types: []string{"int", "float", "string"},
Time: 6789,
}
values := make([]*command.Parameter, len(r.Columns))
values[0] = &command.Parameter{
Value: &command.Parameter_I{
values := make([]*proto.Parameter, len(r.Columns))
values[0] = &proto.Parameter{
Value: &proto.Parameter_I{
I: 123,
},
}
values[1] = &command.Parameter{
Value: &command.Parameter_D{
values[1] = &proto.Parameter{
Value: &proto.Parameter_D{
D: 678.0,
},
}
values[2] = &command.Parameter{
Value: &command.Parameter_S{
values[2] = &proto.Parameter{
Value: &proto.Parameter_S{
S: "fiona",
},
}
r.Values = []*command.Values{
r.Values = []*proto.Values{
{Parameters: values},
}
@ -196,34 +196,34 @@ func Test_MarshalQueryRows(t *testing.T) {
func Test_MarshalQueryAssociativeRows(t *testing.T) {
var b []byte
var err error
var r *command.QueryRows
var r *proto.QueryRows
enc := Encoder{
Associative: true,
}
r = &command.QueryRows{
r = &proto.QueryRows{
Columns: []string{"c1", "c2", "c3"},
Types: []string{"int", "float", "string"},
Time: 6789,
}
values := make([]*command.Parameter, len(r.Columns))
values[0] = &command.Parameter{
Value: &command.Parameter_I{
values := make([]*proto.Parameter, len(r.Columns))
values[0] = &proto.Parameter{
Value: &proto.Parameter_I{
I: 123,
},
}
values[1] = &command.Parameter{
Value: &command.Parameter_D{
values[1] = &proto.Parameter{
Value: &proto.Parameter_D{
D: 678.0,
},
}
values[2] = &command.Parameter{
Value: &command.Parameter_S{
values[2] = &proto.Parameter{
Value: &proto.Parameter_S{
S: "fiona",
},
}
r.Values = []*command.Values{
r.Values = []*proto.Values{
{Parameters: values},
}
@ -264,36 +264,36 @@ func Test_MarshalQueryAssociativeRows(t *testing.T) {
func Test_MarshalQueryRowses(t *testing.T) {
var b []byte
var err error
var r *command.QueryRows
var r *proto.QueryRows
enc := Encoder{}
r = &command.QueryRows{
r = &proto.QueryRows{
Columns: []string{"c1", "c2", "c3"},
Types: []string{"int", "float", "string"},
Time: 6789,
}
values := make([]*command.Parameter, len(r.Columns))
values[0] = &command.Parameter{
Value: &command.Parameter_I{
values := make([]*proto.Parameter, len(r.Columns))
values[0] = &proto.Parameter{
Value: &proto.Parameter_I{
I: 123,
},
}
values[1] = &command.Parameter{
Value: &command.Parameter_D{
values[1] = &proto.Parameter{
Value: &proto.Parameter_D{
D: 678.0,
},
}
values[2] = &command.Parameter{
Value: &command.Parameter_S{
values[2] = &proto.Parameter{
Value: &proto.Parameter_S{
S: "fiona",
},
}
r.Values = []*command.Values{
r.Values = []*proto.Values{
{Parameters: values},
}
b, err = enc.JSONMarshal([]*command.QueryRows{r, r})
b, err = enc.JSONMarshal([]*proto.QueryRows{r, r})
if err != nil {
t.Fatalf("failed to marshal QueryRows: %s", err.Error())
}
@ -306,38 +306,38 @@ func Test_MarshalQueryRowses(t *testing.T) {
func Test_MarshalQueryAssociativeRowses(t *testing.T) {
var b []byte
var err error
var r *command.QueryRows
var r *proto.QueryRows
enc := Encoder{
Associative: true,
}
r = &command.QueryRows{
r = &proto.QueryRows{
Columns: []string{"c1", "c2", "c3"},
Types: []string{"int", "float", "string"},
Time: 6789,
}
values := make([]*command.Parameter, len(r.Columns))
values[0] = &command.Parameter{
Value: &command.Parameter_I{
values := make([]*proto.Parameter, len(r.Columns))
values[0] = &proto.Parameter{
Value: &proto.Parameter_I{
I: 123,
},
}
values[1] = &command.Parameter{
Value: &command.Parameter_D{
values[1] = &proto.Parameter{
Value: &proto.Parameter_D{
D: 678.0,
},
}
values[2] = &command.Parameter{
Value: &command.Parameter_S{
values[2] = &proto.Parameter{
Value: &proto.Parameter_S{
S: "fiona",
},
}
r.Values = []*command.Values{
r.Values = []*proto.Values{
{Parameters: values},
}
b, err = enc.JSONMarshal([]*command.QueryRows{r, r})
b, err = enc.JSONMarshal([]*proto.QueryRows{r, r})
if err != nil {
t.Fatalf("failed to marshal QueryRows: %s", err.Error())
}
@ -351,15 +351,15 @@ func Test_MarshalExecuteQueryResponse(t *testing.T) {
tests := []struct {
name string
responses []*command.ExecuteQueryResponse
responses []*proto.ExecuteQueryResponse
expected string
}{
{
name: "Test with ExecuteResult",
responses: []*command.ExecuteQueryResponse{
responses: []*proto.ExecuteQueryResponse{
{
Result: &command.ExecuteQueryResponse_E{
E: &command.ExecuteResult{
Result: &proto.ExecuteQueryResponse_E{
E: &proto.ExecuteResult{
LastInsertId: 123,
RowsAffected: 456,
},
@ -370,22 +370,22 @@ func Test_MarshalExecuteQueryResponse(t *testing.T) {
},
{
name: "Test with QueryRows",
responses: []*command.ExecuteQueryResponse{
responses: []*proto.ExecuteQueryResponse{
{
Result: &command.ExecuteQueryResponse_Q{
Q: &command.QueryRows{
Result: &proto.ExecuteQueryResponse_Q{
Q: &proto.QueryRows{
Columns: []string{"column1", "column2"},
Types: []string{"type1", "type2"},
Values: []*command.Values{
Values: []*proto.Values{
{
Parameters: []*command.Parameter{
Parameters: []*proto.Parameter{
{
Value: &command.Parameter_I{
Value: &proto.Parameter_I{
I: 123,
},
},
{
Value: &command.Parameter_S{
Value: &proto.Parameter_S{
S: "fiona",
},
},
@ -400,35 +400,35 @@ func Test_MarshalExecuteQueryResponse(t *testing.T) {
},
{
name: "Test with ExecuteResult and QueryRows",
responses: []*command.ExecuteQueryResponse{
responses: []*proto.ExecuteQueryResponse{
{
Result: &command.ExecuteQueryResponse_E{
E: &command.ExecuteResult{
Result: &proto.ExecuteQueryResponse_E{
E: &proto.ExecuteResult{
LastInsertId: 123,
RowsAffected: 456,
},
},
},
{
Result: &command.ExecuteQueryResponse_Error{
Result: &proto.ExecuteQueryResponse_Error{
Error: "unique constraint failed",
},
},
{
Result: &command.ExecuteQueryResponse_Q{
Q: &command.QueryRows{
Result: &proto.ExecuteQueryResponse_Q{
Q: &proto.QueryRows{
Columns: []string{"column1", "column2"},
Types: []string{"int", "text"},
Values: []*command.Values{
Values: []*proto.Values{
{
Parameters: []*command.Parameter{
Parameters: []*proto.Parameter{
{
Value: &command.Parameter_I{
Value: &proto.Parameter_I{
I: 456,
},
},
{
Value: &command.Parameter_S{
Value: &proto.Parameter_S{
S: "declan",
},
},
@ -439,11 +439,11 @@ func Test_MarshalExecuteQueryResponse(t *testing.T) {
},
},
{
Result: &command.ExecuteQueryResponse_Q{
Q: &command.QueryRows{
Result: &proto.ExecuteQueryResponse_Q{
Q: &proto.QueryRows{
Columns: []string{"column1", "column2"},
Types: []string{"int", "text"},
Values: []*command.Values{},
Values: []*proto.Values{},
},
},
},
@ -473,15 +473,15 @@ func Test_MarshalExecuteQueryAssociativeResponse(t *testing.T) {
tests := []struct {
name string
responses []*command.ExecuteQueryResponse
responses []*proto.ExecuteQueryResponse
expected string
}{
{
name: "Test with ExecuteResult",
responses: []*command.ExecuteQueryResponse{
responses: []*proto.ExecuteQueryResponse{
{
Result: &command.ExecuteQueryResponse_E{
E: &command.ExecuteResult{
Result: &proto.ExecuteQueryResponse_E{
E: &proto.ExecuteResult{
LastInsertId: 123,
RowsAffected: 456,
},
@ -492,22 +492,22 @@ func Test_MarshalExecuteQueryAssociativeResponse(t *testing.T) {
},
{
name: "Test with QueryRows",
responses: []*command.ExecuteQueryResponse{
responses: []*proto.ExecuteQueryResponse{
{
Result: &command.ExecuteQueryResponse_Q{
Q: &command.QueryRows{
Result: &proto.ExecuteQueryResponse_Q{
Q: &proto.QueryRows{
Columns: []string{"column1", "column2"},
Types: []string{"type1", "type2"},
Values: []*command.Values{
Values: []*proto.Values{
{
Parameters: []*command.Parameter{
Parameters: []*proto.Parameter{
{
Value: &command.Parameter_I{
Value: &proto.Parameter_I{
I: 123,
},
},
{
Value: &command.Parameter_S{
Value: &proto.Parameter_S{
S: "fiona",
},
},
@ -522,35 +522,35 @@ func Test_MarshalExecuteQueryAssociativeResponse(t *testing.T) {
},
{
name: "Test with ExecuteResult and QueryRows",
responses: []*command.ExecuteQueryResponse{
responses: []*proto.ExecuteQueryResponse{
{
Result: &command.ExecuteQueryResponse_E{
E: &command.ExecuteResult{
Result: &proto.ExecuteQueryResponse_E{
E: &proto.ExecuteResult{
LastInsertId: 123,
RowsAffected: 456,
},
},
},
{
Result: &command.ExecuteQueryResponse_Error{
Result: &proto.ExecuteQueryResponse_Error{
Error: "unique constraint failed",
},
},
{
Result: &command.ExecuteQueryResponse_Q{
Q: &command.QueryRows{
Result: &proto.ExecuteQueryResponse_Q{
Q: &proto.QueryRows{
Columns: []string{"column1", "column2"},
Types: []string{"int", "text"},
Values: []*command.Values{
Values: []*proto.Values{
{
Parameters: []*command.Parameter{
Parameters: []*proto.Parameter{
{
Value: &command.Parameter_I{
Value: &proto.Parameter_I{
I: 456,
},
},
{
Value: &command.Parameter_S{
Value: &proto.Parameter_S{
S: "declan",
},
},
@ -561,17 +561,17 @@ func Test_MarshalExecuteQueryAssociativeResponse(t *testing.T) {
},
},
{
Result: &command.ExecuteQueryResponse_Q{
Q: &command.QueryRows{
Result: &proto.ExecuteQueryResponse_Q{
Q: &proto.QueryRows{
Columns: []string{"aaa", "bbb"},
Types: []string{"int", "text"},
Values: []*command.Values{},
Values: []*proto.Values{},
},
},
},
{
Result: &command.ExecuteQueryResponse_Q{
Q: &command.QueryRows{
Result: &proto.ExecuteQueryResponse_Q{
Q: &proto.QueryRows{
Columns: []string{"ccc", "ddd"},
Types: []string{"int", "text"},
Values: nil,

@ -7,7 +7,8 @@ import (
"fmt"
"io"
"google.golang.org/protobuf/proto"
"github.com/rqlite/rqlite/v8/command/proto"
pb "google.golang.org/protobuf/proto"
)
const (
@ -18,8 +19,8 @@ const (
// Requester is the interface objects must support to be marshaled
// successfully.
type Requester interface {
proto.Message
GetRequest() *Request
pb.Message
GetRequest() *proto.Request
}
// RequestMarshaler marshals Request objects, potentially performing
@ -80,7 +81,7 @@ func (m *RequestMarshaler) Marshal(r Requester) ([]byte, bool, error) {
}
}
b, err := proto.Marshal(r)
b, err := pb.Marshal(r)
if err != nil {
return nil, false, err
}
@ -124,28 +125,28 @@ func (m *RequestMarshaler) Stats() map[string]interface{} {
}
// Marshal marshals a Command.
func Marshal(c *Command) ([]byte, error) {
return proto.Marshal(c)
func Marshal(c *proto.Command) ([]byte, error) {
return pb.Marshal(c)
}
// Unmarshal unmarshals a Command
func Unmarshal(b []byte, c *Command) error {
return proto.Unmarshal(b, c)
func Unmarshal(b []byte, c *proto.Command) error {
return pb.Unmarshal(b, c)
}
// MarshalNoop marshals a Noop command
func MarshalNoop(c *Noop) ([]byte, error) {
return proto.Marshal(c)
func MarshalNoop(c *proto.Noop) ([]byte, error) {
return pb.Marshal(c)
}
// UnmarshalNoop unmarshals a Noop command
func UnmarshalNoop(b []byte, c *Noop) error {
return proto.Unmarshal(b, c)
func UnmarshalNoop(b []byte, c *proto.Noop) error {
return pb.Unmarshal(b, c)
}
// MarshalLoadRequest marshals a LoadRequest command
func MarshalLoadRequest(lr *LoadRequest) ([]byte, error) {
b, err := proto.Marshal(lr)
func MarshalLoadRequest(lr *proto.LoadRequest) ([]byte, error) {
b, err := pb.Marshal(lr)
if err != nil {
return nil, err
}
@ -153,27 +154,27 @@ func MarshalLoadRequest(lr *LoadRequest) ([]byte, error) {
}
// UnmarshalLoadRequest unmarshals a LoadRequest command
func UnmarshalLoadRequest(b []byte, lr *LoadRequest) error {
func UnmarshalLoadRequest(b []byte, lr *proto.LoadRequest) error {
u, err := gzUncompress(b)
if err != nil {
return err
}
return proto.Unmarshal(u, lr)
return pb.Unmarshal(u, lr)
}
// MarshalLoadChunkRequest marshals a LoadChunkRequest command
func MarshalLoadChunkRequest(lr *LoadChunkRequest) ([]byte, error) {
return proto.Marshal(lr)
func MarshalLoadChunkRequest(lr *proto.LoadChunkRequest) ([]byte, error) {
return pb.Marshal(lr)
}
// UnmarshalLoadChunkRequest unmarshals a LoadChunkRequest command
func UnmarshalLoadChunkRequest(b []byte, lr *LoadChunkRequest) error {
return proto.Unmarshal(b, lr)
func UnmarshalLoadChunkRequest(b []byte, lr *proto.LoadChunkRequest) error {
return pb.Unmarshal(b, lr)
}
// UnmarshalSubCommand unmarshalls a sub command m. It assumes that
// m is the correct type.
func UnmarshalSubCommand(c *Command, m proto.Message) error {
func UnmarshalSubCommand(c *proto.Command, m pb.Message) error {
b := c.SubCommand
if c.Compressed {
var err error
@ -183,7 +184,7 @@ func UnmarshalSubCommand(c *Command, m proto.Message) error {
}
}
if err := proto.Unmarshal(b, m); err != nil {
if err := pb.Unmarshal(b, m); err != nil {
return fmt.Errorf("proto unmarshal: %s", err)
}
return nil

@ -4,7 +4,8 @@ import (
"sync"
"testing"
"google.golang.org/protobuf/proto"
"github.com/rqlite/rqlite/v8/command/proto"
pb "google.golang.org/protobuf/proto"
)
func Test_NewRequestMarshaler(t *testing.T) {
@ -16,9 +17,9 @@ func Test_NewRequestMarshaler(t *testing.T) {
func Test_MarshalUncompressed(t *testing.T) {
rm := NewRequestMarshaler()
r := &QueryRequest{
Request: &Request{
Statements: []*Statement{
r := &proto.QueryRequest{
Request: &proto.Request{
Statements: []*proto.Statement{
{
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
},
@ -36,8 +37,8 @@ func Test_MarshalUncompressed(t *testing.T) {
t.Fatal("Marshaled QueryRequest incorrectly compressed")
}
c := &Command{
Type: Command_COMMAND_TYPE_QUERY,
c := &proto.Command{
Type: proto.Command_COMMAND_TYPE_QUERY,
SubCommand: b,
Compressed: comp,
}
@ -47,18 +48,18 @@ func Test_MarshalUncompressed(t *testing.T) {
t.Fatalf("failed to marshal Command: %s", err)
}
var nc Command
var nc proto.Command
if err := Unmarshal(b, &nc); err != nil {
t.Fatalf("failed to unmarshal Command: %s", err)
}
if nc.Type != Command_COMMAND_TYPE_QUERY {
if nc.Type != proto.Command_COMMAND_TYPE_QUERY {
t.Fatalf("unmarshaled command has wrong type: %s", nc.Type)
}
if nc.Compressed {
t.Fatal("Unmarshaled QueryRequest incorrectly marked as compressed")
}
var nr QueryRequest
var nr proto.QueryRequest
if err := UnmarshalSubCommand(&nc, &nr); err != nil {
t.Fatalf("failed to unmarshal sub command: %s", err)
}
@ -81,9 +82,9 @@ func Test_MarshalCompressedBatch(t *testing.T) {
rm.BatchThreshold = 1
rm.ForceCompression = true
r := &QueryRequest{
Request: &Request{
Statements: []*Statement{
r := &proto.QueryRequest{
Request: &proto.Request{
Statements: []*proto.Statement{
{
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
},
@ -101,8 +102,8 @@ func Test_MarshalCompressedBatch(t *testing.T) {
t.Fatal("Marshaled QueryRequest wasn't compressed")
}
c := &Command{
Type: Command_COMMAND_TYPE_QUERY,
c := &proto.Command{
Type: proto.Command_COMMAND_TYPE_QUERY,
SubCommand: b,
Compressed: comp,
}
@ -112,22 +113,22 @@ func Test_MarshalCompressedBatch(t *testing.T) {
t.Fatalf("failed to marshal Command: %s", err)
}
var nc Command
var nc proto.Command
if err := Unmarshal(b, &nc); err != nil {
t.Fatalf("failed to unmarshal Command: %s", err)
}
if nc.Type != Command_COMMAND_TYPE_QUERY {
if nc.Type != proto.Command_COMMAND_TYPE_QUERY {
t.Fatalf("unmarshaled command has wrong type: %s", nc.Type)
}
if !nc.Compressed {
t.Fatal("Unmarshaled QueryRequest incorrectly marked as uncompressed")
}
var nr QueryRequest
var nr proto.QueryRequest
if err := UnmarshalSubCommand(&nc, &nr); err != nil {
t.Fatalf("failed to unmarshal sub command: %s", err)
}
if !proto.Equal(&nr, r) {
if !pb.Equal(&nr, r) {
t.Fatal("Original and unmarshaled Query Request are not equal")
}
}
@ -137,9 +138,9 @@ func Test_MarshalCompressedSize(t *testing.T) {
rm.SizeThreshold = 1
rm.ForceCompression = true
r := &QueryRequest{
Request: &Request{
Statements: []*Statement{
r := &proto.QueryRequest{
Request: &proto.Request{
Statements: []*proto.Statement{
{
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
},
@ -157,8 +158,8 @@ func Test_MarshalCompressedSize(t *testing.T) {
t.Fatal("Marshaled QueryRequest wasn't compressed")
}
c := &Command{
Type: Command_COMMAND_TYPE_QUERY,
c := &proto.Command{
Type: proto.Command_COMMAND_TYPE_QUERY,
SubCommand: b,
Compressed: comp,
}
@ -168,22 +169,22 @@ func Test_MarshalCompressedSize(t *testing.T) {
t.Fatalf("failed to marshal Command: %s", err)
}
var nc Command
var nc proto.Command
if err := Unmarshal(b, &nc); err != nil {
t.Fatalf("failed to unmarshal Command: %s", err)
}
if nc.Type != Command_COMMAND_TYPE_QUERY {
if nc.Type != proto.Command_COMMAND_TYPE_QUERY {
t.Fatalf("unmarshaled command has wrong type: %s", nc.Type)
}
if !nc.Compressed {
t.Fatal("Unmarshaled QueryRequest incorrectly marked as uncompressed")
}
var nr QueryRequest
var nr proto.QueryRequest
if err := UnmarshalSubCommand(&nc, &nr); err != nil {
t.Fatalf("failed to unmarshal sub command: %s", err)
}
if !proto.Equal(&nr, r) {
if !pb.Equal(&nr, r) {
t.Fatal("Original and unmarshaled Query Request are not equal")
}
}
@ -192,9 +193,9 @@ func Test_MarshalWontCompressBatch(t *testing.T) {
rm := NewRequestMarshaler()
rm.BatchThreshold = 1
r := &QueryRequest{
Request: &Request{
Statements: []*Statement{
r := &proto.QueryRequest{
Request: &proto.Request{
Statements: []*proto.Statement{
{
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
},
@ -218,9 +219,9 @@ func Test_MarshalCompressedConcurrent(t *testing.T) {
rm.SizeThreshold = 1
rm.ForceCompression = true
r := &QueryRequest{
Request: &Request{
Statements: []*Statement{
r := &proto.QueryRequest{
Request: &proto.Request{
Statements: []*proto.Statement{
{
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
},
@ -251,9 +252,9 @@ func Test_MarshalWontCompressSize(t *testing.T) {
rm := NewRequestMarshaler()
rm.SizeThreshold = 1
r := &QueryRequest{
Request: &Request{
Statements: []*Statement{
r := &proto.QueryRequest{
Request: &proto.Request{
Statements: []*proto.Statement{
{
Sql: `INSERT INTO "names" VALUES(1,'bob','123-45-678')`,
},

@ -1,7 +1,6 @@
syntax = "proto3";
package command;
option go_package = "github.com/rqlite/rqlite/v8/command";
option go_package = "github.com/rqlite/rqlite/command/proto";
message Parameter {
oneof value {

@ -3,12 +3,13 @@ package command
import (
"strings"
"github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/sql"
)
// Rewrite rewrites the statements such that RANDOM is rewritten,
// if r is true.
func Rewrite(stmts []*Statement, r bool) error {
func Rewrite(stmts []*proto.Statement, r bool) error {
if !r {
return nil
}

@ -3,6 +3,8 @@ package command
import (
"regexp"
"testing"
"github.com/rqlite/rqlite/v8/command/proto"
)
func Test_NoRewrites(t *testing.T) {
@ -13,7 +15,7 @@ func Test_NoRewrites(t *testing.T) {
`INSERT INTO foo(name, age) VALUES(?, ?)`,
} {
stmts := []*Statement{
stmts := []*proto.Statement{
{
Sql: str,
},
@ -28,7 +30,7 @@ func Test_NoRewrites(t *testing.T) {
}
func Test_NoRewritesMulti(t *testing.T) {
stmts := []*Statement{
stmts := []*proto.Statement{
{
Sql: `INSERT INTO "names" VALUES (1, 'bob', '123-45-678')`,
},
@ -65,7 +67,7 @@ func Test_Rewrites(t *testing.T) {
`CREATE TABLE tbl (col1 TEXT, ts DATETIME DEFAULT CURRENT_TIMESTAMP)`, `CREATE TABLE tbl \(col1 TEXT, ts DATETIME DEFAULT CURRENT_TIMESTAMP\)`,
}
for i := 0; i < len(testSQLs)-1; i += 2 {
stmts := []*Statement{
stmts := []*proto.Statement{
{
Sql: testSQLs[i],
},

@ -18,7 +18,7 @@ import (
"time"
"github.com/rqlite/go-sqlite3"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/db/humanize"
)

@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/testdata/chinook"
)

@ -10,8 +10,8 @@ import (
"testing"
"time"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/encoding"
command "github.com/rqlite/rqlite/v8/command/proto"
)
// Test_OpenNonExistentDatabase tests that opening a non-existent database

@ -7,7 +7,7 @@ import (
"strings"
"time"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
)
// QueryParams represents the query parameters passed in an HTTP request.

@ -6,7 +6,7 @@ import (
"errors"
"fmt"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
)
var (

@ -24,6 +24,7 @@ import (
"github.com/rqlite/rqlite/v8/cluster"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/encoding"
"github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/db"
"github.com/rqlite/rqlite/v8/queue"
"github.com/rqlite/rqlite/v8/rtls"
@ -46,20 +47,20 @@ type Database interface {
// to return rows. If timings is true, then timing information will
// be return. If tx is true, then either all queries will be executed
// successfully or it will as though none executed.
Execute(er *command.ExecuteRequest) ([]*command.ExecuteResult, error)
Execute(er *proto.ExecuteRequest) ([]*proto.ExecuteResult, error)
// Query executes a slice of queries, each of which returns rows. If
// timings is true, then timing information will be returned. If tx
// is true, then all queries will take place while a read transaction
// is held on the database.
Query(qr *command.QueryRequest) ([]*command.QueryRows, error)
Query(qr *proto.QueryRequest) ([]*proto.QueryRows, error)
// Request processes a slice of requests, each of which can be either
// an Execute or Query request.
Request(eqr *command.ExecuteQueryRequest) ([]*command.ExecuteQueryResponse, error)
Request(eqr *proto.ExecuteQueryRequest) ([]*proto.ExecuteQueryResponse, error)
// Load loads a SQLite file into the system via Raft consensus.
Load(lr *command.LoadRequest) error
Load(lr *proto.LoadRequest) error
}
// Store is the interface the Raft-based database must implement.
@ -67,7 +68,7 @@ type Store interface {
Database
// Remove removes the node from the cluster.
Remove(rn *command.RemoveNodeRequest) error
Remove(rn *proto.RemoveNodeRequest) error
// LeaderAddr returns the Raft address of the leader of the cluster.
LeaderAddr() (string, error)
@ -82,7 +83,7 @@ type Store interface {
Nodes() ([]*store.Server, error)
// Backup writes backup of the node state to dst
Backup(br *command.BackupRequest, dst io.Writer) error
Backup(br *proto.BackupRequest, dst io.Writer) error
// ReadFrom reads and loads a SQLite database into the node, initially bypassing
// the Raft system. It then triggers a Raft snapshot, which will then make
@ -101,22 +102,22 @@ type Cluster interface {
GetAddresser
// Execute performs an Execute Request on a remote node.
Execute(er *command.ExecuteRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*command.ExecuteResult, error)
Execute(er *proto.ExecuteRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*proto.ExecuteResult, error)
// Query performs an Query Request on a remote node.
Query(qr *command.QueryRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*command.QueryRows, error)
Query(qr *proto.QueryRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*proto.QueryRows, error)
// Request performs an ExecuteQuery Request on a remote node.
Request(eqr *command.ExecuteQueryRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*command.ExecuteQueryResponse, error)
Request(eqr *proto.ExecuteQueryRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) ([]*proto.ExecuteQueryResponse, error)
// Backup retrieves a backup from a remote node and writes to the io.Writer.
Backup(br *command.BackupRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration, w io.Writer) error
Backup(br *proto.BackupRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration, w io.Writer) error
// Load loads a SQLite database into the node.
Load(lr *command.LoadRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) error
Load(lr *proto.LoadRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) error
// RemoveNode removes a node from the cluster.
RemoveNode(rn *command.RemoveNodeRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) error
RemoveNode(rn *proto.RemoveNodeRequest, nodeAddr string, creds *cluster.Credentials, timeout time.Duration) error
// Stats returns stats on the Cluster.
Stats() (map[string]interface{}, error)
@ -136,9 +137,9 @@ type StatusReporter interface {
// DBResults stores either an Execute result, a Query result, or
// an ExecuteQuery result.
type DBResults struct {
ExecuteResult []*command.ExecuteResult
QueryRows []*command.QueryRows
ExecuteQueryResponse []*command.ExecuteQueryResponse
ExecuteResult []*proto.ExecuteResult
QueryRows []*proto.QueryRows
ExecuteQueryResponse []*proto.ExecuteQueryResponse
AssociativeJSON bool // Render in associative form
}
@ -540,7 +541,7 @@ func (s *Service) handleRemove(w http.ResponseWriter, r *http.Request, qp QueryP
return
}
rn := &command.RemoveNodeRequest{
rn := &proto.RemoveNodeRequest{
Id: remoteID,
}
@ -598,7 +599,7 @@ func (s *Service) handleBackup(w http.ResponseWriter, r *http.Request, qp QueryP
return
}
br := &command.BackupRequest{
br := &proto.BackupRequest{
Format: qp.BackupFormat(),
Leader: !qp.NoLeader(),
Vacuum: qp.Vacuum(),
@ -674,7 +675,7 @@ func (s *Service) handleLoad(w http.ResponseWriter, r *http.Request, qp QueryPar
if db.IsValidSQLiteData(b) {
s.logger.Printf("SQLite database file detected as load data")
lr := &command.LoadRequest{
lr := &proto.LoadRequest{
Data: b,
}
@ -1121,8 +1122,8 @@ func (s *Service) execute(w http.ResponseWriter, r *http.Request, qp QueryParams
return
}
er := &command.ExecuteRequest{
Request: &command.Request{
er := &proto.ExecuteRequest{
Request: &proto.Request{
Transaction: qp.Tx(),
Statements: stmts,
},
@ -1197,7 +1198,7 @@ func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request, qp QueryPa
// No point rewriting queries if they don't go through the Raft log, since they
// will never be replayed from the log anyway.
if qp.Level() == command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG {
if qp.Level() == proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG {
if err := command.Rewrite(queries, qp.NoRewriteRandom()); err != nil {
http.Error(w, fmt.Sprintf("SQL rewrite: %s", err.Error()), http.StatusInternalServerError)
return
@ -1207,8 +1208,8 @@ func (s *Service) handleQuery(w http.ResponseWriter, r *http.Request, qp QueryPa
resp := NewResponse()
resp.Results.AssociativeJSON = qp.Associative()
qr := &command.QueryRequest{
Request: &command.Request{
qr := &proto.QueryRequest{
Request: &proto.Request{
Transaction: qp.Tx(),
Statements: queries,
},
@ -1294,8 +1295,8 @@ func (s *Service) handleRequest(w http.ResponseWriter, r *http.Request, qp Query
resp := NewResponse()
resp.Results.AssociativeJSON = qp.Associative()
eqr := &command.ExecuteQueryRequest{
Request: &command.Request{
eqr := &proto.ExecuteQueryRequest{
Request: &proto.Request{
Transaction: qp.Tx(),
Statements: stmts,
},
@ -1502,8 +1503,8 @@ func (s *Service) runQueue() {
case <-s.closeCh:
return
case req := <-s.stmtQueue.C:
er := &command.ExecuteRequest{
Request: &command.Request{
er := &proto.ExecuteRequest{
Request: &proto.Request{
Statements: req.Statements,
Transaction: s.DefaultQueueTx,
},
@ -1590,7 +1591,7 @@ func (s *Service) addAllowHeaders(w http.ResponseWriter) {
// addBackupFormatHeader adds the Content-Type header for the backup format.
func addBackupFormatHeader(w http.ResponseWriter, qp QueryParams) {
w.Header().Set("Content-Type", "application/octet-stream")
if qp.BackupFormat() == command.BackupRequest_BACKUP_REQUEST_FORMAT_SQL {
if qp.BackupFormat() == proto.BackupRequest_BACKUP_REQUEST_FORMAT_SQL {
w.Header().Set("Content-Type", "application/sql")
}
}
@ -1634,9 +1635,9 @@ func (s *Service) writeResponse(w http.ResponseWriter, r *http.Request, qp Query
}
}
func requestQueries(r *http.Request, qp QueryParams) ([]*command.Statement, error) {
func requestQueries(r *http.Request, qp QueryParams) ([]*proto.Statement, error) {
if r.Method == "GET" {
return []*command.Statement{
return []*proto.Statement{
{
Sql: qp.Query(),
},
@ -1698,16 +1699,16 @@ func prettyEnabled(e bool) string {
}
// queryRequestFromStrings converts a slice of strings into a command.QueryRequest
func executeRequestFromStrings(s []string, timings, tx bool) *command.ExecuteRequest {
stmts := make([]*command.Statement, len(s))
func executeRequestFromStrings(s []string, timings, tx bool) *proto.ExecuteRequest {
stmts := make([]*proto.Statement, len(s))
for i := range s {
stmts[i] = &command.Statement{
stmts[i] = &proto.Statement{
Sql: s[i],
}
}
return &command.ExecuteRequest{
Request: &command.Request{
return &proto.ExecuteRequest{
Request: &proto.Request{
Statements: stmts,
Transaction: tx,
},

@ -14,7 +14,7 @@ import (
"time"
"github.com/rqlite/rqlite/v8/cluster"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/store"
)

@ -6,7 +6,7 @@ import (
"sync"
"time"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
)
// stats captures stats for the Queue.

@ -5,7 +5,7 @@ import (
"testing"
"time"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
)
var (

@ -7,6 +7,7 @@ import (
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/chunking"
"github.com/rqlite/rqlite/v8/command/proto"
sql "github.com/rqlite/rqlite/v8/db"
)
@ -24,37 +25,37 @@ func NewCommandProcessor(logger *log.Logger, dm *chunking.DechunkerManager) *Com
}
// Process processes the given command against the given database.
func (c *CommandProcessor) Process(data []byte, pDB **sql.DB) (*command.Command, interface{}) {
func (c *CommandProcessor) Process(data []byte, pDB **sql.DB) (*proto.Command, interface{}) {
db := *pDB
cmd := &command.Command{}
cmd := &proto.Command{}
if err := command.Unmarshal(data, cmd); err != nil {
panic(fmt.Sprintf("failed to unmarshal cluster command: %s", err.Error()))
}
switch cmd.Type {
case command.Command_COMMAND_TYPE_QUERY:
var qr command.QueryRequest
case proto.Command_COMMAND_TYPE_QUERY:
var qr proto.QueryRequest
if err := command.UnmarshalSubCommand(cmd, &qr); err != nil {
panic(fmt.Sprintf("failed to unmarshal query subcommand: %s", err.Error()))
}
r, err := db.Query(qr.Request, qr.Timings)
return cmd, &fsmQueryResponse{rows: r, error: err}
case command.Command_COMMAND_TYPE_EXECUTE:
var er command.ExecuteRequest
case proto.Command_COMMAND_TYPE_EXECUTE:
var er proto.ExecuteRequest
if err := command.UnmarshalSubCommand(cmd, &er); err != nil {
panic(fmt.Sprintf("failed to unmarshal execute subcommand: %s", err.Error()))
}
r, err := db.Execute(er.Request, er.Timings)
return cmd, &fsmExecuteResponse{results: r, error: err}
case command.Command_COMMAND_TYPE_EXECUTE_QUERY:
var eqr command.ExecuteQueryRequest
case proto.Command_COMMAND_TYPE_EXECUTE_QUERY:
var eqr proto.ExecuteQueryRequest
if err := command.UnmarshalSubCommand(cmd, &eqr); err != nil {
panic(fmt.Sprintf("failed to unmarshal execute-query subcommand: %s", err.Error()))
}
r, err := db.Request(eqr.Request, eqr.Timings)
return cmd, &fsmExecuteQueryResponse{results: r, error: err}
case command.Command_COMMAND_TYPE_LOAD:
var lr command.LoadRequest
case proto.Command_COMMAND_TYPE_LOAD:
var lr proto.LoadRequest
if err := command.UnmarshalLoadRequest(cmd.SubCommand, &lr); err != nil {
panic(fmt.Sprintf("failed to unmarshal load subcommand: %s", err.Error()))
}
@ -74,8 +75,8 @@ func (c *CommandProcessor) Process(data []byte, pDB **sql.DB) (*command.Command,
*pDB = newDB
return cmd, &fsmGenericResponse{}
case command.Command_COMMAND_TYPE_LOAD_CHUNK:
var lcr command.LoadChunkRequest
case proto.Command_COMMAND_TYPE_LOAD_CHUNK:
var lcr proto.LoadChunkRequest
if err := command.UnmarshalLoadChunkRequest(cmd.SubCommand, &lcr); err != nil {
panic(fmt.Sprintf("failed to unmarshal load-chunk subcommand: %s", err.Error()))
}
@ -134,7 +135,7 @@ func (c *CommandProcessor) Process(data []byte, pDB **sql.DB) (*command.Command,
}
}
return cmd, &fsmGenericResponse{}
case command.Command_COMMAND_TYPE_NOOP:
case proto.Command_COMMAND_TYPE_NOOP:
return cmd, &fsmGenericResponse{}
default:
return cmd, &fsmGenericResponse{error: fmt.Errorf("unhandled command: %v", cmd.Type)}

@ -5,7 +5,7 @@ import (
"testing"
"time"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
)
// Test_SingleNodeProvide tests that the Store correctly implements

@ -22,6 +22,7 @@ import (
"github.com/hashicorp/raft"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/chunking"
"github.com/rqlite/rqlite/v8/command/proto"
sql "github.com/rqlite/rqlite/v8/db"
"github.com/rqlite/rqlite/v8/db/humanize"
wal "github.com/rqlite/rqlite/v8/db/wal"
@ -1002,7 +1003,7 @@ func (s *Store) Stats() (map[string]interface{}, error) {
}
// Execute executes queries that return no rows, but do modify the database.
func (s *Store) Execute(ex *command.ExecuteRequest) ([]*command.ExecuteResult, error) {
func (s *Store) Execute(ex *proto.ExecuteRequest) ([]*proto.ExecuteResult, error) {
if !s.open {
return nil, ErrNotOpen
}
@ -1017,14 +1018,14 @@ func (s *Store) Execute(ex *command.ExecuteRequest) ([]*command.ExecuteResult, e
return s.execute(ex)
}
func (s *Store) execute(ex *command.ExecuteRequest) ([]*command.ExecuteResult, error) {
func (s *Store) execute(ex *proto.ExecuteRequest) ([]*proto.ExecuteResult, error) {
b, compressed, err := s.tryCompress(ex)
if err != nil {
return nil, err
}
c := &command.Command{
Type: command.Command_COMMAND_TYPE_EXECUTE,
c := &proto.Command{
Type: proto.Command_COMMAND_TYPE_EXECUTE,
SubCommand: b,
Compressed: compressed,
}
@ -1050,12 +1051,12 @@ func (s *Store) execute(ex *command.ExecuteRequest) ([]*command.ExecuteResult, e
}
// Query executes queries that return rows, and do not modify the database.
func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) {
func (s *Store) Query(qr *proto.QueryRequest) ([]*proto.QueryRows, error) {
if !s.open {
return nil, ErrNotOpen
}
if qr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG {
if qr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG {
if s.raft.State() != raft.Leader {
return nil, ErrNotLeader
}
@ -1068,8 +1069,8 @@ func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) {
if err != nil {
return nil, err
}
c := &command.Command{
Type: command.Command_COMMAND_TYPE_QUERY,
c := &proto.Command{
Type: proto.Command_COMMAND_TYPE_QUERY,
SubCommand: b,
Compressed: compressed,
}
@ -1094,11 +1095,11 @@ func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) {
return r.rows, r.error
}
if qr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK && s.raft.State() != raft.Leader {
if qr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK && s.raft.State() != raft.Leader {
return nil, ErrNotLeader
}
if s.raft.State() != raft.Leader && qr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_NONE &&
if s.raft.State() != raft.Leader && qr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE &&
qr.Freshness > 0 && time.Since(s.raft.LastContact()).Nanoseconds() > qr.Freshness {
return nil, ErrStaleRead
}
@ -1114,13 +1115,13 @@ func (s *Store) Query(qr *command.QueryRequest) ([]*command.QueryRows, error) {
}
// Request processes a request that may contain both Executes and Queries.
func (s *Store) Request(eqr *command.ExecuteQueryRequest) ([]*command.ExecuteQueryResponse, error) {
func (s *Store) Request(eqr *proto.ExecuteQueryRequest) ([]*proto.ExecuteQueryResponse, error) {
if !s.open {
return nil, ErrNotOpen
}
if !s.RequiresLeader(eqr) {
if eqr.Level == command.QueryRequest_QUERY_REQUEST_LEVEL_NONE && eqr.Freshness > 0 &&
if eqr.Level == proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE && eqr.Freshness > 0 &&
time.Since(s.raft.LastContact()).Nanoseconds() > eqr.Freshness {
return nil, ErrStaleRead
}
@ -1146,8 +1147,8 @@ func (s *Store) Request(eqr *command.ExecuteQueryRequest) ([]*command.ExecuteQue
return nil, err
}
c := &command.Command{
Type: command.Command_COMMAND_TYPE_EXECUTE_QUERY,
c := &proto.Command{
Type: proto.Command_COMMAND_TYPE_EXECUTE_QUERY,
SubCommand: b,
Compressed: compressed,
}
@ -1173,12 +1174,12 @@ func (s *Store) Request(eqr *command.ExecuteQueryRequest) ([]*command.ExecuteQue
}
// Backup writes a consistent snapshot of the underlying database to dst.
func (s *Store) Backup(br *command.BackupRequest, dst io.Writer) (retErr error) {
func (s *Store) Backup(br *proto.BackupRequest, dst io.Writer) (retErr error) {
if !s.open {
return ErrNotOpen
}
if br.Vacuum && br.Format != command.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY {
if br.Vacuum && br.Format != proto.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY {
return ErrInvalidBackupFormat
}
@ -1194,7 +1195,7 @@ func (s *Store) Backup(br *command.BackupRequest, dst io.Writer) (retErr error)
return ErrNotLeader
}
if br.Format == command.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY {
if br.Format == proto.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY {
f, err := os.CreateTemp(s.dbDir, backupScatchPattern)
if err != nil {
return err
@ -1216,7 +1217,7 @@ func (s *Store) Backup(br *command.BackupRequest, dst io.Writer) (retErr error)
_, err = io.Copy(dst, of)
return err
} else if br.Format == command.BackupRequest_BACKUP_REQUEST_FORMAT_SQL {
} else if br.Format == proto.BackupRequest_BACKUP_REQUEST_FORMAT_SQL {
return s.db.Dump(dst)
}
return ErrInvalidBackupFormat
@ -1224,7 +1225,7 @@ func (s *Store) Backup(br *command.BackupRequest, dst io.Writer) (retErr error)
// Loads an entire SQLite file into the database, sending the request
// through the Raft log.
func (s *Store) Load(lr *command.LoadRequest) error {
func (s *Store) Load(lr *proto.LoadRequest) error {
if !s.open {
return ErrNotOpen
}
@ -1242,7 +1243,7 @@ func (s *Store) Load(lr *command.LoadRequest) error {
// load loads an entire SQLite file into the database, and is for internal use
// only. It does not check for readiness, and does not update statistics.
func (s *Store) load(lr *command.LoadRequest) error {
func (s *Store) load(lr *proto.LoadRequest) error {
startT := time.Now()
b, err := command.MarshalLoadRequest(lr)
@ -1251,8 +1252,8 @@ func (s *Store) load(lr *command.LoadRequest) error {
return err
}
c := &command.Command{
Type: command.Command_COMMAND_TYPE_LOAD,
c := &proto.Command{
Type: proto.Command_COMMAND_TYPE_LOAD,
SubCommand: b,
}
@ -1364,7 +1365,7 @@ func (s *Store) ReadFrom(r io.Reader) (int64, error) {
// with the *advertised Raft address* which the Store doesn't know about.
//
// Notifying is idempotent. A node may repeatedly notify the Store without issue.
func (s *Store) Notify(nr *command.NotifyRequest) error {
func (s *Store) Notify(nr *proto.NotifyRequest) error {
if !s.open {
return ErrNotOpen
}
@ -1423,7 +1424,7 @@ func (s *Store) Notify(nr *command.NotifyRequest) error {
// Join joins a node, identified by id and located at addr, to this store.
// The node must be ready to respond to Raft communications at that address.
func (s *Store) Join(jr *command.JoinRequest) error {
func (s *Store) Join(jr *proto.JoinRequest) error {
if !s.open {
return ErrNotOpen
}
@ -1491,7 +1492,7 @@ func (s *Store) Join(jr *command.JoinRequest) error {
}
// Remove removes a node from the store.
func (s *Store) Remove(rn *command.RemoveNodeRequest) error {
func (s *Store) Remove(rn *proto.RemoveNodeRequest) error {
if !s.open {
return ErrNotOpen
}
@ -1510,7 +1511,7 @@ func (s *Store) Remove(rn *command.RemoveNodeRequest) error {
// consumes a slot in the Raft log, but has no other effect on the
// system.
func (s *Store) Noop(id string) (raft.ApplyFuture, error) {
n := &command.Noop{
n := &proto.Noop{
Id: id,
}
b, err := command.MarshalNoop(n)
@ -1518,8 +1519,8 @@ func (s *Store) Noop(id string) (raft.ApplyFuture, error) {
return nil, err
}
c := &command.Command{
Type: command.Command_COMMAND_TYPE_NOOP,
c := &proto.Command{
Type: proto.Command_COMMAND_TYPE_NOOP,
SubCommand: b,
}
bc, err := command.Marshal(c)
@ -1532,8 +1533,8 @@ func (s *Store) Noop(id string) (raft.ApplyFuture, error) {
// RequiresLeader returns whether the given ExecuteQueryRequest must be
// processed on the cluster Leader.
func (s *Store) RequiresLeader(eqr *command.ExecuteQueryRequest) bool {
if eqr.Level != command.QueryRequest_QUERY_REQUEST_LEVEL_NONE {
func (s *Store) RequiresLeader(eqr *proto.ExecuteQueryRequest) bool {
if eqr.Level != proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE {
return true
}
@ -1631,17 +1632,17 @@ func (s *Store) updateAppliedIndex() chan struct{} {
}
type fsmExecuteResponse struct {
results []*command.ExecuteResult
results []*proto.ExecuteResult
error error
}
type fsmQueryResponse struct {
rows []*command.QueryRows
rows []*proto.QueryRows
error error
}
type fsmExecuteQueryResponse struct {
results []*command.ExecuteQueryResponse
results []*proto.ExecuteQueryResponse
error error
}
@ -1673,7 +1674,7 @@ func (s *Store) fsmApply(l *raft.Log) (e interface{}) {
}
cmd, r := s.cmdProc.Process(l.Data, &s.db)
if cmd.Type == command.Command_COMMAND_TYPE_NOOP {
if cmd.Type == proto.Command_COMMAND_TYPE_NOOP {
s.numNoops++
}
return r
@ -2039,7 +2040,7 @@ func (s *Store) installRestore() error {
if err != nil {
return err
}
lr := &command.LoadRequest{
lr := &proto.LoadRequest{
Data: b,
}
return s.load(lr)

@ -6,7 +6,7 @@ import (
"testing"
"time"
"github.com/rqlite/rqlite/v8/command"
command "github.com/rqlite/rqlite/v8/command/proto"
)
func test_OpenStoreCloseStartup(t *testing.T, s *Store) {

@ -13,8 +13,8 @@ import (
"testing"
"time"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/encoding"
"github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/db"
"github.com/rqlite/rqlite/v8/random"
"github.com/rqlite/rqlite/v8/testdata/chinook"
@ -77,7 +77,7 @@ func Test_SingleNodeOnDiskSQLitePath(t *testing.T) {
}
qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -367,7 +367,7 @@ func Test_OpenStoreCloseSingleNode(t *testing.T) {
}
qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -496,7 +496,7 @@ func Test_SingleNodeExecuteQuery(t *testing.T) {
}
qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -564,21 +564,21 @@ func Test_SingleNodeExecuteQueryTx(t *testing.T) {
}
qr := queryRequestFromString("SELECT * FROM foo", false, true)
var r []*command.QueryRows
var r []*proto.QueryRows
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
_, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
}
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
_, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
}
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -660,7 +660,7 @@ func Test_SingleNodeRequest(t *testing.T) {
}
for _, tt := range tests {
eqr := executeQueryRequestFromStrings(tt.stmts, command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK, false, false)
eqr := executeQueryRequestFromStrings(tt.stmts, proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK, false, false)
r, err := s.Request(eqr)
if err != nil {
t.Fatalf("failed to execute request on single node: %s", err.Error())
@ -740,7 +740,7 @@ func Test_SingleNodeRequestTx(t *testing.T) {
}
for _, tt := range tests {
eqr := executeQueryRequestFromStrings(tt.stmts, command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK, false, tt.tx)
eqr := executeQueryRequestFromStrings(tt.stmts, proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK, false, tt.tx)
r, err := s.Request(eqr)
if err != nil {
t.Fatalf("failed to execute request on single node: %s", err.Error())
@ -780,18 +780,18 @@ func Test_SingleNodeRequestParameters(t *testing.T) {
}
tests := []struct {
request *command.ExecuteQueryRequest
request *proto.ExecuteQueryRequest
expected string
}{
{
request: &command.ExecuteQueryRequest{
Request: &command.Request{
Statements: []*command.Statement{
request: &proto.ExecuteQueryRequest{
Request: &proto.Request{
Statements: []*proto.Statement{
{
Sql: "SELECT * FROM foo WHERE id = ?",
Parameters: []*command.Parameter{
Parameters: []*proto.Parameter{
{
Value: &command.Parameter_I{
Value: &proto.Parameter_I{
I: 1,
},
},
@ -803,14 +803,14 @@ func Test_SingleNodeRequestParameters(t *testing.T) {
expected: `[{"columns":["id","name"],"types":["integer","text"],"values":[[1,"fiona"]]}]`,
},
{
request: &command.ExecuteQueryRequest{
Request: &command.Request{
Statements: []*command.Statement{
request: &proto.ExecuteQueryRequest{
Request: &proto.Request{
Statements: []*proto.Statement{
{
Sql: "SELECT id FROM foo WHERE name = :qux",
Parameters: []*command.Parameter{
Parameters: []*proto.Parameter{
{
Value: &command.Parameter_S{
Value: &proto.Parameter_S{
S: "fiona",
},
Name: "qux",
@ -894,7 +894,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
}
// Every query should return the same results, so use a function for the check.
check := func(r []*command.QueryRows) {
check := func(r []*proto.QueryRows) {
if exp, got := `["id","name"]`, asJSON(r[0].Columns); exp != got {
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
}
@ -904,7 +904,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
}
qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -912,7 +912,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
check(r)
qr = queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -920,7 +920,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
check(r)
qr = queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -929,7 +929,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
qr = queryRequestFromString("SELECT * FROM foo", false, true)
qr.Timings = true
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -938,7 +938,7 @@ func Test_SingleNodeOnDiskFileExecuteQuery(t *testing.T) {
qr = queryRequestFromString("SELECT * FROM foo", true, false)
qr.Request.Transaction = true
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1071,7 +1071,7 @@ COMMIT;
// Check that data were loaded correctly.
qr := queryRequestFromString("SELECT * FROM foo", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1159,7 +1159,7 @@ func Test_SingleNodeLoadTextChinook(t *testing.T) {
// Check that data were loaded correctly.
qr := queryRequestFromString("SELECT count(*) FROM track", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1172,7 +1172,7 @@ func Test_SingleNodeLoadTextChinook(t *testing.T) {
}
qr = queryRequestFromString("SELECT count(*) FROM album", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1185,7 +1185,7 @@ func Test_SingleNodeLoadTextChinook(t *testing.T) {
}
qr = queryRequestFromString("SELECT count(*) FROM artist", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1229,7 +1229,7 @@ COMMIT;
// Check that data were loaded correctly.
qr := queryRequestFromString("SELECT * FROM bar", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1248,7 +1248,7 @@ COMMIT;
// Check that data were loaded correctly.
qr = queryRequestFromString("SELECT * FROM foo WHERE id=2", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1260,7 +1260,7 @@ COMMIT;
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
}
qr = queryRequestFromString("SELECT count(*) FROM foo", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1274,7 +1274,7 @@ COMMIT;
// Check pre-existing data is gone.
qr = queryRequestFromString("SELECT * FROM bar", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1379,7 +1379,7 @@ COMMIT;
// Check that data were loaded correctly.
qr := queryRequestFromString("SELECT * FROM bar", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1415,7 +1415,7 @@ COMMIT;
// Check that data were loaded correctly.
qr = queryRequestFromString("SELECT * FROM foo WHERE id=2", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1427,7 +1427,7 @@ COMMIT;
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
}
qr = queryRequestFromString("SELECT count(*) FROM foo", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1441,7 +1441,7 @@ COMMIT;
// Check pre-existing data is gone.
qr = queryRequestFromString("SELECT * FROM bar", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
r, err = s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1503,7 +1503,7 @@ func Test_SingleNodeRecoverNoChange(t *testing.T) {
queryTest := func() {
t.Helper()
qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1571,7 +1571,7 @@ func Test_SingleNodeRecoverNetworkChange(t *testing.T) {
queryTest := func(s *Store) {
qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -1652,7 +1652,7 @@ func Test_SingleNodeRecoverNetworkChangeSnapshot(t *testing.T) {
queryTest := func(s *Store, c int) {
qr := queryRequestFromString("SELECT COUNT(*) FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -2238,7 +2238,7 @@ func Test_MultiNodeExecuteQuery(t *testing.T) {
}
qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s0.Query(qr)
if err != nil {
t.Fatalf("failed to query leader node: %s", err.Error())
@ -2256,17 +2256,17 @@ func Test_MultiNodeExecuteQuery(t *testing.T) {
t.Fatalf("error waiting for follower to apply index: %s:", err.Error())
}
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
_, err = s1.Query(qr)
if err == nil {
t.Fatalf("successfully queried non-leader node")
}
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
_, err = s1.Query(qr)
if err == nil {
t.Fatalf("successfully queried non-leader node")
}
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err = s1.Query(qr)
if err != nil {
t.Fatalf("failed to query follower node: %s", err.Error())
@ -2284,17 +2284,17 @@ func Test_MultiNodeExecuteQuery(t *testing.T) {
t.Fatalf("error waiting for follower to apply index: %s:", err.Error())
}
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
_, err = s1.Query(qr)
if err == nil {
t.Fatalf("successfully queried non-voting node with Weak")
}
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
_, err = s1.Query(qr)
if err == nil {
t.Fatalf("successfully queried non-voting node with Strong")
}
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err = s1.Query(qr)
if err != nil {
t.Fatalf("failed to query non-voting node: %s", err.Error())
@ -2336,7 +2336,7 @@ func Test_SingleNodeExecuteQueryFreshness(t *testing.T) {
t.Fatalf("failed to wait for fsmIndex: %s", err.Error())
}
qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Freshness = mustParseDuration("1ns").Nanoseconds()
r, err := s0.Query(qr)
if err != nil {
@ -2386,7 +2386,7 @@ func Test_MultiNodeExecuteQueryFreshness(t *testing.T) {
}
qr := queryRequestFromString("SELECT * FROM foo", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s0.Query(qr)
if err != nil {
t.Fatalf("failed to query leader node: %s", err.Error())
@ -2406,13 +2406,13 @@ func Test_MultiNodeExecuteQueryFreshness(t *testing.T) {
// "Weak" consistency queries with 1 nanosecond freshness should pass, because freshness
// is ignored in this case.
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK
qr.Freshness = mustParseDuration("1ns").Nanoseconds()
_, err = s0.Query(qr)
if err != nil {
t.Fatalf("Failed to ignore freshness if level is Weak: %s", err.Error())
}
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG
// "Strong" consistency queries with 1 nanosecond freshness should pass, because freshness
// is ignored in this case.
_, err = s0.Query(qr)
@ -2424,7 +2424,7 @@ func Test_MultiNodeExecuteQueryFreshness(t *testing.T) {
s0.Close(true)
// "None" consistency queries should still work.
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Freshness = 0
r, err = s1.Query(qr)
if err != nil {
@ -2442,7 +2442,7 @@ func Test_MultiNodeExecuteQueryFreshness(t *testing.T) {
// "None" consistency queries with 1 nanosecond freshness should fail, because at least
// one nanosecond *should* have passed since leader died (surely!).
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Freshness = mustParseDuration("1ns").Nanoseconds()
_, err = s1.Query(qr)
if err == nil {
@ -2480,7 +2480,7 @@ func Test_MultiNodeExecuteQueryFreshness(t *testing.T) {
}
// Check Stale-read detection works with Requests too.
eqr := executeQueryRequestFromString("SELECT * FROM foo", command.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
eqr := executeQueryRequestFromString("SELECT * FROM foo", proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
false, false)
eqr.Freshness = mustParseDuration("1ns").Nanoseconds()
_, err = s1.Request(eqr)
@ -2570,7 +2570,7 @@ func Test_StoreLogTruncationMultinode(t *testing.T) {
t.Fatalf("error waiting for follower to apply index: %s:", err.Error())
}
qr := queryRequestFromString("SELECT count(*) FROM foo", false, true)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
qr.Level = proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err := s1.Query(qr)
if err != nil {
t.Fatalf("failed to query single node: %s", err.Error())
@ -2767,7 +2767,7 @@ func Test_RequiresLeader(t *testing.T) {
tests := []struct {
name string
stmts []string
lvl command.QueryRequest_Level
lvl proto.QueryRequest_Level
requires bool
}{
{
@ -2808,43 +2808,43 @@ func Test_RequiresLeader(t *testing.T) {
{
name: "Single SELECT with NONE",
stmts: []string{"SELECT * FROM foo"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
requires: false,
},
{
name: "Single SELECT from non-existent table with NONE",
stmts: []string{"SELECT * FROM qux"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
requires: true,
},
{
name: "Double SELECT with NONE",
stmts: []string{"SELECT * FROM foo", "SELECT * FROM foo WHERE id = 1"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
requires: false,
},
{
name: "Single SELECT with STRONG",
stmts: []string{"SELECT * FROM foo"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_STRONG,
lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_STRONG,
requires: true,
},
{
name: "Single SELECT with WEAK",
stmts: []string{"SELECT * FROM foo"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK,
lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK,
requires: true,
},
{
name: "Mix queries and executes with NONE",
stmts: []string{"SELECT * FROM foo", "INSERT INTO foo(id, name) VALUES(1, 'fiona')"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_NONE,
requires: true,
},
{
name: "Mix queries and executes with WEAK",
stmts: []string{"SELECT * FROM foo", "INSERT INTO foo(id, name) VALUES(1, 'fiona')"},
lvl: command.QueryRequest_QUERY_REQUEST_LEVEL_WEAK,
lvl: proto.QueryRequest_QUERY_REQUEST_LEVEL_WEAK,
requires: true,
},
}
@ -3001,20 +3001,20 @@ func mustFileSize(path string) int64 {
return n
}
func executeRequestFromString(s string, timings, tx bool) *command.ExecuteRequest {
func executeRequestFromString(s string, timings, tx bool) *proto.ExecuteRequest {
return executeRequestFromStrings([]string{s}, timings, tx)
}
// executeRequestFromStrings converts a slice of strings into a command.ExecuteRequest
func executeRequestFromStrings(s []string, timings, tx bool) *command.ExecuteRequest {
stmts := make([]*command.Statement, len(s))
// executeRequestFromStrings converts a slice of strings into a proto.ExecuteRequest
func executeRequestFromStrings(s []string, timings, tx bool) *proto.ExecuteRequest {
stmts := make([]*proto.Statement, len(s))
for i := range s {
stmts[i] = &command.Statement{
stmts[i] = &proto.Statement{
Sql: s[i],
}
}
return &command.ExecuteRequest{
Request: &command.Request{
return &proto.ExecuteRequest{
Request: &proto.Request{
Statements: stmts,
Transaction: tx,
},
@ -3022,20 +3022,20 @@ func executeRequestFromStrings(s []string, timings, tx bool) *command.ExecuteReq
}
}
func queryRequestFromString(s string, timings, tx bool) *command.QueryRequest {
func queryRequestFromString(s string, timings, tx bool) *proto.QueryRequest {
return queryRequestFromStrings([]string{s}, timings, tx)
}
// queryRequestFromStrings converts a slice of strings into a command.QueryRequest
func queryRequestFromStrings(s []string, timings, tx bool) *command.QueryRequest {
stmts := make([]*command.Statement, len(s))
// queryRequestFromStrings converts a slice of strings into a proto.QueryRequest
func queryRequestFromStrings(s []string, timings, tx bool) *proto.QueryRequest {
stmts := make([]*proto.Statement, len(s))
for i := range s {
stmts[i] = &command.Statement{
stmts[i] = &proto.Statement{
Sql: s[i],
}
}
return &command.QueryRequest{
Request: &command.Request{
return &proto.QueryRequest{
Request: &proto.Request{
Statements: stmts,
Transaction: tx,
},
@ -3043,19 +3043,19 @@ func queryRequestFromStrings(s []string, timings, tx bool) *command.QueryRequest
}
}
func executeQueryRequestFromString(s string, lvl command.QueryRequest_Level, timings, tx bool) *command.ExecuteQueryRequest {
func executeQueryRequestFromString(s string, lvl proto.QueryRequest_Level, timings, tx bool) *proto.ExecuteQueryRequest {
return executeQueryRequestFromStrings([]string{s}, lvl, timings, tx)
}
func executeQueryRequestFromStrings(s []string, lvl command.QueryRequest_Level, timings, tx bool) *command.ExecuteQueryRequest {
stmts := make([]*command.Statement, len(s))
func executeQueryRequestFromStrings(s []string, lvl proto.QueryRequest_Level, timings, tx bool) *proto.ExecuteQueryRequest {
stmts := make([]*proto.Statement, len(s))
for i := range s {
stmts[i] = &command.Statement{
stmts[i] = &proto.Statement{
Sql: s[i],
}
}
return &command.ExecuteQueryRequest{
Request: &command.Request{
return &proto.ExecuteQueryRequest{
Request: &proto.Request{
Statements: stmts,
Transaction: tx,
},
@ -3064,43 +3064,43 @@ func executeQueryRequestFromStrings(s []string, lvl command.QueryRequest_Level,
}
}
func backupRequestSQL(leader bool) *command.BackupRequest {
return &command.BackupRequest{
Format: command.BackupRequest_BACKUP_REQUEST_FORMAT_SQL,
func backupRequestSQL(leader bool) *proto.BackupRequest {
return &proto.BackupRequest{
Format: proto.BackupRequest_BACKUP_REQUEST_FORMAT_SQL,
Leader: leader,
}
}
func backupRequestBinary(leader bool) *command.BackupRequest {
return &command.BackupRequest{
Format: command.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY,
func backupRequestBinary(leader bool) *proto.BackupRequest {
return &proto.BackupRequest{
Format: proto.BackupRequest_BACKUP_REQUEST_FORMAT_BINARY,
Leader: leader,
}
}
func loadRequestFromFile(path string) *command.LoadRequest {
return &command.LoadRequest{
func loadRequestFromFile(path string) *proto.LoadRequest {
return &proto.LoadRequest{
Data: mustReadFile(path),
}
}
func joinRequest(id, addr string, voter bool) *command.JoinRequest {
return &command.JoinRequest{
func joinRequest(id, addr string, voter bool) *proto.JoinRequest {
return &proto.JoinRequest{
Id: id,
Address: addr,
Voter: voter,
}
}
func notifyRequest(id, addr string) *command.NotifyRequest {
return &command.NotifyRequest{
func notifyRequest(id, addr string) *proto.NotifyRequest {
return &proto.NotifyRequest{
Id: id,
Address: addr,
}
}
func removeNodeRequest(id string) *command.RemoveNodeRequest {
return &command.RemoveNodeRequest{
func removeNodeRequest(id string) *proto.RemoveNodeRequest {
return &proto.RemoveNodeRequest{
Id: id,
}
}

@ -19,8 +19,8 @@ import (
"time"
"github.com/rqlite/rqlite/v8/cluster"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/encoding"
"github.com/rqlite/rqlite/v8/command/proto"
httpd "github.com/rqlite/rqlite/v8/http"
"github.com/rqlite/rqlite/v8/store"
"github.com/rqlite/rqlite/v8/tcp"
@ -235,7 +235,7 @@ func (n *Node) JoinAsNonVoter(leader *Node) error {
// Notify notifies this node of the existence of another node
func (n *Node) Notify(id, raftAddr string) error {
nr := &command.NotifyRequest{
nr := &proto.NotifyRequest{
Id: n.Store.ID(),
Address: n.RaftAddr,
}

@ -7,7 +7,7 @@ import (
"time"
"github.com/rqlite/rqlite/v8/cluster"
"github.com/rqlite/rqlite/v8/command"
"github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/rtls"
"github.com/rqlite/rqlite/v8/tcp"
)
@ -314,20 +314,20 @@ func Test_MultiNodeClusterQueuedRequestForwardOK(t *testing.T) {
}
}
func executeRequestFromString(s string) *command.ExecuteRequest {
func executeRequestFromString(s string) *proto.ExecuteRequest {
return executeRequestFromStrings([]string{s})
}
// queryRequestFromStrings converts a slice of strings into a command.ExecuteRequest
func executeRequestFromStrings(s []string) *command.ExecuteRequest {
stmts := make([]*command.Statement, len(s))
func executeRequestFromStrings(s []string) *proto.ExecuteRequest {
stmts := make([]*proto.Statement, len(s))
for i := range s {
stmts[i] = &command.Statement{
stmts[i] = &proto.Statement{
Sql: s[i],
}
}
return &command.ExecuteRequest{
Request: &command.Request{
return &proto.ExecuteRequest{
Request: &proto.Request{
Statements: stmts,
Transaction: false,
},
@ -335,20 +335,20 @@ func executeRequestFromStrings(s []string) *command.ExecuteRequest {
}
}
func queryRequestFromString(s string) *command.QueryRequest {
func queryRequestFromString(s string) *proto.QueryRequest {
return queryRequestFromStrings([]string{s})
}
// queryRequestFromStrings converts a slice of strings into a command.QueryRequest
func queryRequestFromStrings(s []string) *command.QueryRequest {
stmts := make([]*command.Statement, len(s))
func queryRequestFromStrings(s []string) *proto.QueryRequest {
stmts := make([]*proto.Statement, len(s))
for i := range s {
stmts[i] = &command.Statement{
stmts[i] = &proto.Statement{
Sql: s[i],
}
}
return &command.QueryRequest{
Request: &command.Request{
return &proto.QueryRequest{
Request: &proto.Request{
Statements: stmts,
Transaction: false,
},
@ -356,20 +356,20 @@ func queryRequestFromStrings(s []string) *command.QueryRequest {
}
}
func executeQueryRequestFromString(s string) *command.ExecuteQueryRequest {
func executeQueryRequestFromString(s string) *proto.ExecuteQueryRequest {
return executeQueryRequestFromStrings([]string{s})
}
// executeQueryRequestFromStrings converts a slice of strings into a command.ExecuteQueryRequest
func executeQueryRequestFromStrings(s []string) *command.ExecuteQueryRequest {
stmts := make([]*command.Statement, len(s))
func executeQueryRequestFromStrings(s []string) *proto.ExecuteQueryRequest {
stmts := make([]*proto.Statement, len(s))
for i := range s {
stmts[i] = &command.Statement{
stmts[i] = &proto.Statement{
Sql: s[i],
}
}
return &command.ExecuteQueryRequest{
Request: &command.Request{
return &proto.ExecuteQueryRequest{
Request: &proto.Request{
Statements: stmts,
Transaction: false,
},

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save