MCPcopy
hub / github.com/sqldef/sqldef / Format

Method Format

parser/node.go:1224–1256  ·  view source on GitHub ↗

Format formats the node.

(buf *nodeBuffer)

Source from the content-addressed store, hash-verified

1222
1223// Format formats the node.
1224func (fk *ForeignKeyDefinition) Format(buf *nodeBuffer) {
1225 if !fk.ConstraintName.IsEmpty() {
1226 buf.Printf("constraint %v ", fk.ConstraintName)
1227 }
1228 buf.Printf("foreign key")
1229 if !fk.IndexName.IsEmpty() {
1230 buf.Printf(" %v", fk.IndexName)
1231 }
1232 formatFKColumnList(buf, fk.IndexColumns, fk.Period)
1233 buf.Printf(" references %v", fk.ReferenceName)
1234 formatFKColumnList(buf, fk.ReferenceColumns, fk.Period)
1235 // Match / OnDelete / OnUpdate are fixed SQL keyword sequences (e.g.
1236 // "MATCH FULL", "SET NULL"), not user identifiers, so emit Name directly
1237 // to avoid Ident.Format quoting space-containing values.
1238 if !fk.Match.IsEmpty() {
1239 buf.Printf(" %s", fk.Match.Name)
1240 }
1241 if !fk.OnDelete.IsEmpty() {
1242 buf.Printf(" on delete %s", fk.OnDelete.Name)
1243 }
1244 if !fk.OnUpdate.IsEmpty() {
1245 buf.Printf(" on update %s", fk.OnUpdate.Name)
1246 }
1247 if fk.NotForReplication {
1248 buf.Printf(" not for replication")
1249 }
1250 if fk.ConstraintOptions != nil && fk.ConstraintOptions.Deferrable {
1251 buf.Printf(" deferrable")
1252 if fk.ConstraintOptions.InitiallyDeferred {
1253 buf.Printf(" initially deferred")
1254 }
1255 }
1256}
1257
1258func formatFKColumnList(buf *nodeBuffer, cols []Ident, period bool) {
1259 buf.Printf(" (")

Callers

nothing calls this directly

Calls 3

formatFKColumnListFunction · 0.85
PrintfMethod · 0.65
IsEmptyMethod · 0.45

Tested by

no test coverage detected