-
Notifications
You must be signed in to change notification settings - Fork 5
/
module.go
33 lines (27 loc) · 928 Bytes
/
module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"fmt"
"log"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"go.riyazali.net/sqlite"
)
type Module struct {
tableName string
columns SQLiteColumns
tableSchema *proto.TableSchema
table sqlite.VirtualTable
}
func NewModule(tableName string, columns SQLiteColumns, tableSchema *proto.TableSchema) *Module {
return &Module{
tableName: tableName,
columns: columns,
tableSchema: tableSchema,
table: &PluginTable{name: tableName, tableSchema: tableSchema},
}
}
func (m *Module) Connect(_ *sqlite.Conn, _ []string, declare func(string) error) (sqlite.VirtualTable, error) {
log.Println("[TRACE] Module.Connect start", m.tableName)
defer log.Println("[TRACE] Module.Connect end", m.tableName)
log.Println("[TRACE] Module.Connect table", m.tableName)
return m.table, declare(fmt.Sprintf("CREATE TABLE %s(%s)", m.tableName, m.columns.DeclarationString()))
}