Skip to content

Commit b92e041

Browse files
authored
Merge pull request #3 from motherduckdb/add-init
Add init sql
2 parents d7d0408 + 9f224db commit b92e041

File tree

11 files changed

+193
-55
lines changed

11 files changed

+193
-55
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changelog
22

3-
## 1.0.0 (Unreleased)
3+
## 0.1.0 (Unreleased)
44

55
Initial release.

cmd/preinstall-extensions/go.mod

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module github.com/motherduckdb/grafana-duckdb-datasource/cmd/preinstall-extensions
2+
3+
go 1.23
4+
5+
require github.com/marcboeker/go-duckdb v1.8.3
6+
7+
require (
8+
github.com/apache/arrow/go/v17 v17.0.0 // indirect
9+
github.com/goccy/go-json v0.10.3 // indirect
10+
github.com/google/flatbuffers v24.3.25+incompatible // indirect
11+
github.com/klauspost/compress v1.17.11 // indirect
12+
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
13+
github.com/mitchellh/mapstructure v1.5.0 // indirect
14+
github.com/pierrec/lz4/v4 v4.1.21 // indirect
15+
github.com/zeebo/xxh3 v1.0.2 // indirect
16+
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
17+
golang.org/x/mod v0.21.0 // indirect
18+
golang.org/x/sync v0.8.0 // indirect
19+
golang.org/x/sys v0.26.0 // indirect
20+
golang.org/x/tools v0.26.0 // indirect
21+
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
22+
gonum.org/v1/gonum v0.15.1 // indirect
23+
)

cmd/preinstall-extensions/go.sum

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
github.com/apache/arrow/go/v17 v17.0.0 h1:RRR2bdqKcdbss9Gxy2NS/hK8i4LDMh23L6BbkN5+F54=
2+
github.com/apache/arrow/go/v17 v17.0.0/go.mod h1:jR7QHkODl15PfYyjM2nU+yTLScZ/qfj7OSUZmJ8putc=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
6+
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
7+
github.com/google/flatbuffers v24.3.25+incompatible h1:CX395cjN9Kke9mmalRoL3d81AtFUxJM+yDthflgJGkI=
8+
github.com/google/flatbuffers v24.3.25+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
9+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
10+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
11+
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
12+
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
13+
github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM=
14+
github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
15+
github.com/marcboeker/go-duckdb v1.8.0 h1:iOWv1wTL0JIMqpyns6hCf5XJJI4fY6lmJNk+itx5RRo=
16+
github.com/marcboeker/go-duckdb v1.8.0/go.mod h1:2oV8BZv88S16TKGKM+Lwd0g7DX84x0jMxjTInThC8Is=
17+
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
18+
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
19+
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
20+
github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
21+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
22+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
23+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
24+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
25+
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
26+
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
27+
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
28+
github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA=
29+
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
30+
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
31+
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
32+
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
33+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
34+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
35+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
36+
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
37+
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
38+
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
39+
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=
40+
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
41+
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
42+
gonum.org/v1/gonum v0.15.1 h1:FNy7N6OUZVUaWG9pTiD+jlhdQ3lMP+/LcTpJ6+a8sQ0=
43+
gonum.org/v1/gonum v0.15.1/go.mod h1:eZTZuRFrzu5pcyjN5wJhcIhnUdNijYxX1T2IcrOGY0o=
44+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
45+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

