8 Commits

Author SHA1 Message Date
Pijus Kamandulis
887d456ad4 Return error code if server fails to start 2025-02-03 22:58:45 +02:00
Pijus Kamandulis
da1566875b Wait for server shutdown when stopping server 2025-02-03 22:21:54 +02:00
Pijus Kamandulis
3fee3bc816 Fix ARRAY_CONTAINS partial matches for nested objects 2025-02-03 19:29:29 +02:00
Pijus Kamandulis
8657c48fc8 Added support for table alias; Make AS keyword optional #9 2025-02-03 19:02:12 +02:00
Pijus Kamandulis
e080888c20 Add shared-libraries to release 2025-01-28 23:28:23 +02:00
Pijus Kamandulis
b8d79fd945 Upgrade upload-artifact pipeline action 2025-01-28 21:31:05 +02:00
Pijus Kamandulis
f25cb7fb03 Stamp binaries with version control information 2025-01-28 21:15:49 +02:00
Pijus Kamandulis
125f10d8a2 Add more error handling and mutex guards 2025-01-27 21:09:37 +02:00
42 changed files with 2215 additions and 1880 deletions

View File

@@ -22,9 +22,10 @@ jobs:
targets: linux/amd64,linux/arm64,windows/amd64,windows/arm64,darwin/amd64,darwin/arm64
v: true
buildmode: c-shared
buildvcs: true
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: shared-libraries
path: dist/*

View File

@@ -17,16 +17,32 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.0
- name: Cross-Compile with xgo
uses: crazy-max/ghaction-xgo@v3.1.0
with:
xgo_version: latest
go_version: 1.22.0
dest: sharedlibrary_dist
pkg: sharedlibrary
prefix: cosmium
targets: linux/amd64,linux/arm64,windows/amd64,windows/arm64,darwin/amd64,darwin/arm64
v: true
buildmode: c-shared
buildvcs: true
- name: Docker Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
dist/
sharedlibrary_dist/
ignored/
explorer_www/
main

View File

@@ -26,6 +26,23 @@ brews:
commit_author:
name: pikami
email: git@pikami.org
skip_upload: auto
archives:
- id: bundle
format: tar.gz
format_overrides:
- goos: windows
format: zip
- id: shared-libraries
meta: true
format: "tar.gz"
wrap_in_directory: true
name_template: "{{ .ProjectName }}_{{ .Version }}_shared-libraries"
files:
- LICENSE
- README.md
- sharedlibrary_dist/**
dockers:
- id: docker-linux-amd64
@@ -33,7 +50,6 @@ dockers:
goarch: amd64
image_templates:
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-amd64"
- "ghcr.io/pikami/{{ .ProjectName }}:latest-amd64"
dockerfile: Dockerfile
use: buildx
build_flag_templates:
@@ -51,9 +67,7 @@ dockers:
goarch: arm64
image_templates:
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-arm64"
- "ghcr.io/pikami/{{ .ProjectName }}:latest-arm64"
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-arm64v8"
- "ghcr.io/pikami/{{ .ProjectName }}:latest-arm64v8"
dockerfile: Dockerfile
use: buildx
build_flag_templates:
@@ -104,16 +118,19 @@ dockers:
docker_manifests:
- name_template: 'ghcr.io/pikami/{{ .ProjectName }}:latest'
skip_push: auto
image_templates:
- "ghcr.io/pikami/{{ .ProjectName }}:latest-amd64"
- "ghcr.io/pikami/{{ .ProjectName }}:latest-arm64"
- "ghcr.io/pikami/{{ .ProjectName }}:latest-arm64v8"
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-amd64"
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-arm64"
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-arm64v8"
- name_template: 'ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}'
skip_push: auto
image_templates:
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-amd64"
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-arm64"
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-arm64v8"
- name_template: 'ghcr.io/pikami/{{ .ProjectName }}:explorer'
skip_push: auto
image_templates:
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-explorer-amd64"
- "ghcr.io/pikami/{{ .ProjectName }}:{{ .Version }}-explorer-arm64"

View File

@@ -7,18 +7,21 @@ import (
)
type ApiServer struct {
stopServer chan interface{}
isActive bool
router *gin.Engine
config config.ServerConfig
stopServer chan interface{}
onServerShutdown chan interface{}
isActive bool
router *gin.Engine
config config.ServerConfig
}
func NewApiServer(dataRepository *repositories.DataRepository, config config.ServerConfig) *ApiServer {
stopChan := make(chan interface{})
onServerShutdownChan := make(chan interface{})
apiServer := &ApiServer{
stopServer: stopChan,
config: config,
stopServer: stopChan,
onServerShutdown: onServerShutdownChan,
config: config,
}
apiServer.CreateRouter(dataRepository)
@@ -32,4 +35,5 @@ func (s *ApiServer) GetRouter() *gin.Engine {
func (s *ApiServer) Stop() {
s.stopServer <- true
<-s.onServerShutdown
}

View File

@@ -58,15 +58,15 @@ func (c *ServerConfig) PopulateCalculatedFields() {
switch c.LogLevel {
case "debug":
logger.LogLevel = logger.LogLevelDebug
logger.SetLogLevel(logger.LogLevelDebug)
case "info":
logger.LogLevel = logger.LogLevelInfo
logger.SetLogLevel(logger.LogLevelInfo)
case "error":
logger.LogLevel = logger.LogLevelError
logger.SetLogLevel(logger.LogLevelError)
case "silent":
logger.LogLevel = logger.LogLevelSilent
logger.SetLogLevel(logger.LogLevelSilent)
default:
logger.LogLevel = logger.LogLevelInfo
logger.SetLogLevel(logger.LogLevelInfo)
}
}

View File

@@ -4,6 +4,8 @@ import (
"context"
"fmt"
"net/http"
"sync"
"time"
"github.com/gin-gonic/gin"
"github.com/pikami/cosmium/api/handlers"
@@ -13,15 +15,19 @@ import (
tlsprovider "github.com/pikami/cosmium/internal/tls_provider"
)
var ginMux sync.Mutex
func (s *ApiServer) CreateRouter(repository *repositories.DataRepository) {
routeHandlers := handlers.NewHandlers(repository, s.config)
ginMux.Lock()
gin.DefaultWriter = logger.InfoWriter()
gin.DefaultErrorWriter = logger.ErrorWriter()
if s.config.LogLevel != "debug" {
gin.SetMode(gin.ReleaseMode)
}
ginMux.Unlock()
router := gin.Default(func(e *gin.Engine) {
e.RedirectTrailingSlash = false
@@ -81,7 +87,7 @@ func (s *ApiServer) CreateRouter(repository *repositories.DataRepository) {
s.router = router
}
func (s *ApiServer) Start() {
func (s *ApiServer) Start() error {
listenAddress := fmt.Sprintf(":%d", s.config.Port)
s.isActive = true
@@ -90,6 +96,8 @@ func (s *ApiServer) Start() {
Handler: s.router.Handler(),
}
errChan := make(chan error, 1)
go func() {
<-s.stopServer
logger.InfoLn("Shutting down server...")
@@ -97,35 +105,40 @@ func (s *ApiServer) Start() {
if err != nil {
logger.ErrorLn("Failed to shutdown server:", err)
}
s.onServerShutdown <- true
}()
go func() {
var err error
if s.config.DisableTls {
logger.Infof("Listening and serving HTTP on %s\n", server.Addr)
err := server.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
logger.ErrorLn("Failed to start HTTP server:", err)
}
s.isActive = false
err = server.ListenAndServe()
} else if s.config.TLS_CertificatePath != "" && s.config.TLS_CertificateKey != "" {
logger.Infof("Listening and serving HTTPS on %s\n", server.Addr)
err := server.ListenAndServeTLS(
err = server.ListenAndServeTLS(
s.config.TLS_CertificatePath,
s.config.TLS_CertificateKey)
if err != nil && err != http.ErrServerClosed {
logger.ErrorLn("Failed to start HTTPS server:", err)
}
s.isActive = false
} else {
tlsConfig := tlsprovider.GetDefaultTlsConfig()
server.TLSConfig = tlsConfig
logger.Infof("Listening and serving HTTPS on %s\n", server.Addr)
err := server.ListenAndServeTLS("", "")
if err != nil && err != http.ErrServerClosed {
logger.ErrorLn("Failed to start HTTPS server:", err)
}
s.isActive = false
err = server.ListenAndServeTLS("", "")
}
if err != nil && err != http.ErrServerClosed {
logger.ErrorLn("Failed to start server:", err)
errChan <- err
} else {
errChan <- nil
}
s.isActive = false
}()
select {
case err := <-errChan:
return err
case <-time.After(50 * time.Millisecond):
return nil
}
}

View File

@@ -19,7 +19,10 @@ func main() {
})
server := api.NewApiServer(repository, configuration)
server.Start()
err := server.Start()
if err != nil {
panic(err)
}
waitForExit(server, repository, configuration)
}

View File

@@ -204,6 +204,15 @@ Cosmium strives to support the core features of Cosmos DB, including:
| IS_PRIMITIVE | Yes |
| IS_STRING | Yes |
### Document Batch Requests
| Operation | Implemented |
| --------- | ----------- |
| Create | No |
| Update | No |
| Delete | No |
| Read | No |
## Known Differences
While Cosmium aims to replicate the behavior of Cosmos DB as closely as possible, there are certain differences and limitations to be aware of:

View File

@@ -6,6 +6,7 @@ import (
"os"
"runtime"
"strings"
"sync"
)
type LogLevelType int
@@ -21,67 +22,68 @@ type LogWriter struct {
WriterLevel LogLevelType
}
var LogLevel = LogLevelInfo
var logLevelMutex sync.RWMutex
var logLevel = LogLevelInfo
var DebugLogger = log.New(os.Stdout, "", log.Ldate|log.Ltime)
var InfoLogger = log.New(os.Stdout, "", log.Ldate|log.Ltime)
var ErrorLogger = log.New(os.Stderr, "", log.Ldate|log.Ltime)
func DebugLn(v ...any) {
if LogLevel <= LogLevelDebug {
if GetLogLevel() <= LogLevelDebug {
prefix := getCallerPrefix()
DebugLogger.Println(append([]interface{}{prefix}, v...)...)
}
}
func Debug(v ...any) {
if LogLevel <= LogLevelDebug {
if GetLogLevel() <= LogLevelDebug {
prefix := getCallerPrefix()
DebugLogger.Println(append([]interface{}{prefix}, v...)...)
}
}
func Debugf(format string, v ...any) {
if LogLevel <= LogLevelDebug {
if GetLogLevel() <= LogLevelDebug {
prefix := getCallerPrefix()
DebugLogger.Printf(prefix+format, v...)
}
}
func InfoLn(v ...any) {
if LogLevel <= LogLevelInfo {
if GetLogLevel() <= LogLevelInfo {
InfoLogger.Println(v...)
}
}
func Info(v ...any) {
if LogLevel <= LogLevelInfo {
if GetLogLevel() <= LogLevelInfo {
InfoLogger.Print(v...)
}
}
func Infof(format string, v ...any) {
if LogLevel <= LogLevelInfo {
if GetLogLevel() <= LogLevelInfo {
InfoLogger.Printf(format, v...)
}
}
func ErrorLn(v ...any) {
if LogLevel <= LogLevelError {
if GetLogLevel() <= LogLevelError {
prefix := getCallerPrefix()
ErrorLogger.Println(append([]interface{}{prefix}, v...)...)
}
}
func Error(v ...any) {
if LogLevel <= LogLevelError {
if GetLogLevel() <= LogLevelError {
prefix := getCallerPrefix()
ErrorLogger.Print(append([]interface{}{prefix}, v...)...)
}
}
func Errorf(format string, v ...any) {
if LogLevel <= LogLevelError {
if GetLogLevel() <= LogLevelError {
prefix := getCallerPrefix()
ErrorLogger.Printf(prefix+format, v...)
}
@@ -112,11 +114,25 @@ func DebugWriter() *LogWriter {
return &LogWriter{WriterLevel: LogLevelDebug}
}
func SetLogLevel(level LogLevelType) {
logLevelMutex.Lock()
defer logLevelMutex.Unlock()
logLevel = level
}
func GetLogLevel() LogLevelType {
logLevelMutex.RLock()
defer logLevelMutex.RUnlock()
return logLevel
}
func getCallerPrefix() string {
_, file, line, ok := runtime.Caller(2)
if ok {
parts := strings.Split(file, "/")
file = parts[len(parts)-1]
if len(parts) > 0 {
file = parts[len(parts)-1]
}
return fmt.Sprintf("%s:%d - ", file, line)
}

View File

@@ -46,8 +46,8 @@ func (r *DataRepository) LoadStateFS(filePath string) {
}
func (r *DataRepository) LoadStateJSON(jsonData string) error {
r.storeState.RLock()
defer r.storeState.RUnlock()
r.storeState.Lock()
defer r.storeState.Unlock()
var state repositorymodels.State
if err := json.Unmarshal([]byte(jsonData), &state); err != nil {

View File

@@ -17,6 +17,7 @@ type SelectStmt struct {
type Table struct {
Value string
SelectItem SelectItem
IsInSelect bool
}
type JoinItem struct {

View File

@@ -4,6 +4,7 @@ import (
"testing"
"github.com/pikami/cosmium/parsers"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Parse_AggregateFunctions(t *testing.T) {
@@ -27,7 +28,7 @@ func Test_Parse_AggregateFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -51,7 +52,7 @@ func Test_Parse_AggregateFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -75,7 +76,7 @@ func Test_Parse_AggregateFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -99,7 +100,7 @@ func Test_Parse_AggregateFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -123,7 +124,7 @@ func Test_Parse_AggregateFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})

View File

@@ -32,7 +32,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -58,7 +58,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -87,7 +87,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -116,7 +116,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -145,7 +145,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -169,7 +169,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -195,7 +195,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -223,7 +223,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -251,7 +251,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})

View File

@@ -4,6 +4,7 @@ import (
"testing"
"github.com/pikami/cosmium/parsers"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Parse_Join(t *testing.T) {
@@ -17,7 +18,7 @@ func Test_Parse_Join(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "pk"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
JoinItems: []parsers.JoinItem{
{
Table: parsers.Table{
@@ -40,7 +41,7 @@ func Test_Parse_Join(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"cc"}, IsTopLevel: true},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
JoinItems: []parsers.JoinItem{
{
Table: parsers.Table{

View File

@@ -4,6 +4,7 @@ import (
"testing"
"github.com/pikami/cosmium/parsers"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Execute_MathFunctions(t *testing.T) {
@@ -644,7 +645,7 @@ func testMathFunctionParse(
},
},
},
Table: parsers.Table{Value: expectedTable},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path(expectedTable)},
},
)
}

View File

@@ -49,7 +49,7 @@ func Test_Parse(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "pk"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
OrderExpressions: []parsers.OrderExpression{
{
SelectItem: parsers.SelectItem{Path: []string{"c", "id"}},
@@ -73,7 +73,7 @@ func Test_Parse(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "pk"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
GroupBy: []parsers.SelectItem{
{Path: []string{"c", "id"}},
{Path: []string{"c", "pk"}},
@@ -93,7 +93,7 @@ func Test_Parse(t *testing.T) {
Type: parsers.SelectItemTypeField,
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -124,10 +124,9 @@ func Test_Parse(t *testing.T) {
},
},
Table: parsers.Table{
Value: "c",
SelectItem: parsers.SelectItem{
Path: []string{"c", "tags"},
},
Value: "c",
SelectItem: testutils.SelectItem_Path("c", "tags"),
IsInSelect: true,
},
},
)

File diff suppressed because it is too large Load Diff

View File

@@ -204,14 +204,22 @@ TopClause <- Top ws count:Integer {
return count, nil
}
FromClause <- From ws table:TableName selectItem:(ws "IN"i ws column:SelectItem { return column, nil })? {
FromClause <- From ws table:TableName selectItem:(ws In ws column:SelectItem { return column, nil }) {
tableTyped := table.(parsers.Table)
if selectItem != nil {
tableTyped.SelectItem = selectItem.(parsers.SelectItem)
tableTyped.IsInSelect = true
}
return tableTyped, nil
} / From ws column:SelectItem {
tableSelectItem := column.(parsers.SelectItem)
table := parsers.Table{
Value: tableSelectItem.Alias,
SelectItem: tableSelectItem,
}
return table, nil
} / From ws subQuery:SubQuerySelectItem {
subQueryTyped := subQuery.(parsers.SelectItem)
table := parsers.Table{
@@ -243,13 +251,13 @@ SubQuerySelectItem <- subQuery:SubQuery asClause:(ws alias:AsClause { return ali
return selectItem, nil
}
JoinClause <- Join ws table:TableName ws "IN"i ws column:SelectItem {
JoinClause <- Join ws table:TableName ws In ws column:SelectItem {
return makeJoin(table, column)
} / Join ws subQuery:SubQuerySelectItem {
return makeJoin(nil, subQuery)
}
OffsetClause <- "OFFSET"i ws offset:IntegerLiteral ws "LIMIT"i ws limit:IntegerLiteral {
OffsetClause <- Offset ws offset:IntegerLiteral ws "LIMIT"i ws limit:IntegerLiteral {
return []interface{}{offset.(parsers.Constant).Value, limit.(parsers.Constant).Value}, nil
}
@@ -317,7 +325,11 @@ SelectItem <- selectItem:(SubQuerySelectItem / Literal / FunctionCall / SelectAr
return itemResult, nil
}
AsClause <- ws As ws alias:Identifier { return alias, nil }
AsClause <- (ws As)? ws !ExcludedKeywords alias:Identifier {
return alias, nil
}
ExcludedKeywords <- Select / Top / As / From / In / Join / Exists / Where / And / Or / GroupBy / OrderBy / Offset
DotFieldAccess <- "." id:Identifier {
return id, nil
@@ -373,6 +385,8 @@ As <- "AS"i
From <- "FROM"i
In <- "IN"i
Join <- "JOIN"i
Exists <- "EXISTS"i
@@ -387,6 +401,8 @@ GroupBy <- "GROUP"i ws "BY"i
OrderBy <- "ORDER"i ws "BY"i
Offset <- "OFFSET"i
ComparisonOperator <- ("=" / "!=" / "<" / "<=" / ">" / ">=") {
return string(c.text), nil
}
@@ -700,7 +716,7 @@ MathNumberBinExpression <- "NumberBin"i ws "(" ws ex1:SelectItem others:(ws ","
MathPiExpression <- "PI"i ws "(" ws ")" { return createFunctionCall(parsers.FunctionCallMathPi, []interface{}{}) }
MathRandExpression <- "RAND"i ws "(" ws ")" { return createFunctionCall(parsers.FunctionCallMathRand, []interface{}{}) }
InFunction <- ex1:SelectProperty ws "IN"i ws "(" ws ex2:SelectItem others:(ws "," ws ex:SelectItem { return ex, nil })* ws ")" {
InFunction <- ex1:SelectProperty ws In ws "(" ws ex2:SelectItem others:(ws "," ws ex:SelectItem { return ex, nil })* ws ")" {
return createFunctionCall(parsers.FunctionCallIn, append([]interface{}{ex1, ex2}, others.([]interface{})...))
}

View File

@@ -4,6 +4,7 @@ import (
"testing"
"github.com/pikami/cosmium/parsers"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Parse_Select(t *testing.T) {
@@ -17,7 +18,7 @@ func Test_Parse_Select(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "pk"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -31,7 +32,7 @@ func Test_Parse_Select(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "@param"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -44,7 +45,7 @@ func Test_Parse_Select(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Distinct: true,
},
)
@@ -58,7 +59,7 @@ func Test_Parse_Select(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Count: 1,
},
)
@@ -72,7 +73,7 @@ func Test_Parse_Select(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Count: 5,
Offset: 3,
},
@@ -87,7 +88,7 @@ func Test_Parse_Select(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}, IsTopLevel: true},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -100,7 +101,20 @@ func Test_Parse_Select(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c"}, IsTopLevel: true},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
t.Run("Should parse SELECT c", func(t *testing.T) {
testQueryParse(
t,
`SELECT c FROM c`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{Path: []string{"c"}, IsTopLevel: false},
},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -120,7 +134,27 @@ func Test_Parse_Select(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
t.Run("Should parse SELECT with alias", func(t *testing.T) {
testQueryParse(
t,
`SELECT
c.id AS aliasWithAs,
c.pk aliasWithoutAs
FROM root c`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{Alias: "aliasWithAs", Path: []string{"c", "id"}},
{Alias: "aliasWithoutAs", Path: []string{"c", "pk"}},
},
Table: parsers.Table{
Value: "c",
SelectItem: parsers.SelectItem{Alias: "c", Path: []string{"root"}},
},
},
)
})
@@ -140,7 +174,7 @@ func Test_Parse_Select(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})

View File

@@ -30,7 +30,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -56,7 +56,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -85,7 +85,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -111,7 +111,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -137,7 +137,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -163,7 +163,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -189,7 +189,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -213,7 +213,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -237,7 +237,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -261,7 +261,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -286,7 +286,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -310,7 +310,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -334,7 +334,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -360,7 +360,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -385,7 +385,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -409,7 +409,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -434,7 +434,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -458,7 +458,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -484,7 +484,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})
@@ -508,7 +508,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
)
})

View File

@@ -4,6 +4,7 @@ import (
"testing"
"github.com/pikami/cosmium/parsers"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Parse_SubQuery(t *testing.T) {
@@ -22,7 +23,7 @@ func Test_Parse_SubQuery(t *testing.T) {
Alias: "c",
Type: parsers.SelectItemTypeSubQuery,
Value: parsers.SelectStmt{
Table: parsers.Table{Value: "cc"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("cc")},
SelectItems: []parsers.SelectItem{
{Path: []string{"cc", "info"}, IsTopLevel: true},
},
@@ -42,9 +43,7 @@ func Test_Parse_SubQuery(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"cc", "name"}},
},
Table: parsers.Table{
Value: "c",
},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
JoinItems: []parsers.JoinItem{
{
Table: parsers.Table{
@@ -55,13 +54,12 @@ func Test_Parse_SubQuery(t *testing.T) {
Type: parsers.SelectItemTypeSubQuery,
Value: parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{Path: []string{"tag", "name"}},
testutils.SelectItem_Path("tag", "name"),
},
Table: parsers.Table{
Value: "tag",
SelectItem: parsers.SelectItem{
Path: []string{"c", "tags"},
},
Value: "tag",
SelectItem: testutils.SelectItem_Path("c", "tags"),
IsInSelect: true,
},
},
},
@@ -82,10 +80,10 @@ func Test_Parse_SubQuery(t *testing.T) {
WHERE hasTags`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
testutils.SelectItem_Path("c", "id"),
},
Table: parsers.Table{
Value: "c",
SelectItem: testutils.SelectItem_Path("c"),
},
JoinItems: []parsers.JoinItem{
{
@@ -100,13 +98,12 @@ func Test_Parse_SubQuery(t *testing.T) {
Type: parsers.SelectItemTypeSubQuery,
Value: parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{Path: []string{"tag", "name"}},
testutils.SelectItem_Path("tag", "name"),
},
Table: parsers.Table{
Value: "tag",
SelectItem: parsers.SelectItem{
Path: []string{"c", "tags"},
},
Value: "tag",
SelectItem: testutils.SelectItem_Path("c", "tags"),
IsInSelect: true,
},
Exists: true,
},

View File

@@ -4,6 +4,7 @@ import (
"testing"
"github.com/pikami/cosmium/parsers"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Execute_TypeCheckingFunctions(t *testing.T) {
@@ -27,7 +28,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -63,7 +64,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -99,7 +100,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -135,7 +136,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -171,7 +172,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -207,7 +208,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -243,7 +244,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -279,7 +280,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -315,7 +316,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -351,7 +352,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{

View File

@@ -19,7 +19,7 @@ func Test_Parse_Were(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.ComparisonExpression{
Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "isCool"}},
@@ -42,7 +42,7 @@ func Test_Parse_Were(t *testing.T) {
{Path: []string{"c", "_rid"}},
{Path: []string{"c", "_ts"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.LogicalExpression{
Operation: parsers.LogicalExpressionTypeOr,
Expressions: []interface{}{
@@ -72,7 +72,7 @@ func Test_Parse_Were(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.LogicalExpression{
Operation: parsers.LogicalExpressionTypeAnd,
Expressions: []interface{}{
@@ -114,7 +114,7 @@ func Test_Parse_Were(t *testing.T) {
AND c.param=@param_id1`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{{Path: []string{"c", "id"}, Alias: ""}},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.LogicalExpression{
Expressions: []interface{}{
parsers.ComparisonExpression{

View File

@@ -5,6 +5,7 @@ import (
"github.com/pikami/cosmium/parsers"
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Execute_AggregateFunctions(t *testing.T) {
@@ -38,7 +39,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
GroupBy: []parsers.SelectItem{
{Path: []string{"c", "key"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -67,7 +68,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -99,7 +100,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
GroupBy: []parsers.SelectItem{
{Path: []string{"c", "key"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -132,7 +133,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
GroupBy: []parsers.SelectItem{
{Path: []string{"c", "key"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -165,7 +166,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
GroupBy: []parsers.SelectItem{
{Path: []string{"c", "key"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -198,7 +199,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
GroupBy: []parsers.SelectItem{
{Path: []string{"c", "key"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{

View File

@@ -220,7 +220,7 @@ func (r rowContext) partialMatch(item interface{}, exprToSearch interface{}) boo
}
for _, key := range exprValue.MapKeys() {
if itemValue.MapIndex(key).Interface() != exprValue.MapIndex(key).Interface() {
if !reflect.DeepEqual(itemValue.MapIndex(key).Interface(), exprValue.MapIndex(key).Interface()) {
return false
}
}

View File

@@ -42,7 +42,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -59,10 +59,11 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
parsers.SelectStmt{
Parameters: map[string]interface{}{
"@categories": []interface{}{"coats", "jackets", "sweatshirts"},
"@objectArray": []interface{}{map[string]interface{}{"category": "shirts", "color": "blue"}},
"@fullMatchObject": map[string]interface{}{"category": "shirts", "color": "blue"},
"@objectArray": []interface{}{map[string]interface{}{"category": "shirts", "color": "blue", "nestedObject": map[string]interface{}{"size": "M"}}},
"@fullMatchObject": map[string]interface{}{"category": "shirts", "color": "blue", "nestedObject": map[string]interface{}{"size": "M"}},
"@partialMatchObject": map[string]interface{}{"category": "shirts"},
"@missingPartialMatchObject": map[string]interface{}{"category": "shorts", "color": "blue"},
"@nestedPartialMatchObject": map[string]interface{}{"nestedObject": map[string]interface{}{"size": "M"}},
},
SelectItems: []parsers.SelectItem{
{
@@ -133,17 +134,30 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
},
},
},
{
Alias: "ContainsNestedPartialMatchObject",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContains,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@objectArray"),
testutils.SelectItem_Constant_Parameter("@nestedPartialMatchObject"),
testutils.SelectItem_Constant_Bool(true),
},
},
},
},
},
[]memoryexecutor.RowType{map[string]interface{}{"id": "123"}},
[]memoryexecutor.RowType{
map[string]interface{}{
"ContainsItem": true,
"MissingItem": false,
"ContainsFullMatchObject": true,
"MissingFullMatchObject": false,
"ContainsPartialMatchObject": true,
"MissingPartialMatchObject": false,
"ContainsItem": true,
"MissingItem": false,
"ContainsFullMatchObject": true,
"MissingFullMatchObject": false,
"ContainsPartialMatchObject": true,
"MissingPartialMatchObject": false,
"ContainsNestedPartialMatchObject": true,
},
},
)
@@ -356,7 +370,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -392,7 +406,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -430,7 +444,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -468,7 +482,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{

View File

@@ -5,6 +5,7 @@ import (
"github.com/pikami/cosmium/parsers"
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Execute_Joins(t *testing.T) {
@@ -33,7 +34,7 @@ func Test_Execute_Joins(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"cc", "name"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
JoinItems: []parsers.JoinItem{
{
Table: parsers.Table{
@@ -62,7 +63,7 @@ func Test_Execute_Joins(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"cc"}, IsTopLevel: true},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
JoinItems: []parsers.JoinItem{
{
Table: parsers.Table{

View File

@@ -6,6 +6,7 @@ import (
"github.com/pikami/cosmium/parsers"
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Execute_MathFunctions(t *testing.T) {
@@ -261,7 +262,7 @@ func testMathFunctionExecute(
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
data,
expectedData,

View File

@@ -80,10 +80,15 @@ func resolveFrom(query parsers.SelectStmt, doc RowType) []rowContext {
initialTableName = query.Table.Value
}
if initialTableName == "" {
initialTableName = resolveDestinationColumnName(query.Table.SelectItem, 0, query.Parameters)
}
initialRow = rowContext{
parameters: query.Parameters,
tables: map[string]RowType{
initialTableName: doc,
"$root": doc,
},
}
}
@@ -93,15 +98,33 @@ func resolveFrom(query parsers.SelectStmt, doc RowType) []rowContext {
if destinationTableName == "" {
destinationTableName = query.Table.Value
}
selectValue := initialRow.parseArray(query.Table.SelectItem)
rowContexts := make([]rowContext, len(selectValue))
for i, newRowData := range selectValue {
rowContexts[i].parameters = initialRow.parameters
rowContexts[i].tables = copyMap(initialRow.tables)
rowContexts[i].tables[destinationTableName] = newRowData
if destinationTableName == "" {
destinationTableName = resolveDestinationColumnName(query.Table.SelectItem, 0, initialRow.parameters)
}
return rowContexts
if query.Table.IsInSelect || query.Table.SelectItem.Type == parsers.SelectItemTypeSubQuery {
selectValue := initialRow.parseArray(query.Table.SelectItem)
rowContexts := make([]rowContext, len(selectValue))
for i, newRowData := range selectValue {
rowContexts[i].parameters = initialRow.parameters
rowContexts[i].tables = copyMap(initialRow.tables)
rowContexts[i].tables[destinationTableName] = newRowData
}
return rowContexts
}
if len(query.Table.SelectItem.Path) > 0 {
sourceTableName := query.Table.SelectItem.Path[0]
sourceTableData := initialRow.tables[sourceTableName]
if sourceTableData == nil {
// When source table is not found, assume it's root document
initialRow.tables[sourceTableName] = initialRow.tables["$root"]
}
}
newRowData := initialRow.resolveSelectItem(query.Table.SelectItem)
initialRow.tables[destinationTableName] = newRowData
return []rowContext{initialRow}
}
return []rowContext{initialRow}
@@ -310,18 +333,7 @@ func (r rowContext) applyProjection(selectItems []parsers.SelectItem) RowType {
// Construct a new row based on the selected columns
row := make(map[string]interface{})
for index, selectItem := range selectItems {
destinationName := selectItem.Alias
if destinationName == "" {
if len(selectItem.Path) > 0 {
destinationName = selectItem.Path[len(selectItem.Path)-1]
} else {
destinationName = fmt.Sprintf("$%d", index+1)
}
if destinationName[0] == '@' {
destinationName = r.parameters[destinationName].(string)
}
}
destinationName := resolveDestinationColumnName(selectItem, index, r.parameters)
row[destinationName] = r.resolveSelectItem(selectItem)
}
@@ -329,6 +341,23 @@ func (r rowContext) applyProjection(selectItems []parsers.SelectItem) RowType {
return row
}
func resolveDestinationColumnName(selectItem parsers.SelectItem, itemIndex int, queryParameters map[string]interface{}) string {
if selectItem.Alias != "" {
return selectItem.Alias
}
destinationName := fmt.Sprintf("$%d", itemIndex+1)
if len(selectItem.Path) > 0 {
destinationName = selectItem.Path[len(selectItem.Path)-1]
}
if destinationName[0] == '@' {
destinationName = queryParameters[destinationName].(string)
}
return destinationName
}
func (r rowContext) resolveSelectItem(selectItem parsers.SelectItem) interface{} {
if selectItem.Type == parsers.SelectItemTypeArray {
return r.selectItem_SelectItemTypeArray(selectItem)

View File

@@ -50,7 +50,7 @@ func Test_Execute(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "pk"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
OrderExpressions: []parsers.OrderExpression{
{
SelectItem: parsers.SelectItem{Path: []string{"c", "pk"}},
@@ -79,7 +79,7 @@ func Test_Execute(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "pk"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
GroupBy: []parsers.SelectItem{
{Path: []string{"c", "pk"}},
},
@@ -102,7 +102,7 @@ func Test_Execute(t *testing.T) {
Type: parsers.SelectItemTypeField,
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
@@ -137,10 +137,9 @@ func Test_Execute(t *testing.T) {
},
},
Table: parsers.Table{
Value: "c",
SelectItem: parsers.SelectItem{
Path: []string{"c", "tags"},
},
Value: "c",
SelectItem: testutils.SelectItem_Path("c", "tags"),
IsInSelect: true,
},
},
mockData,

View File

@@ -5,6 +5,7 @@ import (
"github.com/pikami/cosmium/parsers"
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Execute_Select(t *testing.T) {
@@ -23,7 +24,7 @@ func Test_Execute_Select(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "pk"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -43,7 +44,7 @@ func Test_Execute_Select(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "@param"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Parameters: map[string]interface{}{
"@param": "pk",
},
@@ -65,7 +66,7 @@ func Test_Execute_Select(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "pk"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Distinct: true,
},
mockData,
@@ -84,7 +85,7 @@ func Test_Execute_Select(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "pk"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Count: 1,
},
mockData,
@@ -102,7 +103,7 @@ func Test_Execute_Select(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "pk"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Count: 2,
Offset: 1,
OrderExpressions: []parsers.OrderExpression{
@@ -127,7 +128,7 @@ func Test_Execute_Select(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}, IsTopLevel: true},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -146,7 +147,7 @@ func Test_Execute_Select(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c"}, IsTopLevel: true},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
mockData,
@@ -167,7 +168,7 @@ func Test_Execute_Select(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -193,7 +194,7 @@ func Test_Execute_Select(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{

View File

@@ -40,7 +40,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -76,7 +76,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -112,7 +112,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -148,7 +148,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -184,7 +184,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -220,7 +220,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -256,7 +256,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -290,7 +290,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -325,7 +325,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -359,7 +359,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -393,7 +393,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -429,7 +429,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -464,7 +464,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -498,7 +498,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -533,7 +533,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -567,7 +567,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -603,7 +603,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -637,7 +637,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{

View File

@@ -5,6 +5,7 @@ import (
"github.com/pikami/cosmium/parsers"
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Execute_SubQuery(t *testing.T) {
@@ -41,7 +42,7 @@ func Test_Execute_SubQuery(t *testing.T) {
Alias: "c",
Type: parsers.SelectItemTypeSubQuery,
Value: parsers.SelectStmt{
Table: parsers.Table{Value: "cc"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("cc")},
SelectItems: []parsers.SelectItem{
{Path: []string{"cc", "info"}, IsTopLevel: true},
},
@@ -66,9 +67,7 @@ func Test_Execute_SubQuery(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"cc", "name"}},
},
Table: parsers.Table{
Value: "c",
},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
JoinItems: []parsers.JoinItem{
{
Table: parsers.Table{
@@ -79,13 +78,12 @@ func Test_Execute_SubQuery(t *testing.T) {
Type: parsers.SelectItemTypeSubQuery,
Value: parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{Path: []string{"tag", "name"}},
testutils.SelectItem_Path("tag", "name"),
},
Table: parsers.Table{
Value: "tag",
SelectItem: parsers.SelectItem{
Path: []string{"c", "tags"},
},
Value: "tag",
SelectItem: testutils.SelectItem_Path("c", "tags"),
IsInSelect: true,
},
},
},
@@ -107,10 +105,10 @@ func Test_Execute_SubQuery(t *testing.T) {
t,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
testutils.SelectItem_Path("c", "id"),
},
Table: parsers.Table{
Value: "c",
SelectItem: testutils.SelectItem_Path("c"),
},
JoinItems: []parsers.JoinItem{
{
@@ -125,13 +123,12 @@ func Test_Execute_SubQuery(t *testing.T) {
Type: parsers.SelectItemTypeSubQuery,
Value: parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{Path: []string{"tag", "name"}},
testutils.SelectItem_Path("tag", "name"),
},
Table: parsers.Table{
Value: "tag",
SelectItem: parsers.SelectItem{
Path: []string{"c", "tags"},
},
Value: "tag",
SelectItem: testutils.SelectItem_Path("c", "tags"),
IsInSelect: true,
},
Exists: true,
},

View File

@@ -6,6 +6,7 @@ import (
"github.com/pikami/cosmium/parsers"
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
testutils "github.com/pikami/cosmium/test_utils"
)
func Test_Execute_TypeCheckingFunctions(t *testing.T) {
@@ -40,7 +41,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -76,7 +77,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -112,7 +113,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -148,7 +149,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -184,7 +185,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -220,7 +221,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -256,7 +257,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -292,7 +293,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -328,7 +329,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{
@@ -364,7 +365,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
},
},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
},
mockData,
[]memoryexecutor.RowType{

View File

@@ -23,7 +23,7 @@ func Test_Execute_Where(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.ComparisonExpression{
Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "isCool"}},
@@ -46,7 +46,7 @@ func Test_Execute_Where(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.ComparisonExpression{
Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "id"}},
@@ -71,7 +71,7 @@ func Test_Execute_Where(t *testing.T) {
{Path: []string{"c", "id"}},
{Path: []string{"c", "_self"}, Alias: "self"},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.LogicalExpression{
Operation: parsers.LogicalExpressionTypeAnd,
Expressions: []interface{}{
@@ -102,7 +102,7 @@ func Test_Execute_Where(t *testing.T) {
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
},
Table: parsers.Table{Value: "c"},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.LogicalExpression{
Operation: parsers.LogicalExpressionTypeAnd,
Expressions: []interface{}{

View File

@@ -47,7 +47,10 @@ func GetCollection(serverName *C.char, databaseId *C.char, collectionId *C.char)
return C.CString("")
}
collectionJson, _ := json.Marshal(collection)
collectionJson, err := json.Marshal(collection)
if err != nil {
return C.CString("")
}
return C.CString(string(collectionJson))
}
@@ -67,7 +70,10 @@ func GetAllCollections(serverName *C.char, databaseId *C.char) *C.char {
return C.CString("")
}
collectionsJson, _ := json.Marshal(collections)
collectionsJson, err := json.Marshal(collections)
if err != nil {
return C.CString("")
}
return C.CString(string(collectionsJson))
}

View File

@@ -45,7 +45,10 @@ func GetDatabase(serverName *C.char, databaseId *C.char) *C.char {
return C.CString("")
}
databaseJson, _ := json.Marshal(database)
databaseJson, err := json.Marshal(database)
if err != nil {
return C.CString("")
}
return C.CString(string(databaseJson))
}

View File

@@ -49,7 +49,10 @@ func GetDocument(serverName *C.char, databaseId *C.char, collectionId *C.char, d
return C.CString("")
}
documentJson, _ := json.Marshal(document)
documentJson, err := json.Marshal(document)
if err != nil {
return C.CString("")
}
return C.CString(string(documentJson))
}
@@ -70,7 +73,10 @@ func GetAllDocuments(serverName *C.char, databaseId *C.char, collectionId *C.cha
return C.CString("")
}
documentsJson, _ := json.Marshal(documents)
documentsJson, err := json.Marshal(documents)
if err != nil {
return C.CString("")
}
return C.CString(string(documentsJson))
}

View File

@@ -14,7 +14,7 @@ type ServerInstance struct {
}
var serverInstances map[string]*ServerInstance
var mutex sync.RWMutex
var mutex sync.Mutex
const (
ResponseSuccess = 0
@@ -25,6 +25,7 @@ const (
ResponseFailedToParseRequest = 103
ResponseServerInstanceAlreadyExists = 104
ResponseServerInstanceNotFound = 105
ResponseFailedToStartServer = 106
ResponseRepositoryNotFound = 200
ResponseRepositoryConflict = 201
@@ -32,8 +33,8 @@ const (
)
func getInstance(serverName string) (*ServerInstance, bool) {
mutex.RLock()
defer mutex.RUnlock()
mutex.Lock()
defer mutex.Unlock()
if serverInstances == nil {
serverInstances = make(map[string]*ServerInstance)

View File

@@ -1,8 +1,12 @@
package main
/*
#include <stdlib.h>
*/
import "C"
import (
"encoding/json"
"unsafe"
"github.com/pikami/cosmium/api"
"github.com/pikami/cosmium/api/config"
@@ -33,7 +37,10 @@ func CreateServerInstance(serverName *C.char, configurationJSON *C.char) int {
})
server := api.NewApiServer(repository, configuration)
server.Start()
err = server.Start()
if err != nil {
return ResponseFailedToStartServer
}
addInstance(serverNameStr, &ServerInstance{
server: server,
@@ -87,4 +94,9 @@ func LoadServerInstanceState(serverName *C.char, stateJSON *C.char) int {
return ResponseServerInstanceNotFound
}
//export FreeMemory
func FreeMemory(ptr *C.char) {
C.free(unsafe.Pointer(ptr))
}
func main() {}

View File

@@ -51,3 +51,9 @@ func SelectItem_Constant_Parameter(name string) parsers.SelectItem {
},
}
}
func SelectItem_Path(path ...string) parsers.SelectItem {
return parsers.SelectItem{
Path: path,
}
}