@@ -4,52 +4,22 @@ import (
44 chdbpurego "github.com/chdb-io/chdb-go/chdb-purego"
55)
66
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.
88func Query (queryStr string , outputFormats ... string ) (result chdbpurego.ChdbResult , err error ) {
99 outputFormat := "CSV" // Default value
1010 if len (outputFormats ) > 0 {
1111 outputFormat = outputFormats [0 ]
1212 }
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
3816 }
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 )
4219}
4320
4421func initConnection (connStr string ) (result chdbpurego.ChdbConn , err error ) {
4522 argv := []string {connStr }
4623 // Call NewConnection with the constructed arguments
4724 return chdbpurego .NewConnection (len (argv ), argv )
4825}
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