MCPcopy Create free account
hub / github.com/achiku/planter / LoadTableDef

Function LoadTableDef

planter.go:213–243  ·  view source on GitHub ↗

LoadTableDef load Postgres table definition

(db Queryer, schema string)

Source from the content-addressed store, hash-verified

211
212// LoadTableDef load Postgres table definition
213func LoadTableDef(db Queryer, schema string) ([]*Table, error) {
214 tbDefs, err := db.Query(tableDefSQL, schema)
215 if err != nil {
216 return nil, errors.Wrap(err, "failed to load table def")
217 }
218 var tbls []*Table
219 for tbDefs.Next() {
220 t := &Table{Schema: schema}
221 err := tbDefs.Scan(
222 &t.Name,
223 &t.Comment,
224 )
225 if err != nil {
226 return nil, errors.Wrap(err, "failed to scan")
227 }
228 cols, err := LoadColumnDef(db, schema, t.Name)
229 if err != nil {
230 return nil, errors.Wrap(err, fmt.Sprintf("failed to get columns of %s", t.Name))
231 }
232 t.Columns = cols
233 tbls = append(tbls, t)
234 }
235 for _, tbl := range tbls {
236 fks, err := LoadForeignKeyDef(db, schema, tbls, tbl)
237 if err != nil {
238 return nil, errors.Wrap(err, fmt.Sprintf("failed to get fks of %s", tbl.Name))
239 }
240 tbl.ForeingKeys = fks
241 }
242 return tbls, nil
243}
244
245// TableToUMLEntry table entry
246func TableToUMLEntry(tbls []*Table) ([]byte, error) {

Callers 5

TestLoadForeignKeyDefFunction · 0.85
TestLoadTableDefFunction · 0.85
TestTableToUMLEntryFunction · 0.85
mainFunction · 0.85

Calls 3

LoadColumnDefFunction · 0.85
LoadForeignKeyDefFunction · 0.85
QueryMethod · 0.80

Tested by 4

TestLoadForeignKeyDefFunction · 0.68
TestLoadTableDefFunction · 0.68
TestTableToUMLEntryFunction · 0.68