Skip to content

Commit

Permalink
optimize: add some todo comment, add a undo hook sample (apache#238)
Browse files Browse the repository at this point in the history
add some todo comment, add a undo hook sample
  • Loading branch information
luky116 authored Aug 23, 2022
1 parent 40133c5 commit bd18186
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 25 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/stretchr/testify v1.7.1
go.uber.org/atomic v1.9.0
go.uber.org/zap v1.21.0
golang.org/x/tools v0.1.12 // indirect
google.golang.org/genproto v0.0.0-20220630174209-ad1d48641aa7 // indirect
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.0
Expand Down
17 changes: 13 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
github.com/zouyx/agollo/v3 v3.4.5 h1:7YCxzY9ZYaH9TuVUBvmI6Tk0mwMggikah+cfbYogcHQ=
Expand Down Expand Up @@ -1271,6 +1272,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M=
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -1315,6 +1317,7 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1372,8 +1375,9 @@ golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211105192438-b53810dc28af/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand All @@ -1400,8 +1404,9 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -1495,9 +1500,12 @@ golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -1593,8 +1601,9 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
37 changes: 22 additions & 15 deletions pkg/datasource/sql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ import (
)

type Conn struct {
res *DBResource
txCtx *types.TransactionContext
conn driver.Conn
res *DBResource
txCtx *types.TransactionContext
targetConn driver.Conn
isInTransaction bool
autoCommit bool
autoCommitChanged bool
}

func (c *Conn) ResetSession(ctx context.Context) error {
conn, ok := c.conn.(driver.SessionResetter)
conn, ok := c.targetConn.(driver.SessionResetter)
if !ok {
return driver.ErrSkip
}
Expand All @@ -45,7 +48,7 @@ func (c *Conn) ResetSession(ctx context.Context) error {

// Prepare returns a prepared statement, bound to this connection.
func (c *Conn) Prepare(query string) (driver.Stmt, error) {
s, err := c.conn.Prepare(query)
s, err := c.targetConn.Prepare(query)
if err != nil {
return nil, err
}
Expand All @@ -61,9 +64,9 @@ func (c *Conn) Prepare(query string) (driver.Stmt, error) {

// PrepareContext
func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
conn, ok := c.conn.(driver.ConnPrepareContext)
conn, ok := c.targetConn.(driver.ConnPrepareContext)
if !ok {
stmt, err := c.conn.Prepare(query)
stmt, err := c.targetConn.Prepare(query)
if err != nil {
return nil, err
}
Expand All @@ -87,7 +90,7 @@ func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, e

// Exec
func (c *Conn) Exec(query string, args []driver.Value) (driver.Result, error) {
conn, ok := c.conn.(driver.Execer)
conn, ok := c.targetConn.(driver.Execer)
if !ok {
return nil, driver.ErrSkip
}
Expand Down Expand Up @@ -118,6 +121,8 @@ func (c *Conn) Exec(query string, args []driver.Value) (driver.Result, error) {
return nil, err
}

// todo if user has not opened a transaction, it may call tx.Commit() method to flush undo log

return ret.GetResult(), nil
}

Expand All @@ -126,7 +131,7 @@ func (c *Conn) Exec(query string, args []driver.Value) (driver.Result, error) {

// ExecContext
func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
conn, ok := c.conn.(driver.ExecerContext)
targetConn, ok := c.targetConn.(driver.ExecerContext)
if ok {
values := make([]driver.Value, 0, len(args))

Expand All @@ -150,7 +155,7 @@ func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.Name

ret, err := executor.ExecWithNamedValue(ctx, execCtx,
func(ctx context.Context, query string, args []driver.NamedValue) (types.ExecResult, error) {
ret, err := conn.ExecContext(ctx, query, args)
ret, err := targetConn.ExecContext(ctx, query, args)
if err != nil {
return nil, err
}
Expand All @@ -166,7 +171,7 @@ func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.Name

// QueryContext
func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error) {
conn, ok := c.conn.(driver.Queryer)
conn, ok := c.targetConn.(driver.Queryer)
if !ok {
return nil, driver.ErrSkip
}
Expand Down Expand Up @@ -200,7 +205,7 @@ func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error) {

// QueryContext
func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
conn, ok := c.conn.(driver.QueryerContext)
conn, ok := c.targetConn.(driver.QueryerContext)
if !ok {
values := make([]driver.Value, 0, len(args))

Expand Down Expand Up @@ -242,14 +247,15 @@ func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.Nam
//
// Deprecated: Drivers should implement ConnBeginTx instead (or additionally).
func (c *Conn) Begin() (driver.Tx, error) {
tx, err := c.conn.Begin()
tx, err := c.targetConn.Begin()
if err != nil {
return nil, err
}

c.txCtx = types.NewTxCtx()
c.txCtx.DBType = c.res.dbType
c.txCtx.TxOpt = driver.TxOptions{}
c.autoCommit = true

return newTx(
withDriverConn(c),
Expand All @@ -259,7 +265,7 @@ func (c *Conn) Begin() (driver.Tx, error) {
}

func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
if conn, ok := c.conn.(driver.ConnBeginTx); ok {
if conn, ok := c.targetConn.(driver.ConnBeginTx); ok {
tx, err := conn.BeginTx(ctx, opts)
if err != nil {
return nil, err
Expand All @@ -268,6 +274,7 @@ func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, e
c.txCtx = types.NewTxCtx()
c.txCtx.DBType = c.res.dbType
c.txCtx.TxOpt = opts
c.autoCommit = true

return newTx(
withDriverConn(c),
Expand Down Expand Up @@ -317,5 +324,5 @@ func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, e
// do not block indefinitely (e.g. apply a timeout).
func (c *Conn) Close() error {
c.txCtx = nil
return c.conn.Close()
return c.targetConn.Close()
}
2 changes: 1 addition & 1 deletion pkg/datasource/sql/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *seataConnector) Connect(ctx context.Context) (driver.Conn, error) {
return nil, err
}

return &Conn{conn: conn, res: c.res}, nil
return &Conn{targetConn: conn, res: c.res}, nil
}

// Driver returns the underlying Driver of the Connector,
Expand Down
2 changes: 1 addition & 1 deletion pkg/datasource/sql/datasource/base/meta_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

type (
// trigger
// trigger
trigger interface {
LoadOne(table string) (types.TableMeta, error)

Expand Down
3 changes: 2 additions & 1 deletion pkg/datasource/sql/exec/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (

var (
commonHook = make([]SQLInterceptor, 0, 4)
hookSolts = map[types.SQLType][]SQLInterceptor{}
// todo support distinguish between different db type
hookSolts = map[types.SQLType][]SQLInterceptor{}
)

// RegisCommonHook not goroutine safe
Expand Down
38 changes: 38 additions & 0 deletions pkg/datasource/sql/exec/hook/basic_undo_builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package exec

import (
"context"

"github.com/seata/seata-go/pkg/datasource/sql/exec"
"github.com/seata/seata-go/pkg/datasource/sql/types"
)

type BasicUndoBuilder struct {
}

// buildRowImages build row iamge by exec condition
func (u *BasicUndoBuilder) buildRowImages(ctx context.Context, execCtx *exec.ExecContext) ([]*types.RowImage, error) {
panic("implement me")
}

// buildRowImages query db table to find data image
func (u *BasicUndoBuilder) buildRecordImage(ctx context.Context, execCtx *exec.ExecContext) ([]*types.RecordImage, error) {
panic("implement me")
}
File renamed without changes.
55 changes: 55 additions & 0 deletions pkg/datasource/sql/exec/hook/update_undo_hook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package exec

import (
"context"

"github.com/seata/seata-go/pkg/common/log"
"github.com/seata/seata-go/pkg/datasource/sql/exec"
"github.com/seata/seata-go/pkg/datasource/sql/types"
)

// UpdateUndoHook build image when update executed
type UpdateUndoHook struct {
basicUndoBuilder BasicUndoBuilder
}

func (u UpdateUndoHook) Type() types.SQLType {
return types.SQLTypeUpdate
}

// Before build image before execute business sql
func (u UpdateUndoHook) Before(ctx context.Context, execCtx *exec.ExecContext) {
r, err := u.basicUndoBuilder.buildRecordImage(ctx, execCtx)
if err != nil {
log.Fatalf("build before iamge %v", err)
return
}
execCtx.TxCtx.RoundImages.AppendBeofreImages(r)
}

// Before build image after execute business sql
func (u UpdateUndoHook) After(ctx context.Context, execCtx *exec.ExecContext) {
r, err := u.basicUndoBuilder.buildRecordImage(ctx, execCtx)
if err != nil {
log.Fatalf("build after iamge %v", err)
return
}
execCtx.TxCtx.RoundImages.AppendAfterImages(r)
}
22 changes: 19 additions & 3 deletions pkg/datasource/sql/types/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ type RoundRecordImage struct {
after RecordImages
}

// AppendBeofreImages
func (r *RoundRecordImage) AppendBeofreImages(images []*RecordImage) {
for _, image := range images {
r.AppendBeofreImage(image)
}
}

// AppendBeofreImage
func (r *RoundRecordImage) AppendBeofreImage(image *RecordImage) {
r.bIndex++
Expand All @@ -37,6 +44,13 @@ func (r *RoundRecordImage) AppendBeofreImage(image *RecordImage) {
r.before = append(r.before, image)
}

// AppendAfterImages
func (r *RoundRecordImage) AppendAfterImages(images []*RecordImage) {
for _, image := range images {
r.AppendAfterImage(image)
}
}

// AppendAfterImage
func (r *RoundRecordImage) AppendAfterImage(image *RecordImage) {
r.aIndex++
Expand Down Expand Up @@ -76,10 +90,10 @@ func (rs RecordImages) Reserve() {
type RecordImage struct {
// index
index int32
// Table
// Table table name
Table string
// SQLType
SQLType string
// SQLType sql type
SQLType SQLType
// Rows
Rows []RowImage
}
Expand All @@ -92,6 +106,8 @@ type RowImage struct {

// ColumnImage The mirror data information of the column
type ColumnImage struct {
// KeyType index type
KeyType string
// Name column name
Name string
// Type column type
Expand Down
1 change: 1 addition & 0 deletions pkg/datasource/sql/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func NewTxCtx() *TransactionContext {
LockKeys: make([]string, 0, 4),
TransType: ATMode,
LocalTransID: uuid.New().String(),
RoundImages: &RoundRecordImage{},
}
}

Expand Down

0 comments on commit bd18186

Please sign in to comment.