Skip to content

Commit b1fe9b8

Browse files
committed
✨ Allow loading of local extensions in the CLI
1 parent b531dab commit b1fe9b8

File tree

8 files changed

+29
-3
lines changed

8 files changed

+29
-3
lines changed

cmd/query.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func init() {
2525
queryCmd.Flags().Bool("read-only", false, "Start the server in read-only mode")
2626
queryCmd.Flags().StringArray("init", []string{}, "Run SQL commands in a file before the query. You can specify multiple files.")
2727
queryCmd.Flags().Bool("dev", false, "Run the program in developer mode")
28+
queryCmd.Flags().StringSlice("extension", []string{}, "Load one or more extensions by specifying their path. Separate multiple extensions with a comma.")
2829

2930
// Query flags
3031
queryCmd.Flags().StringP("query", "q", "", "Query to run")

cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func init() {
3838
rootCmd.Flags().Bool("read-only", false, "Start the server in read-only mode")
3939
rootCmd.Flags().StringArray("init", []string{}, "Run SQL commands in a file before the query. You can specify multiple files.")
4040
rootCmd.Flags().Bool("dev", false, "Run the program in developer mode")
41+
rootCmd.Flags().StringSlice("extension", []string{}, "Load one or more extensions by specifying their path. Separate multiple extensions with a comma.")
4142

4243
// Query flags
4344
rootCmd.Flags().StringP("query", "q", "", "Query to run")

cmd/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func init() {
2525
serverCmd.Flags().String("log-file", "/dev/stdout", "Log file")
2626
serverCmd.Flags().String("auth-file", "", "Path to the authentication file")
2727
serverCmd.Flags().Bool("dev", false, "Run the program in developer mode")
28+
serverCmd.Flags().StringSlice("extension", []string{}, "Load one or more extensions by specifying their path. Separate multiple extensions with a comma.")
2829

2930
addFlag_commandModifiesConfiguration(serverCmd)
3031
}

controller/profiles.go

+5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ func createOrUpdateProfile(queries *model.Queries, registryName string, pluginNa
123123
return err
124124
}
125125

126+
// If the plugin is a shared extension, we don't need to ask for the configuration
127+
if pluginInfo.Issharedextension == 1 {
128+
return nil
129+
}
130+
126131
// Parse the asked configuration required by the plugin
127132
var toAskConfig []registry.UserConfig
128133
err = json.Unmarshal([]byte(pluginInfo.Config), &toAskConfig)

controller/query.go

+9
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ func Query(cmd *cobra.Command, args []string) error {
106106
return fmt.Errorf("failed to load config: %w", err)
107107
}
108108

109+
// Get the extensions
110+
extensions, _ := cmd.Flags().GetStringSlice("extension")
111+
for _, extension := range extensions {
112+
err = namespace.LoadSharedExtension(extension, "")
113+
if err != nil {
114+
return fmt.Errorf("failed to load extension: %w", err)
115+
}
116+
}
117+
109118
// Register the namespace
110119
db, err := namespace.Register("main")
111120
if err != nil {

controller/server.go

+9
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ func Server(cmd *cobra.Command, args []string) error {
117117
return err
118118
}
119119

120+
// Get the extensions
121+
extensions, _ := cmd.Flags().GetStringSlice("extension")
122+
for _, extension := range extensions {
123+
err = instance.LoadSharedExtension(extension, "")
124+
if err != nil {
125+
return fmt.Errorf("failed to load extension: %w", err)
126+
}
127+
}
128+
120129
// We register the namespace
121130
db, err := instance.Register("")
122131
if err != nil {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/julien040/anyquery
22

33
go 1.22.3
44

5-
replace github.com/mattn/go-sqlite3 => github.com/julien040/go-sqlite3-anyquery v1.17.5
5+
replace github.com/mattn/go-sqlite3 => github.com/julien040/go-sqlite3-anyquery v1.17.6
66

77
replace github.com/runreveal/pql => github.com/julien040/pql-anyquery v0.2.1
88

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
442442
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
443443
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
444444
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
445-
github.com/julien040/go-sqlite3-anyquery v1.17.5 h1:rSP5owX6B9NTmJR4qMo6aDBzEntuMIq4/1rFvOgX2tw=
446-
github.com/julien040/go-sqlite3-anyquery v1.17.5/go.mod h1:9t7/JQ99yNR2b18cBR11VGyrJYg+Q7IQNHMWoCt6yGE=
445+
github.com/julien040/go-sqlite3-anyquery v1.17.6 h1:AJAPWCDhpZVVu10XXBOg5artrVatNaUyXR5txU9xdrY=
446+
github.com/julien040/go-sqlite3-anyquery v1.17.6/go.mod h1:9t7/JQ99yNR2b18cBR11VGyrJYg+Q7IQNHMWoCt6yGE=
447447
github.com/julien040/go-ternary v0.0.0-20230119180150-f0435f66948e h1:q8lhYSYDzN8slDRCVRt2TD2ShyjNcuQU+I9LZNPv4TM=
448448
github.com/julien040/go-ternary v0.0.0-20230119180150-f0435f66948e/go.mod h1:XXIcjDHL7vyuHA7V0UwaTKMscsqKzFkE9FTGbBeqJHM=
449449
github.com/julien040/pql-anyquery v0.2.1 h1:k4eF28S8diwFYWg1r6fKiA7ZmeiF65PTersyUY3GqVw=

0 commit comments

Comments
 (0)