Skip to content

Commit

Permalink
feat: wip! analyse v2
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury committed Dec 11, 2023
1 parent ad023bf commit d16372a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/infra/analyse/sql_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type SQLExtractor struct {
schema string
}

func (s SQLExtractor) New(tableName string, columnName string) analyse.Extractor {
func (s SQLExtractor) New(tableName string, columnName string) analyse.Extractor { //nolint:ireturn
return &SQLDataSource{
url: s.url,
schema: s.schema,
Expand Down
6 changes: 5 additions & 1 deletion pkg/analyse/driven.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package analyse

import "github.com/cgi-fr/rimo/pkg/model"
import (
"github.com/cgi-fr/rimo/pkg/model"
)

type DataSource interface {
Name() string
Expand All @@ -30,6 +32,8 @@ type ExtractorFactory interface {
}

type Extractor interface {
Open() error
Close() error
ExtractValue() (bool, interface{}, error)
}

Expand Down
19 changes: 13 additions & 6 deletions pkg/analyse/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (d *Driver) Next() bool {
if d.curColumn+1 < len(d.columns) {
// yes, so increase column index
d.curColumn++
fmt.Println("next column!", d.curTable, d.curColumn)

return true
}
Expand All @@ -79,7 +78,6 @@ func (d *Driver) Next() bool {
// yes, increase table index and read columns
d.curTable++
d.curColumn = 0
fmt.Println("next table!", d.curTable, d.curColumn)
d.columns = d.ds.ListColumn(d.tables[d.curTable])

// should we try next table because there is no column in this table
Expand All @@ -89,17 +87,24 @@ func (d *Driver) Next() bool {
}

// last table is not passed
return d.curTable < len(d.tables)
return d.curTable < len(d.tables) && len(d.columns) > 0
}

func (d *Driver) Col() (rimo.ColReader, error) { //nolint:ireturn
return &ValueIterator{
//nolint:ireturn
func (d *Driver) Col() (rimo.ColReader, error) {
vi := &ValueIterator{
Extractor: d.exf.New(d.tables[d.curTable], d.columns[d.curColumn]),
tableName: d.tables[d.curTable],
colName: d.columns[d.curColumn],
nextValue: nil,
err: nil,
}, nil
}

if err := vi.Open(); err != nil {
return nil, err
}

return vi, nil
}

func (d *Driver) Export(base *model.Base) error {
Expand All @@ -118,6 +123,8 @@ type ValueIterator struct {
err error
}

func (vi *ValueIterator) Open() error { return vi.Extractor.Open() } //nolint:wrapcheck
func (vi *ValueIterator) Close() error { return vi.Extractor.Close() } //nolint:wrapcheck
func (vi *ValueIterator) ColName() string { return vi.colName }
func (vi *ValueIterator) TableName() string { return vi.tableName }

Expand Down
3 changes: 3 additions & 0 deletions pkg/analyse/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type testExtractor struct {
index int
}

func (tds *testExtractor) Open() error { return nil }
func (tds *testExtractor) Close() error { return nil }

func (tds *testExtractor) ExtractValue() (bool, interface{}, error) {
defer func() { tds.index++ }()

Expand Down

0 comments on commit d16372a

Please sign in to comment.