cmd/preinstall-extensions/main.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// From https://github.com/snakedotdev/grafana-duckdb-datasource
2+
// Apache 2.0 Licensed
3+
// Copyright snakedotdev
4+
// Modified from original version
5+
6+
package main
7+
8+
import (
9+
"database/sql"
10+
"flag"
11+
"fmt"
12+
"log"
13+
"path/filepath"
14+
"strings"
15+
16+
_ "github.com/marcboeker/go-duckdb"
17+
)
18+
19+
func main() {
20+
var (
21+
sqlCmd = flag.String("s", "", "SQL command to execute (multiple commands can be separated by semicolons)")
22+
dbPath = flag.String("db", "", "Path to DuckDB database file (empty for in-memory)")
23+
)
24+
25+
flag.Parse()
26+
27+
if *sqlCmd == "" {
28+
log.Fatal("SQL command is required")
29+
}
30+
31+
// Prepare database path
32+
dsn := "?access_mode=read_write"
33+
if *dbPath != "" {
34+
absPath, err := filepath.Abs(*dbPath)
35+
if err != nil {
36+
log.Fatalf("Failed to get absolute path: %v", err)
37+
}
38+
dsn = absPath + dsn
39+
}
40+
41+
fmt.Printf("Using DSN: %s\n", dsn)
42+
43+
// Open database connection
44+
db, err := sql.Open("duckdb", dsn)
45+
if err != nil {
46+
log.Fatalf("Failed to open database: %v", err)
47+
}
48+
defer db.Close()
49+
50+
// Split the input command into individual commands
51+
commands := strings.Split(*sqlCmd, ";")
52+
53+
// Execute each command
54+
for _, cmd := range commands {
55+
// Skip empty commands
56+
cmd = strings.TrimSpace(cmd)
57+
if cmd == "" {
58+
continue
59+
}
60+
61+
fmt.Printf("Executing: %s\n", cmd)
62+
result, err := db.Exec(cmd)
63+
if err != nil {
64+
log.Fatalf("Failed to execute SQL '%s': %v", cmd, err)
65+
}
66+
if result != nil {
67+
rows, _ := result.RowsAffected()
68+
fmt.Printf("Rows affected: %d\n", rows)
69+
}
70+
}
71+
72+
fmt.Println("All commands executed successfully")
73+
}

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ require (
9393
go.opentelemetry.io/otel/sdk v1.33.0 // indirect
9494
go.opentelemetry.io/otel/trace v1.33.0 // indirect
9595
go.opentelemetry.io/proto/otlp v1.4.0 // indirect
96-
golang.org/x/crypto v0.31.0 // indirect
96+
golang.org/x/crypto v0.32.0 // indirect
9797
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
9898
golang.org/x/mod v0.22.0 // indirect
99-
golang.org/x/net v0.32.0 // indirect
99+
golang.org/x/net v0.34.0 // indirect
100100
golang.org/x/sync v0.10.0 // indirect
101-
golang.org/x/sys v0.28.0 // indirect
102-
golang.org/x/term v0.27.0 // indirect
101+
golang.org/x/sys v0.29.0 // indirect
102+
golang.org/x/term v0.28.0 // indirect
103103
golang.org/x/text v0.21.0 // indirect
104104
golang.org/x/tools v0.28.0 // indirect
105105
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
268268
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
269269
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
270270
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
271-
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
272-
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
271+
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
272+
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
273273
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 h1:e66Fs6Z+fZTbFBAxKfP3PALWBtpfqks2bwGcexMxgtk=
274274
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0/go.mod h1:2TbTHSBQa924w8M6Xs1QcRcFwyucIwBGpK1p2f1YFFY=
275275
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
@@ -281,8 +281,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
281281
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
282282
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
283283
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
284-
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
285-
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
284+
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
285+
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
286286
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
287287
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
288288
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -300,10 +300,10 @@ golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBc
300300
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
301301
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
302302
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
303-
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
304-
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
305-
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
306-
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
303+
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
304+
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
305+
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
306+
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
307307
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
308308
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
309309
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "duckdb-datasource",
3-
"version": "1.0.0",
4-
"description": "Duck db and mother duck datasource for grafana",
3+
"version": "0.1.0",
4+
"description": "DuckDB and MotherDuck datasource for grafana",
55
"scripts": {
66
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
77
"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",

pkg/models/settings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
type PluginSettings struct {
1111
Path string `json:"path"`
12+
InitSql string `json:"initSql"`
1213
Secrets *SecretPluginSettings `json:"-"`
1314
}
1415

@@ -22,14 +23,13 @@ func LoadPluginSettings(source backend.DataSourceInstanceSettings) (*PluginSetti
2223
if err != nil {
2324
return nil, fmt.Errorf("could not unmarshal PluginSettings json: %w", err)
2425
}
25-
2626
settings.Secrets = loadSecretPluginSettings(source.DecryptedSecureJSONData)
2727

2828
return &settings, nil
2929
}
3030

3131
func loadSecretPluginSettings(source map[string]string) *SecretPluginSettings {
3232
return &SecretPluginSettings{
33-
MotherDuckToken: source["motherduckToken"],
33+
MotherDuckToken: source["motherDuckToken"],
3434
}
3535
}

pkg/plugin/duckdb_driver.go

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,50 +57,24 @@ func (d *DuckDBDriver) Connect(ctx context.Context, settings backend.DataSourceI
5757
os.Setenv("motherduck_token", config.Secrets.MotherDuckToken)
5858
}
5959

60-
// // join config as url parmaeters
61-
// config, err := parseConfig(settings)
62-
63-
// if err != nil {
64-
// return nil, err
65-
// }
66-
67-
// // Create a slice to hold the URL-encoded key-value pairs
68-
// var parts []string
69-
// var dbPath string
70-
// // Iterate through the map
71-
// for key, value := range config {
72-
// if key == "path" {
73-
// dbPath = value
74-
// continue
75-
// } else if key == "apiKey" {
76-
// }
77-
78-
// // URL-encode the key and the value
79-
// encodedKey := url.QueryEscape(key)
80-
// encodedValue := url.QueryEscape(value)
81-
82-
// // Append the encoded key-value pair to the slice
83-
// parts = append(parts, fmt.Sprintf("%s=%s", encodedKey, encodedValue))
84-
// }
85-
86-
// Join all parts with '&' to form the final query string
87-
// queryString := strings.Join(parts, "&")
88-
// dbString := strings.Join([]string{dbPath, queryString}, "?")
89-
9060
connector, err := duckdb.NewConnector(config.Path, func(execer driver.ExecerContext) error {
91-
9261
bootQueries := []string{}
9362

9463
if strings.HasPrefix(config.Path, "md:") {
9564
bootQueries = append(bootQueries, "INSTALL 'motherduck';", "LOAD 'motherduck';")
9665
}
9766

98-
// read env variable GF_PATHS_HOME
67+
// read env variable GF_PATHS_HOME and use it as the home directory for extension installation.
9968
homePath := os.Getenv("GF_PATHS_HOME")
10069
if homePath != "" {
10170
bootQueries = append(bootQueries, "SET home_directory='"+homePath+"';")
10271
}
10372

73+
// User defined init queries.
74+
if strings.TrimSpace(config.InitSql) != "" {
75+
bootQueries = append(bootQueries, config.InitSql)
76+
}
77+
10478
for _, query := range bootQueries {
10579
_, err = execer.ExecContext(context.Background(), query, nil)
10680
if err != nil {

src/components/ConfigEditor.tsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { ChangeEvent } from 'react';
2-
import { InlineField, Input, SecretInput } from '@grafana/ui';
2+
import { InlineField, Input, SecretInput, TextArea } from '@grafana/ui';
33
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
44
import { DuckDBDataSourceOptions, SecureJsonData } from '../types';
55

@@ -19,6 +19,17 @@ export function ConfigEditor(props: Props) {
1919
});
2020
};
2121

22+
const onInitSqlChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
23+
onOptionsChange({
24+
...options,
25+
jsonData: {
26+
...jsonData,
27+
initSql: event.target.value,
28+
},
29+
});
30+
};
31+
32+
2233
// Secure field (only sent to the backend)
2334
const onMotherDuckTokenChange = (event: ChangeEvent<HTMLInputElement>) => {
2435
onOptionsChange({
@@ -33,28 +44,37 @@ export function ConfigEditor(props: Props) {
3344
onOptionsChange({
3445
...options,
3546
secureJsonFields: {
36-
...options.secureJsonFields,
3747
motherDuckToken: false,
3848
},
3949
secureJsonData: {
40-
...options.secureJsonData,
4150
motherDuckToken: '',
4251
},
4352
});
4453
};
4554

4655
return (
4756
<>
48-
<InlineField label="DB Path" labelWidth={20} interactive tooltip={'Json field returned to frontend'}>
57+
<InlineField label="DB Path" labelWidth={20} interactive tooltip={'path to DuckDB file'}>
4958
<Input
5059
id="config-editor-path"
5160
onChange={onPathChange}
5261
value={jsonData.path}
53-
placeholder="Enter the path to the duckdb file, or :memory: for in-memory database."
62+
placeholder="Enter the path to the duckdb file, or leave blank for in-memory database."
5463
width={40}
5564
/>
5665
</InlineField>
57-
<InlineField label="MotherDuck Token" labelWidth={20} interactive tooltip={'Secure json field (backend only)'}>
66+
<InlineField label="Init SQL" labelWidth={20} interactive
67+
tooltip={'(Optional) SQL to run when connection is established'}>
68+
<TextArea
69+
id="config-editor-init-sql"
70+
onChange={onInitSqlChange}
71+
value={jsonData.initSql || ''}
72+
placeholder="e.g. INSTALL 'httpfs'; LOAD 'httpfs';"
73+
width={60}
74+
rows={5}
75+
/>
76+
</InlineField>
77+
<InlineField label="MotherDuck Token" labelWidth={20} interactive tooltip={'MotherDuck Token'}>
5878
<SecretInput
5979
required
6080
id="config-editor-md-token"
@@ -66,6 +86,8 @@ export function ConfigEditor(props: Props) {
6686
onChange={onMotherDuckTokenChange}
6787
/>
6888
</InlineField>
89+
90+
6991
</>
7092
);
7193
}

0 commit comments

Comments
 (0)