Repository: danvergara/dblab
Pull request #7 (2021-04-07 15:22:53)

feat(pkg/command): add a options struct to store the values provided …
…by the user through the flags


Patch:
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
new file mode 100644
index 0000000..dcf3eb6
--- /dev/null
+++ b/.github/workflows/ci.yaml
@@ -0,0 +1,75 @@
+name: Run Integration Tests
+
+on: [push, pull_request]
+
+jobs:
+  integration-test:
+    name: Test
+    strategy:
+      matrix:
+        os: [ubuntu-latest]
+        goVer: [1.13, 1.14, 1.15, 1.16]
+    # Defines the platform for each test run.
+    runs-on: ${{ matrix.os }}
+    # define the container services used to run integration tests
+    services:
+      postgres:
+        image: postgres:12
+        env:
+          POSTGRES_USER: postgres
+          POSTGRES_PASSWORD: password
+          POSTGRES_DB: users
+        ports:
+          - 5432:5432
+        options: >-
+          --health-cmd pg_isready
+          --health-interval 10s
+          --health-timeout 5s
+          --health-retries 5
+    env:
+      DB_DATABASE: users
+      DB_USER: user
+      DB_PASSWORD: password
+
+    steps:
+      - name: Set up MySQL
+      run: |
+        sudo /etc/init.d/mysql start
+        mysql -e 'CREATE DATABASE ${{ env.DB_DATABASE }};' -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}
+
+      # The steps that will be run through for each version and platform combination.
+      - name: Set up Go ${{ matrix.goVer }}
+        uses: actions/setup-go@v2
+        with:
+          go-version: ${{ matrix.goVer }}
+      # Checks out our code locally so we can work with the files.
+      - name: Checkout code
+        uses: actions/checkout@v2
+      # Caches downloaded modules
+      - uses: actions/cache@v2
+        with:
+          path: ~/go/pkg/mod
+          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+          restore-keys: |
+            ${{ runner.os }}-go-
+      # Runs go test ./... against postgres container
+      - name: Test Postgres
+        run: go test -v ./...
+        env:
+          DB_USER: postgres
+          DB_PASSWORD: password
+          DB_HOST: postgres
+          DB_PORT: 5432
+          DB_NAME: users
+          DB_DRIVER: postgres
+
+      # Runs go test ./... against mysql container
+      - name: Test MySQL
+        run: go test -v ./...
+        env:
+          DB_USER: user
+          DB_PASSWORD: password
+          DB_HOST: localhost
+          DB_PORT: 3306
+          DB_NAME: users
+          DB_DRIVER: mysql
diff --git a/cmd/root.go b/cmd/root.go
index 48edac6..d68dc11 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -20,6 +20,7 @@ import (
 	"fmt"
 	"os"
 
+	"github.com/danvergara/dblab/pkg/command"
 	"github.com/spf13/cobra"
 
 	homedir "github.com/mitchellh/go-homedir"
@@ -46,13 +47,22 @@ func NewRootCmd() *cobra.Command {
 		Short: "Interactive databse client",
 		Long:  `dblab is a terminal UI based interactive database client for Postgres, MySQL and SQLite.`,
 		RunE: func(cmd *cobra.Command, args []string) error {
-			fmt.Printf("driver: %s\n", driver)
-			fmt.Printf("host: %s\n", host)
-			fmt.Printf("db: %s\n", db)
-			fmt.Printf("port: %s\n", port)
-			fmt.Printf("user: %s\n", user)
-			fmt.Printf("pass: %s\n", pass)
-			fmt.Printf("ssl: %s\n", ssl)
+
+			opts := command.Options{
+				Driver: driver,
+				URL:    url,
+				Host:   host,
+				Port:   port,
+				User:   user,
+				Pass:   pass,
+				DBName: db,
+				SSL:    ssl,
+			}
+
+			opts = command.SetDefault(opts)
+
+			fmt.Printf("otps : %v\n", opts)
+
 			return nil
 		},
 	}
diff --git a/go.mod b/go.mod
index 48491fa..e62a40f 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,11 @@ module github.com/danvergara/dblab
 go 1.16
 
 require (
-	github.com/mitchellh/go-homedir v1.1.0 // indirect
-	github.com/spf13/cobra v1.1.3 // indirect
-	github.com/spf13/viper v1.7.1 // indirect
+	github.com/go-sql-driver/mysql v1.6.0 // indirect
+	github.com/jmoiron/sqlx v1.3.3 // indirect
+	github.com/lib/pq v1.10.0 // indirect
+	github.com/mitchellh/go-homedir v1.1.0
+	github.com/spf13/cobra v1.1.3
+	github.com/spf13/viper v1.7.1
+	github.com/stretchr/testify v1.7.0
 )
diff --git a/go.sum b/go.sum
index 31916b2..d3b3833 100644
--- a/go.sum
+++ b/go.sum
@@ -11,6 +11,7 @@ cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqCl
 cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
 cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
+github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
@@ -32,6 +33,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
 github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
 github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
 github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
@@ -43,6 +45,9 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9
 github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
 github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
+github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
+github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
+github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
 github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
 github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
@@ -64,6 +69,7 @@ github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OI
 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
 github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
 github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
+github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
 github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
 github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
@@ -92,22 +98,31 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
 github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
 github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
+github.com/jmoiron/sqlx v1.3.3 h1:j82X0bf7oQ27XeqxicSZsTU5suPwKElg3oyxNn43iTk=
+github.com/jmoiron/sqlx v1.3.3/go.mod h1:2BljVx/86SuTyjE+aPYlHCTNvZrnJXghYGpNiXLBMCQ=
 github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
 github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
 github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
+github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
 github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
 github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
 github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
 github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
+github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
 github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
 github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
+github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
+github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
 github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
 github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
 github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
 github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
+github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
 github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
 github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
@@ -129,6 +144,7 @@ github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181
 github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
 github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
 github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
@@ -147,7 +163,9 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
 github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
 github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
 github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
+github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
+github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
 github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
 github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
 github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
@@ -169,6 +187,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
 github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
@@ -285,6 +305,7 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq
 google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
 gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
@@ -295,6 +316,8 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
 gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
 honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
diff --git a/pkg/client/client.go b/pkg/client/client.go
new file mode 100644
index 0000000..6d2c223
--- /dev/null
+++ b/pkg/client/client.go
@@ -0,0 +1,30 @@
+package client
+
+import (
+	// mysql driver.
+	_ "github.com/go-sql-driver/mysql"
+	// postgres driver.
+	_ "github.com/lib/pq"
+
+	"github.com/danvergara/dblab/pkg/command"
+	"github.com/jmoiron/sqlx"
+)
+
+// Client is used to store the pool of db connection.
+type Client struct {
+	db *sqlx.DB
+}
+
+// New return an instance of the client.
+func New(opts command.Options) (*Client, error) {
+	db, err := sqlx.Open(opts.Driver, opts.URL)
+	if err != nil {
+		return nil, err
+	}
+
+	c := Client{
+		db: db,
+	}
+
+	return &c, nil
+}
diff --git a/pkg/command/command.go b/pkg/command/command.go
new file mode 100644
index 0000000..febb2c8
--- /dev/null
+++ b/pkg/command/command.go
@@ -0,0 +1,49 @@
+package command
+
+import "os"
+
+// Options is a struct that stores the provided commands by the user.
+type Options struct {
+	Driver string
+	URL    string
+	Host   string
+	Port   string
+	User   string
+	Pass   string
+	DBName string
+	SSL    string
+}
+
+// SetDefault returns a Options struct and fills the empty
+// values with environment variables if any.
+func SetDefault(opts Options) Options {
+	if opts.URL == "" {
+		opts.URL = os.Getenv("DATABASE_URL")
+	}
+
+	if opts.Driver == "" {
+		opts.Driver = os.Getenv("DB_DRIVER")
+	}
+
+	if opts.Host == "" {
+		opts.Host = os.Getenv("DB_HOST")
+	}
+
+	if opts.User == "" {
+		opts.User = os.Getenv("DB_USER")
+	}
+
+	if opts.Pass == "" {
+		opts.Pass = os.Getenv("DB_PASSWORD")
+	}
+
+	if opts.DBName == "" {
+		opts.DBName = os.Getenv("DB_NAME")
+	}
+
+	if opts.Port == "" {
+		opts.Port = os.Getenv("DB_PORT")
+	}
+
+	return opts
+}


Test patch:
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index 75ee3ea..1add711 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -8,7 +8,7 @@ jobs:
     strategy:
       matrix:
         os: [ubuntu-latest, macos-latest]
-        goVer: [1.12, 1.13, 1.14, 1.15, 1.16]
+        goVer: [1.13, 1.14, 1.15, 1.16]
     # Defines the platform for each test run.
     runs-on: ${{ matrix.os }}
     steps:
@@ -29,30 +29,7 @@ jobs:
             ${{ runner.os }}-go-
       # Runs go test ./...
       - name: Test
-        run: go test -v ./...
-
-  coverage:
-    name: Coverage
-    runs-on: ubuntu-latest
-    steps:
-      # Installs go.
-      # Using a sigle version.
-      - name: Install Go
-        if: success()
-        uses: actions/setup-go@v2
-        with:
-          go-version: 1.16.x
-      # Checks out our code locally so we can work with the files.
-      - name: Checkout code
-        uses: actions/checkout@v2
-      ## Runs the test coverage command.
-      - name: Calc coverage
-        run: |
-          go test -v  -coverprofile=coverage.txt -covermode=atomic ./...
-      - name: Upload coverage to Codecov
-        uses: codecov/codecov-action@v1
-        with:
-          token: ${{ secrets.CODECOV_TOKEN }}
+        run: go test -v -short ./...
 
   lint:
     runs-on: ubuntu-latest
diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go
new file mode 100644
index 0000000..f123093
--- /dev/null
+++ b/pkg/client/client_test.go
@@ -0,0 +1,62 @@
+package client
+
+import (
+	"fmt"
+	"os"
+	"testing"
+
+	"github.com/danvergara/dblab/pkg/command"
+	"github.com/stretchr/testify/assert"
+)
+
+var (
+	driver   string
+	user     string
+	password string
+	host     string
+	port     string
+	name     string
+)
+
+func TestMain(m *testing.M) {
+	driver = os.Getenv("DB_DRIVER")
+	user = os.Getenv("DB_USER")
+	password = os.Getenv("DB_PASSWORD")
+	host = os.Getenv("DB_HOST")
+	port = os.Getenv("DB_PORT")
+	name = os.Getenv("DB_NAME")
+
+	os.Exit(m.Run())
+}
+
+func generateURL(driver string) string {
+	switch driver {
+	case "postgres":
+		return fmt.Sprintf("%s://%s:%s@%s:%s/%s?sslmode=mode", driver, user, password, host, port, name)
+	case "mysql":
+		return fmt.Sprintf("%s://%s:%s@tcp(%s:%s)/%s?sslmode=mode", driver, user, password, host, port, name)
+	default:
+		return ""
+	}
+}
+
+func TestNewClientByURL(t *testing.T) {
+	if testing.Short() {
+		t.Skip("skipping short mode")
+	}
+
+	url := generateURL(driver)
+
+	opts := command.Options{
+		Driver: driver,
+		URL:    url,
+	}
+
+	c, err := New(opts)
+
+	if err != nil {
+		t.Error(err)
+	}
+
+	assert.NotNil(t, c)
+}
diff --git a/pkg/command/command_test.go b/pkg/command/command_test.go
new file mode 100644
index 0000000..0750528
--- /dev/null
+++ b/pkg/command/command_test.go
@@ -0,0 +1,49 @@
+package command
+
+import (
+	"os"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestSetEnvValues(t *testing.T) {
+	if err := os.Setenv("DATABASE_URL", "postgres://user:password@host:port/database?sslmode=disable"); err != nil {
+		t.Fatal(err)
+	}
+
+	if err := os.Setenv("DB_DRIVER", "postgres"); err != nil {
+		t.Fatal(err)
+	}
+
+	if err := os.Setenv("DB_HOST", "localhost"); err != nil {
+		t.Fatal(err)
+	}
+
+	if err := os.Setenv("DB_USER", "user"); err != nil {
+		t.Fatal(err)
+	}
+
+	if err := os.Setenv("DB_PASSWORD", "password"); err != nil {
+		t.Fatal(err)
+	}
+
+	if err := os.Setenv("DB_NAME", "database"); err != nil {
+		t.Fatal(err)
+	}
+
+	if err := os.Setenv("DB_PORT", "5432"); err != nil {
+		t.Fatal(err)
+	}
+
+	opts := Options{}
+
+	result := SetDefault(opts)
+
+	assert.Equal(t, "postgres://user:password@host:port/database?sslmode=disable", result.URL)
+	assert.Equal(t, "localhost", result.Host)
+	assert.Equal(t, "user", result.User)
+	assert.Equal(t, "password", result.Pass)
+	assert.Equal(t, "database", result.DBName)
+	assert.Equal(t, "5432", result.Port)
+}
diff --git a/scripts/test_all.sh b/scripts/test_all.sh
index a2400f7..d0dc4fc 100755
--- a/scripts/test_all.sh
+++ b/scripts/test_all.sh
@@ -6,12 +6,8 @@
 set -e
 
 # database credentials
-export DBHOST=${DBHOST:-localhost}
-export PGUSER="postgres"
-export DBPASSWORD="password"
-export DATABASE="users"
-export PGPORT="15432"
-export MYSQL_PORT="13306"
+
+export MYSQL_PORT="3306"
 
 # Test different versions of postgres available on Docker Hub.
 pgversions="9.6 10.16 11.11 12.6 13.2"
@@ -21,10 +17,17 @@ do
 	PGVERSION="$i"
 	echo "--------------BEGIN POSTGRES TESTS-------------"
 	echo "Running test against PostgreSQL v$PGVERSION"
-	  docker rm -f postgres || true
-	  docker run -p $PGPORT:5432 --name postgres -e POSTGRES_PASSWORD=$DBPASSWORD -d postgres:$PGVERSION
-		sleep 5
-		make test
+
+	export DB_HOST=${DBHOST:-localhost}
+	export DB_USER="postgres"
+	export DB_PASSWORD="password"
+	export DB_NAME="users"
+	export DB_PORT="5432"
+	export DB_DRIVER="postgres"
+	docker rm -f postgres || true
+	docker run -p $DB_PORT:5432 --name postgres -e POSTGRES_PASSWORD=$DB_PASSWORD -d postgres:$PGVERSION
+	sleep 5
+	make test
 	echo "--------------END POSTGRES TESTS-------------"
 done
 
@@ -37,9 +40,16 @@ do
 	MYSQL_VERSION="$i"
 	echo "--------------BEGIN MYSQL TESTS-------------"
 	echo "Running test against MySQL v$MYSQL_VERSION"
-	  docker rm -f mysql || true
-	  docker run -p $MYSQL_PORT:3306 --name mysql -e MYSQL_PASSWORD=$DBPASSWORD -d mysql:$MYSQL_VERSION
-		sleep 5
-		make test
+
+	export DB_HOST=${DBHOST:-localhost}
+	export DB_USER="root"
+	export DB_PASSWORD="password"
+	export DB_NAME="users"
+	export DB_PORT="3306"
+	export DB_DRIVER="mysql"
+	docker rm -f mysql || true
+	docker run -p $DB_PORT:3306 --name mysql -e MYSQL_PASSWORD=$DB_PASSWORD -d mysql:$MYSQL_VERSION
+	sleep 5
+	make test
 	echo "--------------END MYSQL TESTS-------------"
 done