@@ -4,52 +4,22 @@ import (
4
4
chdbpurego "github.com/chdb-io/chdb-go/chdb-purego"
5
5
)
6
6
7
- // Query calls queryToBuffer with a default output format of "CSV" if not provided.
7
+ // Query calls query_conn with a default in-memory session and default output format of "CSV" if not provided.
8
8
func Query (queryStr string , outputFormats ... string ) (result chdbpurego.ChdbResult , err error ) {
9
9
outputFormat := "CSV" // Default value
10
10
if len (outputFormats ) > 0 {
11
11
outputFormat = outputFormats [0 ]
12
12
}
13
- return queryToBuffer (queryStr , outputFormat , "" , "" )
14
- }
15
-
16
- // queryToBuffer constructs the arguments for QueryStable and calls it.
17
- func queryToBuffer (queryStr , outputFormat , path , udfPath string ) (result chdbpurego.ChdbResult , err error ) {
18
- argv := []string {"clickhouse" , "--multiquery" }
19
-
20
- // Handle output format
21
- if outputFormat == "Debug" || outputFormat == "debug" {
22
- argv = append (argv , "--verbose" , "--log-level=trace" , "--output-format=CSV" )
23
- } else {
24
- argv = append (argv , "--output-format=" + outputFormat )
25
- }
26
-
27
- // Handle path
28
- if path != "" {
29
- argv = append (argv , "--path=" + path )
30
- }
31
-
32
- // Add query string
33
- argv = append (argv , "--query=" + queryStr )
34
-
35
- // Handle user-defined functions path
36
- if udfPath != "" {
37
- argv = append (argv , "--" , "--user_scripts_path=" + udfPath , "--user_defined_executable_functions_config=" + udfPath + "/*.xml" )
13
+ tempSession , err := initConnection (":memory:" )
14
+ if err != nil {
15
+ return nil , err
38
16
}
39
-
40
- // Call QueryStable with the constructed arguments
41
- return chdbpurego .RawQuery (len (argv ), argv )
17
+ defer tempSession .Close ()
18
+ return tempSession .Query (queryStr , outputFormat )
42
19
}
43
20
44
21
func initConnection (connStr string ) (result chdbpurego.ChdbConn , err error ) {
45
22
argv := []string {connStr }
46
23
// Call NewConnection with the constructed arguments
47
24
return chdbpurego .NewConnection (len (argv ), argv )
48
25
}
49
-
50
- func connQueryToBuffer (conn chdbpurego.ChdbConn , queryStr , outputFormat string ) (result chdbpurego.ChdbResult , err error ) {
51
- if outputFormat == "" {
52
- outputFormat = "CSV"
53
- }
54
- return conn .Query (queryStr , outputFormat )
55
- }
0 commit comments