@@ -6,29 +6,31 @@ import (
66 "os"
77 "strings"
88
9+ "github.com/DataBridgeTech/dbqcore"
10+
911 "github.com/spf13/cobra"
1012 "github.com/spf13/viper"
1113 "gopkg.in/yaml.v3"
1214)
1315
14- type DbqApp interface {
16+ type DbqCliApp interface {
1517 PingDataSource (srcId string ) (string , error )
1618 ImportDatasets (srcId string , filter string ) ([]string , error )
17- ProfileDataset (srcId string , dataset string , sample bool ) (* TableMetrics , error )
18- GetDbqConfig () * DbqConfig
19+ ProfileDataset (srcId string , dataset string , sample bool ) (* dbqcore. TableMetrics , error )
20+ GetDbqConfig () * dbqcore. DbqConfig
1921 SaveDbqConfig () error
20- FindDataSourceById (srcId string ) * DataSource
21- RunCheck (check * Check , dataSource * DataSource , dataset string , defaultWhere string ) (bool , string , error )
22+ FindDataSourceById (srcId string ) * dbqcore. DataSource
23+ RunCheck (check * dbqcore. Check , dataSource * dbqcore. DataSource , dataset string , defaultWhere string ) (bool , string , error )
2224 SetLogLevel (level slog.Level )
2325}
2426
2527type DbqAppImpl struct {
2628 dbqConfigPath string
27- dbqConfig * DbqConfig
29+ dbqConfig * dbqcore. DbqConfig
2830 logLevel slog.Level
2931}
3032
31- func NewDbqApp (dbqConfigPath string ) DbqApp {
33+ func NewDbqCliApp (dbqConfigPath string ) DbqCliApp {
3234 dbqConfig , dbqConfigUsedPath := initConfig (dbqConfigPath )
3335 return & DbqAppImpl {
3436 dbqConfigPath : dbqConfigUsedPath ,
@@ -63,7 +65,7 @@ func (app *DbqAppImpl) ImportDatasets(srcId string, filter string) ([]string, er
6365 return cnn .ImportDatasets (filter )
6466}
6567
66- func (app * DbqAppImpl ) ProfileDataset (srcId string , dataset string , sample bool ) (* TableMetrics , error ) {
68+ func (app * DbqAppImpl ) ProfileDataset (srcId string , dataset string , sample bool ) (* dbqcore. TableMetrics , error ) {
6769 var dataSource = app .FindDataSourceById (srcId )
6870 cnn , err := getDbqConnector (* dataSource )
6971 if err != nil {
@@ -72,7 +74,7 @@ func (app *DbqAppImpl) ProfileDataset(srcId string, dataset string, sample bool)
7274 return cnn .ProfileDataset (dataset , sample )
7375}
7476
75- func (app * DbqAppImpl ) GetDbqConfig () * DbqConfig {
77+ func (app * DbqAppImpl ) GetDbqConfig () * dbqcore. DbqConfig {
7678 return app .dbqConfig
7779}
7880
@@ -90,7 +92,7 @@ func (app *DbqAppImpl) SaveDbqConfig() error {
9092 return nil
9193}
9294
93- func (app * DbqAppImpl ) FindDataSourceById (srcId string ) * DataSource {
95+ func (app * DbqAppImpl ) FindDataSourceById (srcId string ) * dbqcore. DataSource {
9496 for i := range app .dbqConfig .DataSources {
9597 if app .dbqConfig .DataSources [i ].ID == srcId {
9698 return & app .dbqConfig .DataSources [i ]
@@ -99,7 +101,7 @@ func (app *DbqAppImpl) FindDataSourceById(srcId string) *DataSource {
99101 return nil
100102}
101103
102- func (app * DbqAppImpl ) RunCheck (check * Check , dataSource * DataSource , dataset string , defaultWhere string ) (bool , string , error ) {
104+ func (app * DbqAppImpl ) RunCheck (check * dbqcore. Check , dataSource * dbqcore. DataSource , dataset string , defaultWhere string ) (bool , string , error ) {
103105 cnn , err := getDbqConnector (* dataSource )
104106 if err != nil {
105107 return false , "" , err
@@ -111,7 +113,7 @@ func (app *DbqAppImpl) SetLogLevel(logLevel slog.Level) {
111113 app .logLevel = logLevel
112114}
113115
114- func initConfig (dbqConfigPath string ) (* DbqConfig , string ) {
116+ func initConfig (dbqConfigPath string ) (* dbqcore. DbqConfig , string ) {
115117 v := viper .New ()
116118
117119 if dbqConfigPath != "" {
@@ -129,19 +131,19 @@ func initConfig(dbqConfigPath string) (*DbqConfig, string) {
129131 cobra .CheckErr (err )
130132 }
131133
132- var dbqConfig DbqConfig
134+ var dbqConfig dbqcore. DbqConfig
133135 if err := v .Unmarshal (& dbqConfig ); err != nil {
134136 cobra .CheckErr (err )
135137 }
136138
137139 return & dbqConfig , v .ConfigFileUsed ()
138140}
139141
140- func getDbqConnector (ds DataSource ) (DbqConnector , error ) {
142+ func getDbqConnector (ds dbqcore. DataSource ) (dbqcore. DbqConnector , error ) {
141143 dsType := strings .ToLower (ds .Type )
142144 switch dsType {
143145 case "clickhouse" :
144- return NewClickhouseDbqConnector (ds )
146+ return dbqcore . NewClickhouseDbqConnector (ds )
145147 default :
146148 return nil , fmt .Errorf ("data source type '%s' is not supported" , dsType )
147149 }
0 commit comments