Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature:build undo log by insert target SQL #333

Merged
merged 7 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/datasource/sql/types/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package types

import (
"reflect"

"github.com/pkg/errors"
Code-Fight marked this conversation as resolved.
Show resolved Hide resolved
)

// ColumnMeta
Expand Down Expand Up @@ -117,3 +119,29 @@ func (m TableMeta) GetPrimaryKeyOnlyName() []string {
}
return keys
}

func (m TableMeta) GetPrimaryKeyType() (int32, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议加上单测

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议加上注释

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

for _, index := range m.Indexs {
if index.IType == IndexTypePrimaryKey {
Code-Fight marked this conversation as resolved.
Show resolved Hide resolved
for i := range index.Columns {
return index.Columns[i].DatabaseType, nil
}
}
}
return 0, errors.New("get primary key type error")
}

func (m TableMeta) GetPrimaryKeyTypeStrMap() (map[string]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议加上单测

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

pkMap := make(map[string]string)
for _, index := range m.Indexs {
if index.IType == IndexTypePrimaryKey {
for i := range index.Columns {
pkMap[index.ColumnName] = index.Columns[i].DatabaseTypeString
}
}
}
if len(pkMap) == 0 {
return nil, errors.New("get primary key type error")
}
return pkMap, nil
}
Loading