Repository: oom-ai/oomstore
Pull request #891 (2022-01-04 06:03:43)

refactor: use pointer for consistency

codecov[bot]: # [Codecov](https://codecov.io/gh/oom-ai/oomstore/pull/891?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai) Report
> Merging [#891](https://codecov.io/gh/oom-ai/oomstore/pull/891?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai) (4dc8a1f) into [main](https://codecov.io/gh/oom-ai/oomstore/commit/77cd80d135c3df8456fa4a2059c9ae64c52cc5e2?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai) (77cd80d) will **increase** coverage by `0.07%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/oom-ai/oomstore/pull/891/graphs/tree.svg?width=650&height=150&src=pr&token=C59L7LTRM4&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai)](https://codecov.io/gh/oom-ai/oomstore/pull/891?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai)

```diff
@@            Coverage Diff             @@
##             main     #891      +/-   ##
==========================================
+ Coverage   51.28%   51.35%   +0.07%     
==========================================
  Files          84       84              
  Lines        3436     3441       +5     
==========================================
+ Hits         1762     1767       +5     
  Misses       1461     1461              
  Partials      213      213              
```


| [Impacted Files](https://codecov.io/gh/oom-ai/oomstore/pull/891?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai) | Coverage Δ | |
|---|---|---|
| [internal/database/metadata/mysql/store.go](https://codecov.io/gh/oom-ai/oomstore/pull/891/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai#diff-aW50ZXJuYWwvZGF0YWJhc2UvbWV0YWRhdGEvbXlzcWwvc3RvcmUuZ28=) | `46.66% <100.00%> (ø)` | |
| [...rnal/database/metadata/postgres/create\_database.go](https://codecov.io/gh/oom-ai/oomstore/pull/891/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai#diff-aW50ZXJuYWwvZGF0YWJhc2UvbWV0YWRhdGEvcG9zdGdyZXMvY3JlYXRlX2RhdGFiYXNlLmdv) | `40.90% <100.00%> (ø)` | |
| [...ternal/database/metadata/sqlite/create\_database.go](https://codecov.io/gh/oom-ai/oomstore/pull/891/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai#diff-aW50ZXJuYWwvZGF0YWJhc2UvbWV0YWRhdGEvc3FsaXRlL2NyZWF0ZV9kYXRhYmFzZS5nbw==) | `43.47% <100.00%> (ø)` | |
| [pkg/oomstore/online\_query.go](https://codecov.io/gh/oom-ai/oomstore/pull/891/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai#diff-cGtnL29vbXN0b3JlL29ubGluZV9xdWVyeS5nbw==) | `84.03% <0.00%> (ø)` | |
| [pkg/oomstore/join.go](https://codecov.io/gh/oom-ai/oomstore/pull/891/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai#diff-cGtnL29vbXN0b3JlL2pvaW4uZ28=) | `38.21% <0.00%> (+2.03%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/oom-ai/oomstore/pull/891?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/oom-ai/oomstore/pull/891?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai). Last update [77cd80d...4dc8a1f](https://codecov.io/gh/oom-ai/oomstore/pull/891?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=oom-ai).


Patch:
diff --git a/internal/database/database.go b/internal/database/database.go
index 30266104..d6da9932 100644
--- a/internal/database/database.go
+++ b/internal/database/database.go
@@ -70,13 +70,13 @@ func OpenMetadataStore(opt types.MetadataStoreConfig) (metadata.Store, error) {
 func CreateMetadataDatabase(ctx context.Context, opt types.MetadataStoreConfig) error {
 	switch opt.Backend {
 	case types.BackendPostgres:
-		return metadataPG.CreateDatabase(ctx, *opt.Postgres)
+		return metadataPG.CreateDatabase(ctx, opt.Postgres)
 	case types.BackendMySQL:
-		return metadataMySQL.CreateDatabase(ctx, *opt.MySQL)
+		return metadataMySQL.CreateDatabase(ctx, opt.MySQL)
 	case types.BackendTiDB:
-		return metadataMySQL.CreateDatabase(ctx, *opt.TiDB)
+		return metadataMySQL.CreateDatabase(ctx, opt.TiDB)
 	case types.BackendSQLite:
-		return metadataSQLite.CreateDatabase(ctx, *opt.SQLite)
+		return metadataSQLite.CreateDatabase(ctx, opt.SQLite)
 	default:
 		return fmt.Errorf("unsupported backend: %s", opt.Backend)
 	}
diff --git a/internal/database/metadata/mysql/store.go b/internal/database/metadata/mysql/store.go
index 5586a8c3..3d58f5f1 100644
--- a/internal/database/metadata/mysql/store.go
+++ b/internal/database/metadata/mysql/store.go
@@ -59,7 +59,7 @@ func Open(ctx context.Context, option *types.MySQLOpt) (*DB, error) {
 	}, nil
 }
 
-func CreateDatabase(ctx context.Context, opt types.MySQLOpt) (err error) {
+func CreateDatabase(ctx context.Context, opt *types.MySQLOpt) (err error) {
 	defaultDB, err := dbutil.OpenMysqlDB(opt.Host, opt.Port, opt.User, opt.Password, "")
 	if err != nil {
 		return
diff --git a/internal/database/metadata/postgres/create_database.go b/internal/database/metadata/postgres/create_database.go
index 1d5a6104..93aea8cb 100644
--- a/internal/database/metadata/postgres/create_database.go
+++ b/internal/database/metadata/postgres/create_database.go
@@ -12,7 +12,7 @@ import (
 	"github.com/oom-ai/oomstore/pkg/oomstore/types"
 )
 
-func CreateDatabase(ctx context.Context, opt types.PostgresOpt) (err error) {
+func CreateDatabase(ctx context.Context, opt *types.PostgresOpt) (err error) {
 	defaultDB, err := dbutil.OpenPostgresDB(opt.Host, opt.Port, opt.User, opt.Password, "")
 	if err != nil {
 		return
diff --git a/internal/database/metadata/sqlite/create_database.go b/internal/database/metadata/sqlite/create_database.go
index c6070768..98ff4445 100644
--- a/internal/database/metadata/sqlite/create_database.go
+++ b/internal/database/metadata/sqlite/create_database.go
@@ -9,7 +9,7 @@ import (
 	"github.com/oom-ai/oomstore/pkg/oomstore/types"
 )
 
-func CreateDatabase(ctx context.Context, opt types.SQLiteOpt) (err error) {
+func CreateDatabase(ctx context.Context, opt *types.SQLiteOpt) (err error) {
 	db, err := dbutil.OpenSQLite(opt.DBFile)
 	if err != nil {
 		return err


Test patch:
diff --git a/internal/database/metadata/mysql/db_test.go b/internal/database/metadata/mysql/db_test.go
index fbfe7ce2..fc0a41c2 100644
--- a/internal/database/metadata/mysql/db_test.go
+++ b/internal/database/metadata/mysql/db_test.go
@@ -25,7 +25,7 @@ func prepareStore(t *testing.T) (context.Context, metadata.Store) {
 	ctx := context.Background()
 	opt := runtime_mysql.GetOpt(DATABASE)
 
-	if err := mysql.CreateDatabase(ctx, *opt); err != nil {
+	if err := mysql.CreateDatabase(ctx, opt); err != nil {
 		t.Fatal(err)
 	}
 	store, err := mysql.Open(ctx, opt)
@@ -44,7 +44,7 @@ func TestCreateDatabase(t *testing.T) {
 
 	ctx := context.Background()
 	opt := runtime_mysql.GetOpt(DATABASE)
-	if err := mysql.CreateDatabase(ctx, *opt); err != nil {
+	if err := mysql.CreateDatabase(ctx, opt); err != nil {
 		t.Fatal(err)
 	}
 	store, err := mysql.Open(ctx, opt)
diff --git a/internal/database/metadata/postgres/db_test.go b/internal/database/metadata/postgres/db_test.go
index 2af3c021..3996d9f6 100644
--- a/internal/database/metadata/postgres/db_test.go
+++ b/internal/database/metadata/postgres/db_test.go
@@ -25,7 +25,7 @@ func prepareStore(t *testing.T) (context.Context, metadata.Store) {
 	ctx := context.Background()
 
 	opt := runtime_pg.RootOpt(DATABASE)
-	if err := postgres.CreateDatabase(ctx, *opt); err != nil {
+	if err := postgres.CreateDatabase(ctx, opt); err != nil {
 		t.Fatal(err)
 	}
 
@@ -42,7 +42,7 @@ func TestCreateDatabase(t *testing.T) {
 
 	ctx := context.Background()
 	opt := runtime_pg.RootOpt(DATABASE)
-	if err := postgres.CreateDatabase(ctx, *opt); err != nil {
+	if err := postgres.CreateDatabase(ctx, opt); err != nil {
 		t.Fatal(err)
 	}
 	store, err := postgres.Open(ctx, opt)
diff --git a/internal/database/metadata/sqlite/db_test.go b/internal/database/metadata/sqlite/db_test.go
index 53e0df60..2de2b1f1 100644
--- a/internal/database/metadata/sqlite/db_test.go
+++ b/internal/database/metadata/sqlite/db_test.go
@@ -29,7 +29,7 @@ func prepareDB(t *testing.T) (context.Context, *sqlite.DB) {
 	}
 	file.Close()
 
-	err = sqlite.CreateDatabase(ctx, types.SQLiteOpt{
+	err = sqlite.CreateDatabase(ctx, &types.SQLiteOpt{
 		DBFile: file.Name(),
 	})
 	if err != nil {
diff --git a/internal/database/metadata/tidb/db_test.go b/internal/database/metadata/tidb/db_test.go
index ba33e199..03cd7eb1 100644
--- a/internal/database/metadata/tidb/db_test.go
+++ b/internal/database/metadata/tidb/db_test.go
@@ -25,7 +25,7 @@ func prepareStore(t *testing.T) (context.Context, metadata.Store) {
 	ctx := context.Background()
 	opt := runtime_tidb.GetOpt(DATABASE)
 
-	if err := mysql.CreateDatabase(ctx, *opt); err != nil {
+	if err := mysql.CreateDatabase(ctx, opt); err != nil {
 		t.Fatal(err)
 	}
 	store, err := mysql.Open(ctx, opt)
@@ -44,7 +44,7 @@ func TestCreateDatabase(t *testing.T) {
 
 	ctx := context.Background()
 	opt := runtime_tidb.GetOpt(DATABASE)
-	if err := mysql.CreateDatabase(ctx, *opt); err != nil {
+	if err := mysql.CreateDatabase(ctx, opt); err != nil {
 		t.Fatal(err)
 	}
 	store, err := mysql.Open(ctx, opt)