Skip to content

Commit

Permalink
Try again.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncruces committed Aug 8, 2024
1 parent 20d1330 commit 33bb5e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
29 changes: 23 additions & 6 deletions ext/steampipe/steampipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,33 @@ import (
"strings"

"github.com/ncruces/go-sqlite3"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
)

func Register(db *sqlite3.Conn, plugin *plugin.Plugin) error {
for name := range plugin.TableMap {
func Register(db *sqlite3.Conn, name string, fn plugin.PluginFunc) error {
server := plugin.Server(&plugin.ServeOpts{
PluginName: name,
PluginFunc: fn,
})

_, err := server.SetAllConnectionConfigs(&proto.SetAllConnectionConfigsRequest{
Configs: []*proto.ConnectionConfig{{Connection: name}},
})
if err != nil {
return err
}

res, err := server.GetSchema(&proto.GetSchemaRequest{})
if err != nil {
return err
}

schema := res.Schema.Schema
for name := range schema {
err := sqlite3.CreateModule[*table](db, name, nil,
func(db *sqlite3.Conn, _, _, name string, _ ...string) (*table, error) {
table := table{
Table: plugin.TableMap[name],
}
table := table{TableSchema: schema[name]}

var sep string
var str strings.Builder
Expand All @@ -40,7 +57,7 @@ func Register(db *sqlite3.Conn, plugin *plugin.Plugin) error {
}

type table struct {
*plugin.Table
*proto.TableSchema
}

func (*table) BestIndex(idx *sqlite3.IndexInfo) error {
Expand Down
4 changes: 1 addition & 3 deletions ext/steampipe/steampipe_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package steampipe_test

import (
"context"
"log"

"github.com/ncruces/go-sqlite3"
Expand All @@ -13,8 +12,7 @@ import (

func Example() {
db, err := driver.Open(":memory:", func(c *sqlite3.Conn) error {
ctx := context.TODO()
return steampipe.Register(c, hackernews.Plugin(ctx))
return steampipe.Register(c, "hackernews", hackernews.Plugin)
})
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 33bb5e8

Please sign in to comment.