MCPcopy
hub / github.com/sqldef/sqldef / isPrimaryKey

Method isPrimaryKey

schema/generator.go:3803–3818  ·  view source on GitHub ↗

isPrimaryKey checks if a column is part of the table's primary key. TODO: This function uses direct string comparison (indexColumn.ColumnName() == column.name.Name) instead of quote-aware comparison via identsEqual(). This could cause incorrect results when the column name and index column name hav

(column Column, table Table)

Source from the content-addressed store, hash-verified

3801// cause issues in offline mode where SQL is parsed directly without database normalization.
3802// Consider using g.identsEqual() or normalizeIdentKey() for correctness.
3803func (g *Generator) isPrimaryKey(column Column, table Table) bool {
3804 if column.keyOption == ColumnKeyPrimary {
3805 return true
3806 }
3807
3808 for _, index := range table.indexes {
3809 if index.primary {
3810 for _, indexColumn := range index.columns {
3811 if indexColumn.ColumnName() == column.name.Name {
3812 return true
3813 }
3814 }
3815 }
3816 }
3817 return false
3818}
3819
3820// Destructively modify table1 to have table2 columns/indexes
3821func mergeTable(table1 *Table, table2 Table) {

Callers 1

Calls 1

ColumnNameMethod · 0.80

Tested by

no test coverage detected