Skip to content

support to check if a column is primary key #744

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

Merged
merged 7 commits into from
Nov 29, 2022
Merged
Changes from 2 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
11 changes: 11 additions & 0 deletions schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,21 @@ func (ta *Table) FindColumn(name string) int {
return -1
}

// Get TableColumn by Index index
func (ta *Table) GetPKColumn(index int) *TableColumn {
return &ta.Columns[ta.PKColumns[index]]
}

// Get Index by column index. Return nil if the column is not a index.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Get Index by column index

What if the column has multiple indexes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think this function is to get primary index only. PKColumns must be PRIMARY. I Will update.

func (ta *Table) GetIndex(colIndex int) *Index {
for i, _colIndex := range ta.PKColumns {
if _colIndex == colIndex {
return ta.Indexes[i]
}
}
return nil
}

func (ta *Table) AddIndex(name string) (index *Index) {
index = NewIndex(name)
ta.Indexes = append(ta.Indexes, index)
Expand Down