Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(pg): switch reads to pg (#619)

Danny Xu6fd1c09cdc9d
diff --git a/api/task_check_run.go b/api/task_check_run.go
index e86c1be670..7e528ab3b2 100644
--- a/api/task_check_run.go
+++ b/api/task_check_run.go
@@ -198,7 +198,6 @@ type TaskCheckRunService interface {
FindTaskCheckRunList(ctx context.Context, find *TaskCheckRunFind) ([]*TaskCheckRun, error)
FindTaskCheckRunListTx(ctx context.Context, tx *sql.Tx, find *TaskCheckRunFind) ([]*TaskCheckRun, error)
PgFindTaskCheckRunListTx(ctx context.Context, tx *sql.Tx, find *TaskCheckRunFind) ([]*TaskCheckRun, error)
- FindTaskCheckRunTx(ctx context.Context, tx *sql.Tx, find *TaskCheckRunFind) (*TaskCheckRun, error)
PatchTaskCheckRunStatus(ctx context.Context, patch *TaskCheckRunStatusPatch) (*TaskCheckRun, error)
PatchTaskCheckRunStatusTx(ctx context.Context, tx *sql.Tx, patch *TaskCheckRunStatusPatch) (*TaskCheckRun, error)
}
diff --git a/resources/resources.go b/resources/resources.go
index 34f7129a2a..2a28778e83 100644
--- a/resources/resources.go
+++ b/resources/resources.go
@@ -5,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
- "log"
"os"
"os/exec"
"path"
@@ -86,8 +85,6 @@ func extractTXZ(directory string, data []byte) error {
}
targetPath := filepath.Join(directory, header.Name)
- log.Printf("Extracting path: %s\n", targetPath)
-
if err := os.MkdirAll(filepath.Dir(targetPath), os.ModePerm); err != nil {
return err
}
diff --git a/store/activity.go b/store/activity.go
index 52643d0c1b..a33e290f81 100644
--- a/store/activity.go
+++ b/store/activity.go
@@ -62,7 +62,7 @@ func (s *ActivityService) FindActivityList(ctx context.Context, find *api.Activi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findActivityList(ctx, tx, find)
+ list, err := findActivityList(ctx, tx.PTx, find)
if err != nil {
return []*api.Activity{}, err
}
@@ -80,7 +80,7 @@ func (s *ActivityService) FindActivity(ctx context.Context, find *api.ActivityFi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findActivityList(ctx, tx, find)
+ list, err := findActivityList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -247,20 +247,20 @@ func pgCreateActivity(ctx context.Context, tx *sql.Tx, create *api.ActivityCreat
return &activity, nil
}
-func findActivityList(ctx context.Context, tx *Tx, find *api.ActivityFind) (_ []*api.Activity, err error) {
+func findActivityList(ctx context.Context, tx *sql.Tx, find *api.ActivityFind) (_ []*api.Activity, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.ContainerID; v != nil {
- where, args = append(where, "container_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("container_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.CreatorID; v != nil {
- where, args = append(where, "creator_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("creator_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Type; v != nil {
- where, args = append(where, "type = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("type = $%d", len(args)+1)), append(args, *v)
}
var query = `
@@ -281,7 +281,7 @@ func findActivityList(ctx context.Context, tx *Tx, find *api.ActivityFind) (_ []
query += fmt.Sprintf(" ORDER BY updated_ts DESC LIMIT %d", *v)
}
- rows, err := tx.Tx.QueryContext(ctx, query,
+ rows, err := tx.QueryContext(ctx, query,
args...,
)
if err != nil {
diff --git a/store/anomaly.go b/store/anomaly.go
index cabbed4530..97c39c1d1c 100644
--- a/store/anomaly.go
+++ b/store/anomaly.go
@@ -44,7 +44,7 @@ func (s *AnomalyService) UpsertActiveAnomaly(ctx context.Context, upsert *api.An
DatabaseID: upsert.DatabaseID,
Type: &upsert.Type,
}
- list, err := findAnomalyList(ctx, tx, find)
+ list, err := findAnomalyList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -95,7 +95,7 @@ func (s *AnomalyService) FindAnomalyList(ctx context.Context, find *api.AnomalyF
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findAnomalyList(ctx, tx, find)
+ list, err := findAnomalyList(ctx, tx.PTx, find)
if err != nil {
return []*api.Anomaly{}, err
}
@@ -236,28 +236,28 @@ func pgCreateAnomaly(ctx context.Context, tx *sql.Tx, upsert *api.AnomalyUpsert)
return nil, err
}
-func findAnomalyList(ctx context.Context, tx *Tx, find *api.AnomalyFind) (_ []*api.Anomaly, err error) {
+func findAnomalyList(ctx context.Context, tx *sql.Tx, find *api.AnomalyFind) (_ []*api.Anomaly, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.InstanceID; v != nil {
- where, args = append(where, "instance_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("instance_id = $%d", len(args)+1)), append(args, *v)
if find.InstanceOnly {
where = append(where, "database_id is NULL")
}
}
if find.InstanceID == nil || !find.InstanceOnly {
if v := find.DatabaseID; v != nil {
- where, args = append(where, "database_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("database_id = $%d", len(args)+1)), append(args, *v)
}
}
if v := find.RowStatus; v != nil {
- where, args = append(where, "row_status = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("row_status = $%d", len(args)+1)), append(args, *v)
}
if v := find.Type; v != nil {
- where, args = append(where, "type = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("type = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,
diff --git a/store/backup.go b/store/backup.go
index 204ce09c9a..660b023fb9 100644
--- a/store/backup.go
+++ b/store/backup.go
@@ -64,7 +64,7 @@ func (s *BackupService) FindBackup(ctx context.Context, find *api.BackupFind) (*
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findBackupList(ctx, tx, find)
+ list, err := s.findBackupList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -86,7 +86,7 @@ func (s *BackupService) FindBackupList(ctx context.Context, find *api.BackupFind
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findBackupList(ctx, tx, find)
+ list, err := s.findBackupList(ctx, tx.PTx, find)
if err != nil {
return []*api.Backup{}, err
}
@@ -234,23 +234,23 @@ func (s *BackupService) pgCreateBackup(ctx context.Context, tx *sql.Tx, create *
return &backup, nil
}
-func (s *BackupService) findBackupList(ctx context.Context, tx *Tx, find *api.BackupFind) (_ []*api.Backup, err error) {
+func (s *BackupService) findBackupList(ctx context.Context, tx *sql.Tx, find *api.BackupFind) (_ []*api.Backup, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.DatabaseID; v != nil {
- where, args = append(where, "database_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("database_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Name; v != nil {
- where, args = append(where, "name = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
if v := find.Status; v != nil {
- where, args = append(where, "status = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("status = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,
diff --git a/store/bookmark.go b/store/bookmark.go
index cf38be9b2d..6cef4e868f 100644
--- a/store/bookmark.go
+++ b/store/bookmark.go
@@ -62,7 +62,7 @@ func (s *BookmarkService) FindBookmarkList(ctx context.Context, find *api.Bookma
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findBookmarkList(ctx, tx, find)
+ list, err := findBookmarkList(ctx, tx.PTx, find)
if err != nil {
return []*api.Bookmark{}, err
}
@@ -80,7 +80,7 @@ func (s *BookmarkService) FindBookmark(ctx context.Context, find *api.BookmarkFi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findBookmarkList(ctx, tx, find)
+ list, err := findBookmarkList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -202,25 +202,25 @@ func pgCreateBookmark(ctx context.Context, tx *sql.Tx, create *api.BookmarkCreat
return &bookmark, nil
}
-func findBookmarkList(ctx context.Context, tx *Tx, find *api.BookmarkFind) (_ []*api.Bookmark, err error) {
+func findBookmarkList(ctx context.Context, tx *sql.Tx, find *api.BookmarkFind) (_ []*api.Bookmark, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.CreatorID; v != nil {
- where, args = append(where, "creator_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("creator_id = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- name,
- link
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ link
FROM bookmark
WHERE `+strings.Join(where, " AND "),
args...,
diff --git a/store/column.go b/store/column.go
index ea9ca4c50d..f74bd6502a 100644
--- a/store/column.go
+++ b/store/column.go
@@ -62,7 +62,7 @@ func (s *ColumnService) FindColumnList(ctx context.Context, find *api.ColumnFind
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findColumnList(ctx, tx, find)
+ list, err := s.findColumnList(ctx, tx.PTx, find)
if err != nil {
return []*api.Column{}, err
}
@@ -80,7 +80,7 @@ func (s *ColumnService) FindColumn(ctx context.Context, find *api.ColumnFind) (*
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findColumnList(ctx, tx, find)
+ list, err := s.findColumnList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -275,23 +275,23 @@ func (s *ColumnService) pgCreateColumn(ctx context.Context, tx *sql.Tx, create *
return &column, nil
}
-func (s *ColumnService) findColumnList(ctx context.Context, tx *Tx, find *api.ColumnFind) (_ []*api.Column, err error) {
+func (s *ColumnService) findColumnList(ctx context.Context, tx *sql.Tx, find *api.ColumnFind) (_ []*api.Column, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.DatabaseID; v != nil {
- where, args = append(where, "database_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("database_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.TableID; v != nil {
- where, args = append(where, "table_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("table_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Name; v != nil {
- where, args = append(where, "name = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,
@@ -302,11 +302,11 @@ func (s *ColumnService) findColumnList(ctx context.Context, tx *Tx, find *api.Co
table_id,
name,
position,
- `+"`default`,"+`
+ "default",
nullable,
type,
character_set,
- collation,
+ "collation",
comment
FROM col
WHERE `+strings.Join(where, " AND ")+`
diff --git a/store/data_source.go b/store/data_source.go
index 28b085c44a..98589c18b2 100644
--- a/store/data_source.go
+++ b/store/data_source.go
@@ -72,7 +72,7 @@ func (s *DataSourceService) FindDataSourceList(ctx context.Context, find *api.Da
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findDataSourceList(ctx, tx, find)
+ list, err := s.findDataSourceList(ctx, tx.PTx, find)
if err != nil {
return []*api.DataSource{}, err
}
@@ -90,7 +90,7 @@ func (s *DataSourceService) FindDataSource(ctx context.Context, find *api.DataSo
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findDataSourceList(ctx, tx, find)
+ list, err := s.findDataSourceList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -237,30 +237,30 @@ func (s *DataSourceService) pgCreateDataSource(ctx context.Context, tx *sql.Tx,
return &dataSource, nil
}
-func (s *DataSourceService) findDataSourceList(ctx context.Context, tx *Tx, find *api.DataSourceFind) (_ []*api.DataSource, err error) {
+func (s *DataSourceService) findDataSourceList(ctx context.Context, tx *sql.Tx, find *api.DataSourceFind) (_ []*api.DataSource, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.InstanceID; v != nil {
- where, args = append(where, "instance_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("instance_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.DatabaseID; v != nil {
- where, args = append(where, "`database_id` = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("database_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Type; v != nil {
- where, args = append(where, "type = ?"), append(args, api.DataSourceType(*v))
+ where, args = append(where, fmt.Sprintf("type = $%d", len(args)+1)), append(args, api.DataSourceType(*v))
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
instance_id,
database_id,
- name,
- type,
+ name,
+ type,
username,
password
FROM data_source
diff --git a/store/database.go b/store/database.go
index 9d214e4605..3a7f3e6dc8 100644
--- a/store/database.go
+++ b/store/database.go
@@ -151,7 +151,7 @@ func (s *DatabaseService) FindDatabaseList(ctx context.Context, find *api.Databa
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findDatabaseList(ctx, tx, find)
+ list, err := s.findDatabaseList(ctx, tx.PTx, find)
if err != nil {
return []*api.Database{}, err
}
@@ -188,7 +188,7 @@ func (s *DatabaseService) FindDatabase(ctx context.Context, find *api.DatabaseFi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findDatabaseList(ctx, tx, find)
+ list, err := s.findDatabaseList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -377,26 +377,26 @@ func (s *DatabaseService) pgCreateDatabase(ctx context.Context, tx *sql.Tx, crea
return &database, nil
}
-func (s *DatabaseService) findDatabaseList(ctx context.Context, tx *Tx, find *api.DatabaseFind) (_ []*api.Database, err error) {
+func (s *DatabaseService) findDatabaseList(ctx context.Context, tx *sql.Tx, find *api.DatabaseFind) (_ []*api.Database, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.InstanceID; v != nil {
- where, args = append(where, "instance_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("instance_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.ProjectID; v != nil {
- where, args = append(where, "project_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("project_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Name; v != nil {
- where, args = append(where, "name = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
if !find.IncludeAllDatabase {
where = append(where, "name != '"+api.AllDatabaseName+"'")
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,
@@ -408,7 +408,7 @@ func (s *DatabaseService) findDatabaseList(ctx context.Context, tx *Tx, find *ap
source_backup_id,
name,
character_set,
- collation,
+ "collation",
sync_status,
last_successful_sync_ts,
schema_version
diff --git a/store/deploy.go b/store/deploy.go
index 8ee71b7416..a34749b543 100644
--- a/store/deploy.go
+++ b/store/deploy.go
@@ -38,13 +38,13 @@ func (s *DeploymentConfigService) FindDeploymentConfig(ctx context.Context, find
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.ProjectID; v != nil {
- where, args = append(where, "project_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("project_id = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.PTx.QueryContext(ctx, `
SELECT
id,
creator_id,
@@ -52,7 +52,7 @@ func (s *DeploymentConfigService) FindDeploymentConfig(ctx context.Context, find
updater_id,
updated_ts,
project_id,
- name,
+ name,
config
FROM deployment_config
WHERE `+strings.Join(where, " AND "),
diff --git a/store/environment.go b/store/environment.go
index 47ad03eb70..77005a495c 100644
--- a/store/environment.go
+++ b/store/environment.go
@@ -68,7 +68,7 @@ func (s *EnvironmentService) FindEnvironmentList(ctx context.Context, find *api.
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findEnvironmentList(ctx, tx, find)
+ list, err := s.findEnvironmentList(ctx, tx.PTx, find)
if err != nil {
return []*api.Environment{}, err
}
@@ -105,7 +105,7 @@ func (s *EnvironmentService) FindEnvironment(ctx context.Context, find *api.Envi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findEnvironmentList(ctx, tx, find)
+ list, err := s.findEnvironmentList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -284,26 +284,26 @@ func (s *EnvironmentService) pgCreateEnvironment(ctx context.Context, tx *sql.Tx
return &environment, nil
}
-func (s *EnvironmentService) findEnvironmentList(ctx context.Context, tx *Tx, find *api.EnvironmentFind) (_ []*api.Environment, err error) {
+func (s *EnvironmentService) findEnvironmentList(ctx context.Context, tx *sql.Tx, find *api.EnvironmentFind) (_ []*api.Environment, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.RowStatus; v != nil {
- where, args = append(where, "row_status = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("row_status = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
+ id,
row_status,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- name,
- `+"`order`"+`
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ "order"
FROM environment
WHERE `+strings.Join(where, " AND "),
args...,
diff --git a/store/inbox.go b/store/inbox.go
index db435896ca..13457b8bdc 100644
--- a/store/inbox.go
+++ b/store/inbox.go
@@ -64,7 +64,7 @@ func (s *InboxService) FindInboxList(ctx context.Context, find *api.InboxFind) (
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findInboxList(ctx, tx, find)
+ list, err := findInboxList(ctx, tx.PTx, find)
if err != nil {
return []*api.Inbox{}, err
}
@@ -82,7 +82,7 @@ func (s *InboxService) FindInbox(ctx context.Context, find *api.InboxFind) (*api
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findInboxList(ctx, tx, find)
+ list, err := findInboxList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -132,16 +132,14 @@ func (s *InboxService) FindInboxSummary(ctx context.Context, principalID int) (*
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- row, err := tx.Tx.QueryContext(ctx, `
- SELECT EXISTS (SELECT 1 FROM inbox WHERE receiver_id = ? AND status = 'UNREAD')
+ row, err := tx.PTx.QueryContext(ctx, `
+ SELECT EXISTS (SELECT 1 FROM inbox WHERE receiver_id = $1 AND status = 'UNREAD')
`,
principalID,
)
-
if err != nil {
return nil, FormatError(err)
}
- defer row.Close()
row.Next()
var inboxSummary api.InboxSummary
@@ -150,10 +148,13 @@ func (s *InboxService) FindInboxSummary(ctx context.Context, principalID int) (*
); err != nil {
return nil, FormatError(err)
}
+ if err := row.Close(); err != nil {
+ return nil, FormatError(err)
+ }
if inboxSummary.HasUnread {
row2, err := tx.Tx.QueryContext(ctx, `
- SELECT EXISTS (SELECT 1 FROM inbox, activity WHERE inbox.receiver_id = ? AND inbox.status = 'UNREAD' AND inbox.activity_id = activity.id AND activity.level = 'ERROR')
+ SELECT EXISTS (SELECT 1 FROM inbox, activity WHERE inbox.receiver_id = $1 AND inbox.status = 'UNREAD' AND inbox.activity_id = activity.id AND activity.level = 'ERROR')
`,
principalID,
)
@@ -264,21 +265,21 @@ func (s *InboxService) pgCreateInbox(ctx context.Context, tx *sql.Tx, create *ap
return &inbox, nil
}
-func findInboxList(ctx context.Context, tx *Tx, find *api.InboxFind) (_ []*api.Inbox, err error) {
+func findInboxList(ctx context.Context, tx *sql.Tx, find *api.InboxFind) (_ []*api.Inbox, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
where = append(where, "inbox.activity_id = activity.id")
if v := find.ID; v != nil {
- where, args = append(where, "inbox.id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("inbox.id = $%d", len(args)+1)), append(args, *v)
}
if v := find.ReceiverID; v != nil {
- where, args = append(where, "receiver_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("receiver_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.ReadCreatedAfterTs; v != nil {
- where, args = append(where, "(status != 'READ' OR created_ts >= ?)"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("(status != 'READ' OR created_ts >= $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
inbox.id,
receiver_id,
@@ -392,7 +393,7 @@ func (s *InboxService) pgPatchInbox(ctx context.Context, tx *sql.Tx, patch *api.
UPDATE inbox
SET `+strings.Join(set, ", ")+`
WHERE id = $2
- RETURNING id, receiver_id, activity_id, `+"status"+`
+ RETURNING id, receiver_id, activity_id, status
`,
args...,
)
diff --git a/store/instance.go b/store/instance.go
index cec11e0a6c..b2d847d4d2 100644
--- a/store/instance.go
+++ b/store/instance.go
@@ -106,7 +106,7 @@ func (s *InstanceService) FindInstanceList(ctx context.Context, find *api.Instan
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findInstanceList(ctx, tx, find)
+ list, err := findInstanceList(ctx, tx.PTx, find)
if err != nil {
return []*api.Instance{}, err
}
@@ -133,7 +133,7 @@ func (s *InstanceService) CountInstance(ctx context.Context, find *api.InstanceF
where, args := findInstanceQuery(find)
- row, err := tx.Tx.QueryContext(ctx, `
+ row, err := tx.PTx.QueryContext(ctx, `
SELECT COUNT(*)
FROM instance
WHERE `+where,
@@ -175,7 +175,7 @@ func (s *InstanceService) FindInstance(ctx context.Context, find *api.InstanceFi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findInstanceList(ctx, tx, find)
+ list, err := findInstanceList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -333,17 +333,17 @@ func pgCreateInstance(ctx context.Context, tx *sql.Tx, create *api.InstanceCreat
return &instance, nil
}
-func findInstanceList(ctx context.Context, tx *Tx, find *api.InstanceFind) (_ []*api.Instance, err error) {
+func findInstanceList(ctx context.Context, tx *sql.Tx, find *api.InstanceFind) (_ []*api.Instance, err error) {
where, args := findInstanceQuery(find)
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
+ id,
row_status,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
environment_id,
name,
engine,
@@ -525,10 +525,10 @@ func findInstanceQuery(find *api.InstanceFind) (string, []interface{}) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.RowStatus; v != nil {
- where, args = append(where, "row_status = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("row_status = $%d", len(args)+1)), append(args, *v)
}
return strings.Join(where, " AND "), args
diff --git a/store/instance_user.go b/store/instance_user.go
index 8af16675ec..75fd6facf5 100644
--- a/store/instance_user.go
+++ b/store/instance_user.go
@@ -60,7 +60,7 @@ func (s *InstanceUserService) FindInstanceUserList(ctx context.Context, find *ap
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findInstanceUserList(ctx, tx, find)
+ list, err := findInstanceUserList(ctx, tx.PTx, find)
if err != nil {
return []*api.InstanceUser{}, err
}
@@ -180,17 +180,17 @@ func pgUpsertInstanceUser(ctx context.Context, tx *sql.Tx, upsert *api.InstanceU
return nil, err
}
-func findInstanceUserList(ctx context.Context, tx *Tx, find *api.InstanceUserFind) (_ []*api.InstanceUser, err error) {
+func findInstanceUserList(ctx context.Context, tx *sql.Tx, find *api.InstanceUserFind) (_ []*api.InstanceUser, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
- where, args = append(where, "instance_id = ?"), append(args, find.InstanceID)
+ where, args = append(where, "instance_id = $1"), append(args, find.InstanceID)
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
instance_id,
name,
- grant
+ "grant"
FROM instance_user
WHERE `+strings.Join(where, " AND ")+`
ORDER BY name ASC
diff --git a/store/issue.go b/store/issue.go
index 9a8122e5eb..b36e8a8faa 100644
--- a/store/issue.go
+++ b/store/issue.go
@@ -69,7 +69,7 @@ func (s *IssueService) FindIssueList(ctx context.Context, find *api.IssueFind) (
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findIssueList(ctx, tx, find)
+ list, err := s.findIssueList(ctx, tx.PTx, find)
if err != nil {
return []*api.Issue{}, err
}
@@ -95,7 +95,7 @@ func (s *IssueService) FindIssue(ctx context.Context, find *api.IssueFind) (*api
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findIssueList(ctx, tx, find)
+ list, err := s.findIssueList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -257,20 +257,20 @@ func (s *IssueService) pgCreateIssue(ctx context.Context, tx *sql.Tx, create *ap
return &issue, nil
}
-func (s *IssueService) findIssueList(ctx context.Context, tx *Tx, find *api.IssueFind) (_ []*api.Issue, err error) {
+func (s *IssueService) findIssueList(ctx context.Context, tx *sql.Tx, find *api.IssueFind) (_ []*api.Issue, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.PipelineID; v != nil {
- where, args = append(where, "pipeline_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("pipeline_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.ProjectID; v != nil {
- where, args = append(where, "project_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("project_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.PrincipalID; v != nil {
- where = append(where, "(creator_id = ? OR assignee_id = ? OR EXISTS (SELECT 1 FROM issue_subscriber WHERE issue_id = issue.id AND subscriber_id = ?))")
+ where = append(where, fmt.Sprintf("(creator_id = $%d OR assignee_id = $%d OR EXISTS (SELECT 1 FROM issue_subscriber WHERE issue_id = issue.id AND subscriber_id = $%d))", len(args)+1, len(args)+2, len(args)+3))
args = append(args, *v)
args = append(args, *v)
args = append(args, *v)
@@ -278,7 +278,7 @@ func (s *IssueService) findIssueList(ctx context.Context, tx *Tx, find *api.Issu
if v := find.StatusList; v != nil {
list := []string{}
for _, status := range *v {
- list = append(list, "?")
+ list = append(list, fmt.Sprintf("$%d", len(args)+1))
args = append(args, status)
}
where = append(where, fmt.Sprintf("status in (%s)", strings.Join(list, ",")))
@@ -286,14 +286,14 @@ func (s *IssueService) findIssueList(ctx context.Context, tx *Tx, find *api.Issu
var query = `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
project_id,
pipeline_id,
- name,
+ name,
status,
type,
description,
@@ -305,7 +305,7 @@ func (s *IssueService) findIssueList(ctx context.Context, tx *Tx, find *api.Issu
query += fmt.Sprintf(" ORDER BY updated_ts DESC LIMIT %d", *v)
}
- rows, err := tx.Tx.QueryContext(ctx, query, args...)
+ rows, err := tx.QueryContext(ctx, query, args...)
if err != nil {
return nil, FormatError(err)
}
diff --git a/store/issue_subscriber.go b/store/issue_subscriber.go
index 24db080c71..6423fe5c13 100644
--- a/store/issue_subscriber.go
+++ b/store/issue_subscriber.go
@@ -3,6 +3,7 @@ package store
import (
"context"
"database/sql"
+ "fmt"
"strings"
"github.com/bytebase/bytebase/api"
@@ -60,7 +61,7 @@ func (s *IssueSubscriberService) FindIssueSubscriberList(ctx context.Context, fi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findIssueSubscriberList(ctx, tx, find)
+ list, err := findIssueSubscriberList(ctx, tx.PTx, find)
if err != nil {
return []*api.IssueSubscriber{}, err
}
@@ -158,17 +159,17 @@ func pgCreateIssueSubscriber(ctx context.Context, tx *sql.Tx, create *api.IssueS
return &issueSubscriber, nil
}
-func findIssueSubscriberList(ctx context.Context, tx *Tx, find *api.IssueSubscriberFind) (_ []*api.IssueSubscriber, err error) {
+func findIssueSubscriberList(ctx context.Context, tx *sql.Tx, find *api.IssueSubscriberFind) (_ []*api.IssueSubscriber, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.IssueID; v != nil {
- where, args = append(where, "issue_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("issue_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.SubscriberID; v != nil {
- where, args = append(where, "subscriber_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("subscriber_id = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
issue_id,
subscriber_id
diff --git a/store/label.go b/store/label.go
index 0e2d9d054f..5ed05df8a9 100644
--- a/store/label.go
+++ b/store/label.go
@@ -35,7 +35,7 @@ func (s *LabelService) FindLabelKeyList(ctx context.Context, find *api.LabelKeyF
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- ret, err := s.findLabelKeyList(ctx, tx, find)
+ ret, err := s.findLabelKeyList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -50,20 +50,20 @@ func (s *LabelService) FindLabelKeyList(ctx context.Context, find *api.LabelKeyF
return ret, nil
}
-func (s *LabelService) findLabelKeyList(ctx context.Context, tx *Tx, find *api.LabelKeyFind) ([]*api.LabelKey, error) {
+func (s *LabelService) findLabelKeyList(ctx context.Context, tx *sql.Tx, find *api.LabelKeyFind) ([]*api.LabelKey, error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.RowStatus; v != nil {
- where, args = append(where, "row_status = ?"), append(args, *v)
+ where, args = append(where, "row_status = $1"), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,
created_ts,
updater_id,
updated_ts,
- key
+ key
FROM label_key
WHERE `+strings.Join(where, " AND "),
args...,
@@ -71,8 +71,6 @@ func (s *LabelService) findLabelKeyList(ctx context.Context, tx *Tx, find *api.L
if err != nil {
return nil, FormatError(err)
}
- defer rows.Close()
-
// Iterate over result set and deserialize rows into list.
var ret []*api.LabelKey
keymap := make(map[string]*api.LabelKey)
@@ -95,9 +93,12 @@ func (s *LabelService) findLabelKeyList(ctx context.Context, tx *Tx, find *api.L
if err := rows.Err(); err != nil {
return nil, FormatError(err)
}
+ if err := rows.Close(); err != nil {
+ return nil, FormatError(err)
+ }
// Find key values.
- valueRows, err := tx.Tx.QueryContext(ctx, `
+ valueRows, err := tx.QueryContext(ctx, `
SELECT
key,
value
@@ -147,7 +148,7 @@ func (s *LabelService) PatchLabelKey(ctx context.Context, patch *api.LabelKeyPat
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- ret, err := s.findLabelKeyList(ctx, tx, &api.LabelKeyFind{})
+ ret, err := s.findLabelKeyList(ctx, tx.PTx, &api.LabelKeyFind{})
if err != nil {
return nil, err
}
@@ -271,7 +272,7 @@ func (s *LabelService) FindDatabaseLabelList(ctx context.Context, find *api.Data
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- databaseLabelList, err := s.findDatabaseLabels(ctx, tx, find)
+ databaseLabelList, err := s.findDatabaseLabels(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -286,19 +287,19 @@ func (s *LabelService) FindDatabaseLabelList(ctx context.Context, find *api.Data
return databaseLabelList, nil
}
-func (s *LabelService) findDatabaseLabels(ctx context.Context, tx *Tx, find *api.DatabaseLabelFind) ([]*api.DatabaseLabel, error) {
+func (s *LabelService) findDatabaseLabels(ctx context.Context, tx *sql.Tx, find *api.DatabaseLabelFind) ([]*api.DatabaseLabel, error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.RowStatus; v != nil {
- where, args = append(where, "row_status = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("row_status = $%d", len(args)+1)), append(args, *v)
}
if v := find.DatabaseID; v != nil {
- where, args = append(where, "database_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("database_id = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
row_status,
@@ -307,7 +308,7 @@ func (s *LabelService) findDatabaseLabels(ctx context.Context, tx *Tx, find *api
updater_id,
updated_ts,
database_id,
- key,
+ key,
value
FROM db_label
WHERE `+strings.Join(where, " AND ")+` ORDER BY key`,
diff --git a/store/member.go b/store/member.go
index f9ca8216f1..c14d24b67b 100644
--- a/store/member.go
+++ b/store/member.go
@@ -68,7 +68,7 @@ func (s *MemberService) FindMemberList(ctx context.Context, find *api.MemberFind
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findMemberList(ctx, tx, find)
+ list, err := findMemberList(ctx, tx.PTx, find)
if err != nil {
return []*api.Member{}, err
}
@@ -105,7 +105,7 @@ func (s *MemberService) FindMember(ctx context.Context, find *api.MemberFind) (*
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findMemberList(ctx, tx, find)
+ list, err := findMemberList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -243,30 +243,30 @@ func pgCreateMember(ctx context.Context, tx *sql.Tx, create *api.MemberCreate) (
return &member, nil
}
-func findMemberList(ctx context.Context, tx *Tx, find *api.MemberFind) (_ []*api.Member, err error) {
+func findMemberList(ctx context.Context, tx *sql.Tx, find *api.MemberFind) (_ []*api.Member, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.PrincipalID; v != nil {
- where, args = append(where, "principal_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("principal_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Role; v != nil {
- where, args = append(where, "role = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("role = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
+ id,
row_status,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
status,
- role,
- principal_id
+ role,
+ principal_id
FROM member
WHERE `+strings.Join(where, " AND "),
args...,
diff --git a/store/pipeline.go b/store/pipeline.go
index 77499e3fe9..cab6bd5151 100644
--- a/store/pipeline.go
+++ b/store/pipeline.go
@@ -68,7 +68,7 @@ func (s *PipelineService) FindPipelineList(ctx context.Context, find *api.Pipeli
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findPipelineList(ctx, tx, find)
+ list, err := s.findPipelineList(ctx, tx.PTx, find)
if err != nil {
return []*api.Pipeline{}, err
}
@@ -105,7 +105,7 @@ func (s *PipelineService) FindPipeline(ctx context.Context, find *api.PipelineFi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findPipelineList(ctx, tx, find)
+ list, err := s.findPipelineList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -231,25 +231,25 @@ func (s *PipelineService) pgCreatePipeline(ctx context.Context, tx *sql.Tx, crea
return &pipeline, nil
}
-func (s *PipelineService) findPipelineList(ctx context.Context, tx *Tx, find *api.PipelineFind) (_ []*api.Pipeline, err error) {
+func (s *PipelineService) findPipelineList(ctx context.Context, tx *sql.Tx, find *api.PipelineFind) (_ []*api.Pipeline, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Status; v != nil {
- where, args = append(where, "status = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("status = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- name,
- status
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ name,
+ status
FROM pipeline
WHERE `+strings.Join(where, " AND "),
args...,
diff --git a/store/policy.go b/store/policy.go
index 0efd9c6ded..86cfe49953 100644
--- a/store/policy.go
+++ b/store/policy.go
@@ -44,7 +44,7 @@ func (s *PolicyService) FindPolicy(ctx context.Context, find *api.PolicyFind) (*
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findPolicy(ctx, tx, find)
+ list, err := s.findPolicy(ctx, tx.PTx, find)
var ret *api.Policy
if err != nil {
return nil, err
@@ -74,20 +74,20 @@ func (s *PolicyService) FindPolicy(ctx context.Context, find *api.PolicyFind) (*
return ret, nil
}
-func (s *PolicyService) findPolicy(ctx context.Context, tx *Tx, find *api.PolicyFind) (_ []*api.Policy, err error) {
+func (s *PolicyService) findPolicy(ctx context.Context, tx *sql.Tx, find *api.PolicyFind) (_ []*api.Policy, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.EnvironmentID; v != nil {
- where, args = append(where, "environment_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("environment_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Type; v != nil {
- where, args = append(where, "type = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("type = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,
diff --git a/store/principal.go b/store/principal.go
index 35ae31dd55..d6608a4844 100644
--- a/store/principal.go
+++ b/store/principal.go
@@ -68,7 +68,7 @@ func (s *PrincipalService) FindPrincipalList(ctx context.Context) ([]*api.Princi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findPrincipalList(ctx, tx, &api.PrincipalFind{})
+ list, err := findPrincipalList(ctx, tx.PTx, &api.PrincipalFind{})
if err != nil {
return []*api.Principal{}, err
}
@@ -105,7 +105,7 @@ func (s *PrincipalService) FindPrincipal(ctx context.Context, find *api.Principa
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findPrincipalList(ctx, tx, find)
+ list, err := findPrincipalList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -248,26 +248,26 @@ func pgCreatePrincipal(ctx context.Context, tx *sql.Tx, create *api.PrincipalCre
return &principal, nil
}
-func findPrincipalList(ctx context.Context, tx *Tx, find *api.PrincipalFind) (_ []*api.Principal, err error) {
+func findPrincipalList(ctx context.Context, tx *sql.Tx, find *api.PrincipalFind) (_ []*api.Principal, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Email; v != nil {
- where, args = append(where, "email = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("email = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
- type,
- name,
- email,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
+ type,
+ name,
+ email,
password_hash
FROM principal
WHERE `+strings.Join(where, " AND "),
diff --git a/store/project.go b/store/project.go
index d3cf9dd47b..74ae669b93 100644
--- a/store/project.go
+++ b/store/project.go
@@ -68,7 +68,7 @@ func (s *ProjectService) FindProjectList(ctx context.Context, find *api.ProjectF
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findProjectList(ctx, tx, find)
+ list, err := findProjectList(ctx, tx.PTx, find)
if err != nil {
return []*api.Project{}, err
}
@@ -105,7 +105,7 @@ func (s *ProjectService) FindProject(ctx context.Context, find *api.ProjectFind)
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findProjectList(ctx, tx, find)
+ list, err := findProjectList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -289,27 +289,27 @@ func pgCreateProject(ctx context.Context, tx *sql.Tx, create *api.ProjectCreate)
return &project, nil
}
-func findProjectList(ctx context.Context, tx *Tx, find *api.ProjectFind) (_ []*api.Project, err error) {
+func findProjectList(ctx context.Context, tx *sql.Tx, find *api.ProjectFind) (_ []*api.Project, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.RowStatus; v != nil {
- where, args = append(where, "row_status = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("row_status = $%d", len(args)+1)), append(args, *v)
}
if v := find.PrincipalID; v != nil {
- where, args = append(where, "id IN (SELECT project_id FROM project_member WHERE principal_id = ?)"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id IN (SELECT project_id FROM project_member WHERE principal_id = $%d)", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
+ id,
row_status,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
name,
key,
workflow_type,
diff --git a/store/project_member.go b/store/project_member.go
index f146094cd4..5be8b953eb 100644
--- a/store/project_member.go
+++ b/store/project_member.go
@@ -62,7 +62,7 @@ func (s *ProjectMemberService) FindProjectMemberList(ctx context.Context, find *
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findProjectMemberList(ctx, tx, find)
+ list, err := findProjectMemberList(ctx, tx.PTx, find)
if err != nil {
return []*api.ProjectMember{}, err
}
@@ -79,7 +79,7 @@ func (s *ProjectMemberService) FindProjectMember(ctx context.Context, find *api.
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findProjectMemberList(ctx, tx, find)
+ list, err := findProjectMemberList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -234,26 +234,26 @@ func pgCreateProjectMember(ctx context.Context, tx *sql.Tx, create *api.ProjectM
return &projectMember, nil
}
-func findProjectMemberList(ctx context.Context, tx *Tx, find *api.ProjectMemberFind) (_ []*api.ProjectMember, err error) {
+func findProjectMemberList(ctx context.Context, tx *sql.Tx, find *api.ProjectMemberFind) (_ []*api.ProjectMember, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.ProjectID; v != nil {
- where, args = append(where, "project_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("project_id = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
project_id,
- role,
- principal_id
+ role,
+ principal_id
FROM project_member
WHERE `+strings.Join(where, " AND "),
args...,
diff --git a/store/project_webhook.go b/store/project_webhook.go
index c06b6c22b1..19045c88d9 100644
--- a/store/project_webhook.go
+++ b/store/project_webhook.go
@@ -62,7 +62,7 @@ func (s *ProjectWebhookService) FindProjectWebhookList(ctx context.Context, find
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findProjectWebhookList(ctx, tx, find)
+ list, err := findProjectWebhookList(ctx, tx.PTx, find)
if err != nil {
return []*api.ProjectWebhook{}, err
}
@@ -80,7 +80,7 @@ func (s *ProjectWebhookService) FindProjectWebhook(ctx context.Context, find *ap
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findProjectWebhookList(ctx, tx, find)
+ list, err := findProjectWebhookList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -251,26 +251,26 @@ func pgCreateProjectWebhook(ctx context.Context, tx *sql.Tx, create *api.Project
return &projectWebhook, nil
}
-func findProjectWebhookList(ctx context.Context, tx *Tx, find *api.ProjectWebhookFind) (_ []*api.ProjectWebhook, err error) {
+func findProjectWebhookList(ctx context.Context, tx *sql.Tx, find *api.ProjectWebhookFind) (_ []*api.ProjectWebhook, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.ProjectID; v != nil {
- where, args = append(where, "project_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("project_id = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
project_id,
type,
- name,
+ name,
url,
activity_list
FROM project_webhook
diff --git a/store/repository.go b/store/repository.go
index c1e23db6d2..800992659d 100644
--- a/store/repository.go
+++ b/store/repository.go
@@ -64,7 +64,7 @@ func (s *RepositoryService) FindRepositoryList(ctx context.Context, find *api.Re
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findRepositoryList(ctx, tx, find)
+ list, err := findRepositoryList(ctx, tx.PTx, find)
if err != nil {
return []*api.Repository{}, err
}
@@ -82,7 +82,7 @@ func (s *RepositoryService) FindRepository(ctx context.Context, find *api.Reposi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findRepositoryList(ctx, tx, find)
+ list, err := findRepositoryList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -165,8 +165,8 @@ func (s *RepositoryService) createRepository(ctx context.Context, tx *sql.Tx, cr
// Insert row into database.
row, err := tx.QueryContext(ctx, `
INSERT INTO repository (
- creator_id,
- updater_id,
+ creator_id,
+ updater_id,
vcs_id,
project_id,
name,
@@ -262,8 +262,8 @@ func (s *RepositoryService) pgCreateRepository(ctx context.Context, tx *sql.Tx,
// Insert row into database.
row, err := tx.QueryContext(ctx, `
INSERT INTO repository (
- creator_id,
- updater_id,
+ creator_id,
+ updater_id,
vcs_id,
project_id,
name,
@@ -343,29 +343,29 @@ func (s *RepositoryService) pgCreateRepository(ctx context.Context, tx *sql.Tx,
return &repository, nil
}
-func findRepositoryList(ctx context.Context, tx *Tx, find *api.RepositoryFind) (_ []*api.Repository, err error) {
+func findRepositoryList(ctx context.Context, tx *sql.Tx, find *api.RepositoryFind) (_ []*api.Repository, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.VCSID; v != nil {
- where, args = append(where, "vcs_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("vcs_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.ProjectID; v != nil {
- where, args = append(where, "project_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("project_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.WebhookEndpointID; v != nil {
- where, args = append(where, "webhook_endpoint_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("webhook_endpoint_id = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
vcs_id,
project_id,
name,
diff --git a/store/setting.go b/store/setting.go
index 003d6bfc9f..175d13a4ae 100644
--- a/store/setting.go
+++ b/store/setting.go
@@ -75,7 +75,7 @@ func (s *SettingService) FindSettingList(ctx context.Context, find *api.SettingF
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findSettingList(ctx, tx, find)
+ list, err := findSettingList(ctx, tx.PTx, find)
if err != nil {
return []*api.Setting{}, err
}
@@ -92,7 +92,7 @@ func (s *SettingService) FindSetting(ctx context.Context, find *api.SettingFind)
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findSettingList(ctx, tx, find)
+ list, err := findSettingList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -211,21 +211,21 @@ func pgCreateSetting(ctx context.Context, tx *sql.Tx, create *api.SettingCreate)
return &setting, nil
}
-func findSettingList(ctx context.Context, tx *Tx, find *api.SettingFind) (_ []*api.Setting, err error) {
+func findSettingList(ctx context.Context, tx *sql.Tx, find *api.SettingFind) (_ []*api.Setting, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.Name; v != nil {
- where, args = append(where, "name = ?"), append(args, *v)
+ where, args = append(where, "name = $1"), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
creator_id,
created_ts,
updater_id,
updated_ts,
- name,
- value,
+ name,
+ value,
description
FROM setting
WHERE `+strings.Join(where, " AND "),
diff --git a/store/sheet.go b/store/sheet.go
index c71fe5678d..0278d68fc9 100644
--- a/store/sheet.go
+++ b/store/sheet.go
@@ -89,7 +89,7 @@ func (s *SheetService) FindSheetList(ctx context.Context, find *api.SheetFind) (
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findSheetList(ctx, tx, find)
+ list, err := findSheetList(ctx, tx.PTx, find)
if err != nil {
return []*api.Sheet{}, err
}
@@ -107,7 +107,7 @@ func (s *SheetService) FindSheet(ctx context.Context, find *api.SheetFind) (*api
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findSheetList(ctx, tx, find)
+ list, err := findSheetList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -373,38 +373,38 @@ func pgPatchSheet(ctx context.Context, tx *sql.Tx, patch *api.SheetPatch) (*api.
return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("sheet ID not found: %d", patch.ID)}
}
-func findSheetList(ctx context.Context, tx *Tx, find *api.SheetFind) (_ []*api.Sheet, err error) {
+func findSheetList(ctx context.Context, tx *sql.Tx, find *api.SheetFind) (_ []*api.Sheet, err error) {
where, args := []string{"1 = 1"}, []interface{}{}
// Standard fields
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.RowStatus; v != nil {
- where, args = append(where, "row_status = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("row_status = $%d", len(args)+1)), append(args, *v)
}
if v := find.CreatorID; v != nil {
- where, args = append(where, "creator_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("creator_id = $%d", len(args)+1)), append(args, *v)
}
// Related fields
if v := find.InstanceID; v != nil {
- where, args = append(where, "instance_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("instance_id = $%d", len(args)+1)), append(args, *v)
if find.InstanceOnly {
where = append(where, "database_id is NULL")
}
}
if find.InstanceID == nil || !find.InstanceOnly {
if v := find.DatabaseID; v != nil {
- where, args = append(where, "database_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("database_id = $%d", len(args)+1)), append(args, *v)
}
}
// Domain fields
if v := find.Visibility; v != nil {
- where, args = append(where, "visibility = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("visibility = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,
diff --git a/store/stage.go b/store/stage.go
index 7a77003f63..10b1ce6e49 100644
--- a/store/stage.go
+++ b/store/stage.go
@@ -62,7 +62,7 @@ func (s *StageService) FindStageList(ctx context.Context, find *api.StageFind) (
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findStageList(ctx, tx, find)
+ list, err := s.findStageList(ctx, tx.PTx, find)
if err != nil {
return []*api.Stage{}, err
}
@@ -80,7 +80,7 @@ func (s *StageService) FindStage(ctx context.Context, find *api.StageFind) (*api
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findStageList(ctx, tx, find)
+ list, err := s.findStageList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -179,26 +179,26 @@ func (s *StageService) pgCreateStage(ctx context.Context, tx *sql.Tx, create *ap
return &stage, nil
}
-func (s *StageService) findStageList(ctx context.Context, tx *Tx, find *api.StageFind) (_ []*api.Stage, err error) {
+func (s *StageService) findStageList(ctx context.Context, tx *sql.Tx, find *api.StageFind) (_ []*api.Stage, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.PipelineID; v != nil {
- where, args = append(where, "pipeline_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("pipeline_id = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
pipeline_id,
environment_id,
- name
+ name
FROM stage
WHERE `+strings.Join(where, " AND "),
args...,
diff --git a/store/table.go b/store/table.go
index 7260c2ea81..834d4a16bf 100644
--- a/store/table.go
+++ b/store/table.go
@@ -267,27 +267,27 @@ func (s *TableService) findTableList(ctx context.Context, tx *Tx, find *api.Tabl
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.DatabaseID; v != nil {
- where, args = append(where, "database_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("database_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Name; v != nil {
- where, args = append(where, "name = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
rows, err := tx.Tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
database_id,
- name,
+ name,
type,
engine,
- collation,
+ "collation",
row_count,
data_size,
index_size,
diff --git a/store/table_index.go b/store/table_index.go
index 83073b01fe..275d589a95 100644
--- a/store/table_index.go
+++ b/store/table_index.go
@@ -62,7 +62,7 @@ func (s *IndexService) FindIndexList(ctx context.Context, find *api.IndexFind) (
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findIndexList(ctx, tx, find)
+ list, err := s.findIndexList(ctx, tx.PTx, find)
if err != nil {
return []*api.Index{}, err
}
@@ -80,7 +80,7 @@ func (s *IndexService) FindIndex(ctx context.Context, find *api.IndexFind) (*api
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findIndexList(ctx, tx, find)
+ list, err := s.findIndexList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -217,26 +217,26 @@ func (s *IndexService) pgCreateIndex(ctx context.Context, tx *sql.Tx, create *ap
return &index, nil
}
-func (s *IndexService) findIndexList(ctx context.Context, tx *Tx, find *api.IndexFind) (_ []*api.Index, err error) {
+func (s *IndexService) findIndexList(ctx context.Context, tx *sql.Tx, find *api.IndexFind) (_ []*api.Index, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.DatabaseID; v != nil {
- where, args = append(where, "database_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("database_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.TableID; v != nil {
- where, args = append(where, "table_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("table_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Name; v != nil {
- where, args = append(where, "name = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
if v := find.Expression; v != nil {
- where, args = append(where, "expression = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("expression = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,
@@ -248,8 +248,8 @@ func (s *IndexService) findIndexList(ctx context.Context, tx *Tx, find *api.Inde
name,
expression,
position,
- `+"type,"+`
- `+"`unique`,"+`
+ type,
+ "unique",
visible,
comment
FROM idx
diff --git a/store/task.go b/store/task.go
index 068e5b186c..821b60ff5b 100644
--- a/store/task.go
+++ b/store/task.go
@@ -66,7 +66,7 @@ func (s *TaskService) FindTaskList(ctx context.Context, find *api.TaskFind) ([]*
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findTaskList(ctx, tx.Tx, find)
+ list, err := s.pgFindTaskList(ctx, tx.PTx, find)
if err != nil {
return []*api.Task{}, err
}
@@ -84,7 +84,7 @@ func (s *TaskService) FindTask(ctx context.Context, find *api.TaskFind) (*api.Ta
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- return s.findTask(ctx, tx.Tx, find)
+ return s.pgFindTask(ctx, tx.PTx, find)
}
// PatchTask updates an existing task.
@@ -398,17 +398,17 @@ func (s *TaskService) findTaskList(ctx context.Context, tx *sql.Tx, find *api.Ta
rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
pipeline_id,
stage_id,
instance_id,
database_id,
- name,
- status,
+ name,
+ status,
type,
payload,
earliest_allowed_ts
@@ -491,17 +491,17 @@ func (s *TaskService) pgFindTaskList(ctx context.Context, tx *sql.Tx, find *api.
rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
pipeline_id,
stage_id,
instance_id,
database_id,
- name,
- status,
+ name,
+ status,
type,
payload,
earliest_allowed_ts
diff --git a/store/task_check_run.go b/store/task_check_run.go
index 66ec817b39..926c1e8257 100644
--- a/store/task_check_run.go
+++ b/store/task_check_run.go
@@ -47,7 +47,7 @@ func (s *TaskCheckRunService) CreateTaskCheckRunIfNeeded(ctx context.Context, cr
StatusList: &statusList,
}
- taskCheckRunList, err := s.FindTaskCheckRunListTx(ctx, tx.Tx, taskCheckRunFind)
+ taskCheckRunList, err := s.PgFindTaskCheckRunListTx(ctx, tx.PTx, taskCheckRunFind)
if err != nil {
return nil, err
}
@@ -209,7 +209,7 @@ func (s *TaskCheckRunService) FindTaskCheckRunList(ctx context.Context, find *ap
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findTaskCheckRunList(ctx, tx.Tx, find)
+ list, err := s.pgFindTaskCheckRunList(ctx, tx.PTx, find)
if err != nil {
return []*api.TaskCheckRun{}, err
}
@@ -237,22 +237,6 @@ func (s *TaskCheckRunService) PgFindTaskCheckRunListTx(ctx context.Context, tx *
return list, nil
}
-// FindTaskCheckRunTx retrieves a single taskCheckRun based on find.
-// Returns ECONFLICT if finding more than 1 matching records.
-func (s *TaskCheckRunService) FindTaskCheckRunTx(ctx context.Context, tx *sql.Tx, find *api.TaskCheckRunFind) (*api.TaskCheckRun, error) {
- list, err := s.findTaskCheckRunList(ctx, tx, find)
- if err != nil {
- return nil, err
- }
-
- if len(list) == 0 {
- return nil, nil
- } else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d task runs with filter %+v, expect 1", len(list), find)}
- }
- return list[0], nil
-}
-
// PatchTaskCheckRunStatus updates a taskCheckRun status. Returns the new state of the taskCheckRun after update.
func (s *TaskCheckRunService) PatchTaskCheckRunStatus(ctx context.Context, patch *api.TaskCheckRunStatusPatch) (*api.TaskCheckRun, error) {
tx, err := s.db.BeginTx(ctx, nil)
@@ -414,9 +398,9 @@ func (s *TaskCheckRunService) findTaskCheckRunList(ctx context.Context, tx *sql.
SELECT
id,
creator_id,
- created_ts,
+ created_ts,
updater_id,
- updated_ts,
+ updated_ts,
task_id,
status,
type,
diff --git a/store/task_run.go b/store/task_run.go
index 839bf12874..15ff596f1f 100644
--- a/store/task_run.go
+++ b/store/task_run.go
@@ -323,9 +323,9 @@ func (s *TaskRunService) findTaskRunList(ctx context.Context, tx *sql.Tx, find *
SELECT
id,
creator_id,
- created_ts,
+ created_ts,
updater_id,
- updated_ts,
+ updated_ts,
task_id,
name,
status,
diff --git a/store/vcs.go b/store/vcs.go
index 630f3651fd..15c998df16 100644
--- a/store/vcs.go
+++ b/store/vcs.go
@@ -62,7 +62,7 @@ func (s *VCSService) FindVCSList(ctx context.Context, find *api.VCSFind) ([]*api
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findVCSList(ctx, tx, find)
+ list, err := findVCSList(ctx, tx.PTx, find)
if err != nil {
return []*api.VCS{}, err
}
@@ -80,7 +80,7 @@ func (s *VCSService) FindVCS(ctx context.Context, find *api.VCSFind) (*api.VCS,
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := findVCSList(ctx, tx, find)
+ list, err := findVCSList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -253,20 +253,20 @@ func pgCreateVCS(ctx context.Context, tx *sql.Tx, create *api.VCSCreate) (*api.V
return &vcs, nil
}
-func findVCSList(ctx context.Context, tx *Tx, find *api.VCSFind) (_ []*api.VCS, err error) {
+func findVCSList(ctx context.Context, tx *sql.Tx, find *api.VCSFind) (_ []*api.VCS, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, "id = $1"), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
- id,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
+ id,
+ creator_id,
+ created_ts,
+ updater_id,
+ updated_ts,
name,
type,
instance_url,
diff --git a/store/view.go b/store/view.go
index a9dc9a3276..f64419533a 100644
--- a/store/view.go
+++ b/store/view.go
@@ -62,7 +62,7 @@ func (s *ViewService) FindViewList(ctx context.Context, find *api.ViewFind) ([]*
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findViewList(ctx, tx, find)
+ list, err := s.findViewList(ctx, tx.PTx, find)
if err != nil {
return []*api.View{}, err
}
@@ -80,7 +80,7 @@ func (s *ViewService) FindView(ctx context.Context, find *api.ViewFind) (*api.Vi
defer tx.Tx.Rollback()
defer tx.PTx.Rollback()
- list, err := s.findViewList(ctx, tx, find)
+ list, err := s.findViewList(ctx, tx.PTx, find)
if err != nil {
return nil, err
}
@@ -221,20 +221,20 @@ func (s *ViewService) pgCreateView(ctx context.Context, tx *sql.Tx, create *api.
return &view, nil
}
-func (s *ViewService) findViewList(ctx context.Context, tx *Tx, find *api.ViewFind) (_ []*api.View, err error) {
+func (s *ViewService) findViewList(ctx context.Context, tx *sql.Tx, find *api.ViewFind) (_ []*api.View, err error) {
// Build WHERE clause.
where, args := []string{"1 = 1"}, []interface{}{}
if v := find.ID; v != nil {
- where, args = append(where, "id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("id = $%d", len(args)+1)), append(args, *v)
}
if v := find.DatabaseID; v != nil {
- where, args = append(where, "database_id = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("database_id = $%d", len(args)+1)), append(args, *v)
}
if v := find.Name; v != nil {
- where, args = append(where, "name = ?"), append(args, *v)
+ where, args = append(where, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
- rows, err := tx.Tx.QueryContext(ctx, `
+ rows, err := tx.QueryContext(ctx, `
SELECT
id,
creator_id,