MCPcopy Index your code
hub / github.com/sqldef/sqldef / exportTableDDL

Method exportTableDDL

database/postgres/database.go:734–764  ·  view source on GitHub ↗
(table string, cache *TableDDLComponentsCache)

Source from the content-addressed store, hash-verified

732}
733
734func (d *PostgresDatabase) exportTableDDL(table string, cache *TableDDLComponentsCache) (string, error) {
735 components := TableDDLComponents{
736 TableName: table,
737 DefaultSchema: d.GetDefaultSchema(),
738 }
739
740 components.Columns = cache.columns[table]
741 components.PrimaryKeyCols = cache.primaryKeyCols[table]
742 // if pkey cols exist, retrieve the pkey name
743 if len(components.PrimaryKeyCols) > 0 {
744 pkInfo, ok := cache.primaryKeyInfos[table]
745 if !ok {
746 return "", fmt.Errorf("failed to get primary key name for table %s", table)
747 }
748 components.PrimaryKeyName = pkInfo.name
749 components.PrimaryKeyPeriod = pkInfo.period
750 }
751 components.IndexDefs = cache.indexDefs[table]
752 components.ForeignDefs = cache.foreignDefs[table]
753 components.RLSDefs = cache.rlsDefs[table]
754 components.PolicyDefs = cache.policyDefs[table]
755 components.CheckConstraints = cache.checkConstraints[table]
756 components.UniqueConstraints = cache.uniqueConstraints[table]
757 if components.UniqueConstraints == nil {
758 components.UniqueConstraints = make(map[string]string)
759 }
760 components.ExclusionDefs = cache.exclusionDefs[table]
761 components.Comments = cache.comments[table]
762 components.PrivilegeDefs = cache.privilegeDefs[table]
763 return d.buildExportTableDDL(components), nil
764}
765
766func (d *PostgresDatabase) buildExportTableDDL(components TableDDLComponents) string {
767 var queryBuilder strings.Builder

Callers 1

ExportDDLsMethod · 0.95

Calls 3

GetDefaultSchemaMethod · 0.95
buildExportTableDDLMethod · 0.95
ErrorfMethod · 0.65

Tested by

no test coverage detected