-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package postgres | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
"github.com/ayinke-llc/malak" | ||
"github.com/uptrace/bun" | ||
) | ||
|
||
type dashboardRepo struct { | ||
inner *bun.DB | ||
} | ||
|
||
func NewDashboardRepo(inner *bun.DB) malak.DashboardRepository { | ||
return &dashboardRepo{ | ||
inner: inner, | ||
} | ||
} | ||
|
||
func (d *dashboardRepo) Create(ctx context.Context, | ||
dashboard *malak.Dashboard) error { | ||
|
||
ctx, cancelFn := withContext(ctx) | ||
defer cancelFn() | ||
|
||
return d.inner.RunInTx(ctx, &sql.TxOptions{}, | ||
func(ctx context.Context, tx bun.Tx) error { | ||
|
||
_, err := tx.NewInsert(). | ||
Model(dashboard). | ||
Exec(ctx) | ||
return err | ||
}) | ||
} |
6 changes: 6 additions & 0 deletions
6
...datastore/postgres/migrations/20250214212029_add_extra_fields_to_dashboard_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ALTER TABLE dashboards | ||
DROP COLUMN description, | ||
DROP COLUMN chart_count, | ||
DROP COLUMN created_at, | ||
DROP COLUMN updated_at, | ||
DROP COLUMN deleted_at; |
6 changes: 6 additions & 0 deletions
6
...l/datastore/postgres/migrations/20250214212029_add_extra_fields_to_dashboard_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ALTER TABLE dashboards | ||
ADD COLUMN description TEXT NOT NULL, | ||
ADD COLUMN chart_count SMALLINT NOT NULL DEFAULT 0, | ||
ADD COLUMN created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
ADD COLUMN updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
ADD COLUMN deleted_at TIMESTAMP WITH TIME ZONE; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.