Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Data Type] supports array data type for RPC requests #52

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Config struct {
TraceCollectorEndpoint string `mapstructure:"TRACE_COLLECTOR_ENDPOINT"`
Version string `mapstructure:"VERSION"`
MaxServerRequestBodySize int `mapstructure:"MAX_SERVER_REQUEST_BODY_SIZE"`
MaxServerReadBufferSize int `mapstructure:"MAX_SERVER_READ_BUFFER_SIZE"`
}

// The function `LoadConfig` loads a configuration file based on the provided path or uses default
Expand Down Expand Up @@ -98,6 +99,10 @@ func LoadConfig(path *string) (*Config, error) {
config.MaxServerRequestBodySize = 8 * 1024 * 1024 // Default Max: 8 MB
}

if config.MaxServerReadBufferSize == 0 {
config.MaxServerReadBufferSize = 8 * 1024 * 1024 // Default Max: 8 MB
}

return &config, nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/generator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ TRACE_COLLECTOR: {{ .TraceCollector}}
TRACE_COLLECTOR_ENDPOINT: {{ .TraceCollectorEndpoint }}

MAX_SERVER_REQUEST_BODY_SIZE: {{ .MaxServerRequestBodySize }}
MAX_SERVER_READ_BUFFER_SIZE: {{ .MaxServerReadBufferSize }}

CORS_ALLOWED_ORIGINS:
CORS_ALLOWED_METHODS:
Expand Down Expand Up @@ -75,6 +76,10 @@ func GenerateConfig(basePath string, config *raiden.Config, generateFn GenerateF
config.MaxServerRequestBodySize = 8 * 1024 * 1024
}

if config.MaxServerReadBufferSize == 0 {
config.MaxServerReadBufferSize = 8 * 1024 * 1024
}

