Browse Source

Implement UpdateRowOnly func

Volodymyr Tkach 2 years ago
parent
commit
595baa3b41
3 changed files with 13 additions and 0 deletions
  1. 1 0
      gosql/common/common.go
  2. 6 0
      gosql/common/dbmethods.go
  3. 6 0
      gosql/common/tx.go

+ 1 - 0
gosql/common/common.go

@@ -44,6 +44,7 @@ type Engine interface {
 	SetMaxOpenConns(n int)
 	Transaction(ctx context.Context, queries func(ctx context.Context, tx *Tx) error) error
 	UpdateRow(ctx context.Context, row any) error
+	UpdateRowOnly(ctx context.Context, row any, only ...string) error
 }
 
 var rSqlParam = regexp.MustCompile(`\$\d+`)

+ 6 - 0
gosql/common/dbmethods.go

@@ -197,3 +197,9 @@ func (d *DBMethods) UpdateRow(ctx context.Context, row any) error {
 	_, err := d.Exec(ctx, query, args...)
 	return err
 }
+
+func (d *DBMethods) UpdateRowOnly(ctx context.Context, row any, only ...string) error {
+	query, args := updateRowString(row, only...)
+	_, err := d.Exec(ctx, query, args...)
+	return err
+}

+ 6 - 0
gosql/common/tx.go

@@ -143,3 +143,9 @@ func (t *Tx) UpdateRow(ctx context.Context, row any) error {
 	_, err := t.Exec(ctx, query, args...)
 	return err
 }
+
+func (t *Tx) UpdateRowOnly(ctx context.Context, row any, only ...string) error {
+	query, args := updateRowString(row, only...)
+	_, err := t.Exec(ctx, query, args...)
+	return err
+}