Skip to content

Commit

Permalink
feat(drivers): create the interface for the driver and how it's used
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Dec 12, 2022
1 parent ca0a935 commit dc018a5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmd/db.go
Expand Up @@ -16,15 +16,44 @@ limitations under the License.
package cmd

import (
"os"
"path"

"github.com/mrsimonemms/gobblr/pkg/drivers"
"github.com/mrsimonemms/gobblr/pkg/gobblr"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var dbOpts struct {
DataPath string
Driver drivers.Driver
}

// dbCmd represents the db command
var dbCmd = &cobra.Command{
Use: "db",
Short: "Control the dataset in your database",
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
// Use a persistent post run command as each of the subcommands is there
// to create the configure only. The execution happens here.
//
// There can be only one PersistentPostRun command.

// @todo(sje): log number of items inserted
_, err := gobblr.Execute(dbOpts.DataPath, dbOpts.Driver)

return err
},
}

func init() {
rootCmd.AddCommand(dbCmd)

currentPath, err := os.Getwd()
cobra.CheckErr(err)

viper.SetDefault("path", path.Join(currentPath, "data"))
dbCmd.PersistentFlags().StringVar(&dbOpts.DataPath, "path", viper.GetString("path"), "location of the data files")
}
20 changes: 20 additions & 0 deletions pkg/drivers/driver.go
@@ -0,0 +1,20 @@
package drivers

// NB. In this file, the interfaces refer to "table", as per a SQL
// type database. This naming convention may differ, such as "collection"
// in a MongoDB instance. However, the functionality will remain the
// same from an interface point of view.

type Driver interface {
// Authorize the connection to the database
Auth() error

// Close the database connection and free up resources
Close() error

// Insert data in bulk
InsertBulk(table string, data []map[string]interface{}) (inserted int, err error)

// Remove all the data from the table
Truncate(table string) error
}
9 changes: 9 additions & 0 deletions pkg/gobblr/execute.go
@@ -0,0 +1,9 @@
package gobblr

import "github.com/mrsimonemms/gobblr/pkg/drivers"

func Execute(dataPath string, driver drivers.Driver) (map[string]int, error) {
inserted := make(map[string]int, 0)

return inserted, nil
}

0 comments on commit dc018a5

Please sign in to comment.