input := GenerateInput{
BindData: config,
Template: ConfigTemplate,
Expand Down
25 changes: 20 additions & 5 deletions pkg/state/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,28 @@ func BindRpcFunction(rpc raiden.Rpc, fn *objects.Function) (err error) {
fn.CompleteStatement = rpc.GetCompleteStmt()

// validate definition query
matches := regexp.MustCompile(`:\w+`).FindAllString(fn.CompleteStatement, -1)
if len(matches) > 0 {
allMatches := regexp.MustCompile(`:\w+`).FindAllString(fn.CompleteStatement, -1)
allExcludes := regexp.MustCompile(`::\w+`).FindAllString(fn.CompleteStatement, -1)

// Filter out double colon string that work as postgre typecast
validMatches := []string{}
excludeSet := make(map[string]bool)
for _, exclude := range allExcludes {
excludeSet[exclude] = true
}

for _, match := range allMatches {
if !excludeSet[fmt.Sprintf(":%s", match)] {
validMatches = append(validMatches, match)
}
}

if len(validMatches) > 0 {
var errMsg string
if len(matches) > 1 {
errMsg = fmt.Sprintf("rpc %q is invalid, There are %q keys that are not mapped with any parameters or models.", rpc.GetName(), strings.Join(matches, ","))
if len(validMatches) > 1 {
errMsg = fmt.Sprintf("rpc %q is invalid, There are %q keys that are not mapped with any parameters or models.", rpc.GetName(), strings.Join(validMatches, ","))
} else {
errMsg = fmt.Sprintf("rpc %q is invalid, There is %q key that is not mapped with any parameters or models.", rpc.GetName(), matches[0])
errMsg = fmt.Sprintf("rpc %q is invalid, There is %q key that is not mapped with any parameters or models.", rpc.GetName(), validMatches[0])
}
return errors.New(errMsg)
}
Expand Down
21 changes: 13 additions & 8 deletions pkg/supabase/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func getClient() Client {
Concurrency: 4096,
DNSCacheDuration: time.Hour,
}).Dial,
ReadBufferSize: 8192,
}
}

Expand Down Expand Up @@ -113,16 +114,20 @@ func SendRequest(method string, url string, body []byte, timeout time.Duration,
statusCode := resp.StatusCode()

if !strings.HasPrefix(strconv.Itoa(statusCode), "2") {
err = fmt.Errorf("invalid HTTP response code: %d", statusCode)
if resp.Body() != nil && len(resp.Body()) > 0 {
Logger.Error(string(resp.Body()))
sendErr := ReqError{
Message: err.Error(),
Body: resp.Body(),
// Allow redirect for GET Method
if method != fasthttp.MethodGet && !strings.HasPrefix(strconv.Itoa(statusCode), "3") {
err = fmt.Errorf("invalid HTTP response code: %d", statusCode)
if resp.Body() != nil && len(resp.Body()) > 0 {
Logger.Error(string(resp.Body()))
sendErr := ReqError{
Message: err.Error(),
Body: resp.Body(),
}
return nil, sendErr
}
return nil, sendErr
return nil, err
}
return nil, err

}

if resInterceptor != nil {
Expand Down
190 changes: 189 additions & 1 deletion rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ const (
RpcParamDataTypeJSON RpcParamDataType = "JSON"
RpcParamDataTypeJSONB RpcParamDataType = "JSONB"
RpcParamDataTypeUuid RpcParamDataType = "UUID"

// ARRAY TYPES
RpcParamDataTypeArrayInteger RpcParamDataType = "INTEGER[]"
RpcParamDataTypeArrayBigInt RpcParamDataType = "BIGINT[]"
RpcParamDataTypeArrayReal RpcParamDataType = "REAL[]"
RpcParamDataTypeArrayDoublePreci RpcParamDataType = "DOUBLE PRECISION[]"
RpcParamDataTypeArrayNumeric RpcParamDataType = "NUMERIC[]"
RpcParamDataTypeArrayText RpcParamDataType = "TEXT[]"
RpcParamDataTypeArrayVarchar RpcParamDataType = "CHARACTER VARYING[]"
RpcParamDataTypeArrayVarcharAlias RpcParamDataType = "VARCHAR[]"
RpcParamDataTypeArrayBoolean RpcParamDataType = "BOOLEAN[]"
RpcParamDataTypeArrayBytea RpcParamDataType = "BYTEA[]"
RpcParamDataTypeArrayTimestamp RpcParamDataType = "TIMESTAMP WITHOUT TIME ZONE[]"
RpcParamDataTypeArrayTimestampAlias RpcParamDataType = "TIMESTAMP[]"
RpcParamDataTypeArrayTimestampTZ RpcParamDataType = "TIMESTAMP WITH TIME ZONE[]"
RpcParamDataTypeArrayTimestampTZAlias RpcParamDataType = "TIMESTAMPZ[]"
RpcParamDataTypeArrayJSON RpcParamDataType = "JSON[]"
RpcParamDataTypeArrayJSONB RpcParamDataType = "JSONB[]"
RpcParamDataTypeArrayUuid RpcParamDataType = "UUID[]"
)

// Define constants for rpc return data type
Expand All @@ -50,6 +69,7 @@ const (
RpcReturnDataTypeBigInt RpcReturnDataType = "BIGINT"
RpcReturnDataTypeReal RpcReturnDataType = "REAL"
RpcReturnDataTypeDoublePreci RpcReturnDataType = "DOUBLE PRECISION"
RpcReturnDataTypeNumeric RpcReturnDataType = "NUMERIC"
RpcReturnDataTypeText RpcReturnDataType = "TEXT"
RpcReturnDataTypeVarchar RpcReturnDataType = "CHARACTER VARYING"
RpcReturnDataTypeVarcharAlias RpcReturnDataType = "VARCHAR"
Expand All @@ -66,6 +86,24 @@ const (
RpcReturnDataTypeSetOf RpcReturnDataType = "SETOF"
RpcReturnDataTypeVoid RpcReturnDataType = "VOID"
RpcReturnDataTypeTrigger RpcReturnDataType = "TRIGGER"

// ARRAY TYPES
RpcReturnDataTypeArrayInteger RpcReturnDataType = "INTEGER[]"
RpcReturnDataTypeArrayBigInt RpcReturnDataType = "BIGINT[]"
RpcReturnDataTypeArrayReal RpcReturnDataType = "REAL[]"
RpcReturnDataTypeArrayDoublePreci RpcReturnDataType = "DOUBLE PRECISION[]"
RpcReturnDataTypeArrayNumeric RpcReturnDataType = "NUMERIC[]"
RpcReturnDataTypeArrayText RpcReturnDataType = "TEXT[]"
RpcReturnDataTypeArrayVarchar RpcReturnDataType = "CHARACTER VARYING[]"
RpcReturnDataTypeArrayVarcharAlias RpcReturnDataType = "VARCHAR[]"
RpcReturnDataTypeArrayBoolean RpcReturnDataType = "BOOLEAN[]"
RpcReturnDataTypeArrayBytea RpcReturnDataType = "BYTEA[]"
RpcReturnDataTypeArrayTimestamp RpcReturnDataType = "TIMESTAMP WITHOUT TIME ZONE[]"
RpcReturnDataTypeArrayTimestampAlias RpcReturnDataType = "TIMESTAMP[]"
RpcReturnDataTypeArrayTimestampTZ RpcReturnDataType = "TIMESTAMP WITH TIME ZONE[]"
RpcReturnDataTypeArrayTimestampTZAlias RpcReturnDataType = "TIMESTAMPZ[]"
RpcReturnDataTypeArrayJSON RpcReturnDataType = "JSON[]"
RpcReturnDataTypeArrayJSONB RpcReturnDataType = "JSONB[]"
)

func RpcParamToGoType(dataType RpcParamDataType) string {
Expand All @@ -88,6 +126,25 @@ func RpcParamToGoType(dataType RpcParamDataType) string {
return "map[string]interface{}"
case RpcParamDataTypeUuid:
return "uuid.UUID"
// ARRAY TYPES
case RpcParamDataTypeArrayInteger, RpcParamDataTypeArrayBigInt:
return "[]int64"
case RpcParamDataTypeArrayReal:
return "[]float32"
case RpcParamDataTypeArrayDoublePreci, RpcParamDataTypeArrayNumeric:
return "[]float64"
case RpcParamDataTypeArrayText, RpcParamDataTypeArrayVarchar, RpcParamDataTypeArrayVarcharAlias:
return "[]string"
case RpcParamDataTypeArrayBoolean:
return "[]bool"
case RpcParamDataTypeArrayBytea:
return "[][]byte"
case RpcParamDataTypeArrayTimestamp, RpcParamDataTypeArrayTimestampTZ, RpcParamDataTypeArrayTimestampAlias, RpcParamDataTypeArrayTimestampTZAlias:
return "[]time.Time"
case RpcParamDataTypeArrayJSON, RpcParamDataTypeArrayJSONB:
return "[]map[string]interface{}"
case RpcParamDataTypeArrayUuid:
return "[]uuid.UUID"
default:
return "interface{}" // Return interface{} for unknown types
}
Expand Down Expand Up @@ -133,6 +190,44 @@ func GetValidRpcParamType(pType string, returnAlias bool) (RpcParamDataType, err
return RpcParamDataTypeJSONB, nil
case RpcParamDataTypeUuid:
return RpcParamDataTypeUuid, nil
// ARRAY TYPES
case RpcParamDataTypeArrayInteger:
return RpcParamDataTypeArrayInteger, nil
case RpcParamDataTypeArrayBigInt:
return RpcParamDataTypeArrayBigInt, nil
case RpcParamDataTypeArrayReal:
return RpcParamDataTypeArrayReal, nil
case RpcParamDataTypeArrayDoublePreci:
return RpcParamDataTypeArrayDoublePreci, nil
case RpcParamDataTypeArrayNumeric:
return RpcParamDataTypeArrayNumeric, nil
case RpcParamDataTypeArrayText:
return RpcParamDataTypeArrayText, nil
case RpcParamDataTypeArrayVarchar, RpcParamDataTypeArrayVarcharAlias:
if returnAlias {
return RpcParamDataTypeArrayVarcharAlias, nil
}
return RpcParamDataTypeArrayVarchar, nil
case RpcParamDataTypeArrayBoolean:
return RpcParamDataTypeArrayBoolean, nil
case RpcParamDataTypeArrayBytea:
return RpcParamDataTypeArrayBytea, nil
case RpcParamDataTypeArrayTimestamp, RpcParamDataTypeArrayTimestampAlias:
if returnAlias {
return RpcParamDataTypeArrayTimestampAlias, nil
}
return RpcParamDataTypeArrayTimestamp, nil
case RpcParamDataTypeArrayTimestampTZ, RpcParamDataTypeArrayTimestampTZAlias:
if returnAlias {
return RpcParamDataTypeArrayTimestampTZAlias, nil
}
return RpcParamDataTypeArrayTimestampTZ, nil
case RpcParamDataTypeArrayJSON:
return RpcParamDataTypeArrayJSON, nil
case RpcParamDataTypeArrayJSONB:
return RpcParamDataTypeArrayJSONB, nil
case RpcParamDataTypeArrayUuid:
return RpcParamDataTypeArrayUuid, nil
default:
return "", fmt.Errorf("unsupported rpc param type : %s", pCheckType)
}
Expand All @@ -144,7 +239,7 @@ func RpcReturnToGoType(dataType RpcReturnDataType) string {
return "int64"
case RpcReturnDataTypeReal:
return "float32"
case RpcReturnDataTypeDoublePreci:
case RpcReturnDataTypeDoublePreci, RpcReturnDataTypeNumeric:
return "float64"
case RpcReturnDataTypeText, RpcReturnDataTypeVarchar:
return "string"
Expand All @@ -156,6 +251,23 @@ func RpcReturnToGoType(dataType RpcReturnDataType) string {
return "time.Time"
case RpcReturnDataTypeJSON, RpcReturnDataTypeJSONB:
return "map[string]interface{}"
// ARRAY TYPES
case RpcReturnDataTypeArrayInteger, RpcReturnDataTypeArrayBigInt:
return "[]int64"
case RpcReturnDataTypeArrayReal:
return "[]float32"
case RpcReturnDataTypeArrayDoublePreci, RpcReturnDataTypeArrayNumeric:
return "[]float64"
case RpcReturnDataTypeArrayText, RpcReturnDataTypeArrayVarchar:
return "[]string"
case RpcReturnDataTypeArrayBoolean:
return "[]bool"
case RpcReturnDataTypeArrayBytea:
return "[][]byte"
case RpcReturnDataTypeArrayTimestamp, RpcReturnDataTypeArrayTimestampTZ:
return "[]time.Time"
case RpcReturnDataTypeArrayJSON, RpcReturnDataTypeArrayJSONB:
return "[]map[string]interface{}"
default:
return "interface{}" // Return interface{} for unknown types
}
Expand All @@ -172,6 +284,8 @@ func GetValidRpcReturnType(pType string, returnAlias bool) (RpcReturnDataType, e
return RpcReturnDataTypeReal, nil
case RpcReturnDataTypeDoublePreci:
return RpcReturnDataTypeDoublePreci, nil
case RpcReturnDataTypeNumeric:
return RpcReturnDataTypeNumeric, nil
case RpcReturnDataTypeText:
return RpcReturnDataTypeText, nil
case RpcReturnDataTypeVarchar, RpcReturnDataTypeVarcharAlias:
Expand Down Expand Up @@ -205,6 +319,42 @@ func GetValidRpcReturnType(pType string, returnAlias bool) (RpcReturnDataType, e
return RpcReturnDataTypeVoid, nil
case RpcReturnDataTypeTrigger:
return RpcReturnDataTypeTrigger, nil
// ARRAY TYPES
case RpcReturnDataTypeArrayInteger:
return RpcReturnDataTypeArrayInteger, nil
case RpcReturnDataTypeArrayBigInt:
return RpcReturnDataTypeArrayBigInt, nil
case RpcReturnDataTypeArrayReal:
return RpcReturnDataTypeArrayReal, nil
case RpcReturnDataTypeArrayDoublePreci:
return RpcReturnDataTypeArrayDoublePreci, nil
case RpcReturnDataTypeArrayNumeric:
return RpcReturnDataTypeArrayNumeric, nil
case RpcReturnDataTypeArrayText:
return RpcReturnDataTypeArrayText, nil
case RpcReturnDataTypeArrayVarchar, RpcReturnDataTypeArrayVarcharAlias:
if returnAlias {
return RpcReturnDataTypeArrayVarcharAlias, nil
}
return RpcReturnDataTypeArrayVarchar, nil
case RpcReturnDataTypeArrayBoolean:
return RpcReturnDataTypeArrayBoolean, nil
case RpcReturnDataTypeArrayBytea:
return RpcReturnDataTypeArrayBytea, nil
case RpcReturnDataTypeArrayTimestamp, RpcReturnDataTypeArrayTimestampAlias:
if returnAlias {
return RpcReturnDataTypeArrayTimestampAlias, nil
}
return RpcReturnDataTypeArrayTimestamp, nil
case RpcReturnDataTypeArrayTimestampTZ, RpcReturnDataTypeArrayTimestampTZAlias:
if returnAlias {
return RpcReturnDataTypeArrayTimestampTZAlias, nil
}
return RpcReturnDataTypeArrayTimestampTZ, nil
case RpcReturnDataTypeArrayJSON:
return RpcReturnDataTypeArrayJSON, nil
case RpcReturnDataTypeArrayJSONB:
return RpcReturnDataTypeArrayJSONB, nil
default:
return "", fmt.Errorf("unsupported rpc return type : %s", pCheckType)
}
Expand All @@ -220,6 +370,8 @@ func GetValidRpcReturnNameDecl(pType RpcReturnDataType, returnAlias bool) (strin
return "RpcReturnDataTypeReal", nil
case RpcReturnDataTypeDoublePreci:
return "RpcReturnDataTypeDoublePreci", nil
case RpcReturnDataTypeNumeric:
return "RpcReturnDataTypeNumeric", nil
case RpcReturnDataTypeText:
return "RpcReturnDataTypeText", nil
case RpcReturnDataTypeVarchar, RpcReturnDataTypeVarcharAlias:
Expand Down Expand Up @@ -253,6 +405,42 @@ func GetValidRpcReturnNameDecl(pType RpcReturnDataType, returnAlias bool) (strin
return "RpcReturnDataTypeVoid", nil
case RpcReturnDataTypeTrigger:
return "RpcReturnDataTypeTrigger", nil
// ARRAY TYPES
case RpcReturnDataTypeArrayInteger:
return "RpcReturnDataTypeArrayInteger", nil
case RpcReturnDataTypeArrayBigInt:
return "RpcReturnDataTypeArrayBigInt", nil
case RpcReturnDataTypeArrayReal:
return "RpcReturnDataTypeArrayReal", nil
case RpcReturnDataTypeArrayDoublePreci:
return "RpcReturnDataTypeArrayDoublePreci", nil
case RpcReturnDataTypeArrayNumeric:
return "RpcReturnDataTypeArrayNumeric", nil
case RpcReturnDataTypeArrayText:
return "RpcReturnDataTypeArrayText", nil
case RpcReturnDataTypeArrayVarchar, RpcReturnDataTypeArrayVarcharAlias:
if returnAlias {
return "RpcReturnDataTypeArrayVarcharAlias", nil
}
return "RpcReturnDataTypeArrayVarchar", nil
case RpcReturnDataTypeArrayBoolean:
return "RpcReturnDataTypeArrayBoolean", nil
case RpcReturnDataTypeArrayBytea:
return "RpcReturnDataTypeArrayBytea", nil
case RpcReturnDataTypeArrayTimestamp:
if returnAlias {
return "RpcReturnDataTypeArrayTimestampAlias", nil
}
return "RpcReturnDataTypeArrayTimestamp", nil
case RpcReturnDataTypeArrayTimestampTZ:
if returnAlias {
return "RpcReturnDataTypeArrayTimestampTZAlias", nil
}
return "RpcReturnDataTypeArrayTimestampTZ", nil
case RpcReturnDataTypeArrayJSON:
return "RpcReturnDataTypeArrayJSON", nil
case RpcReturnDataTypeArrayJSONB:
return "RpcReturnDataTypeArrayJSONB", nil
default:
return "", fmt.Errorf("unsupported rpc return name declaration : %s", pType)
}
Expand Down
Loading
Loading