MCPcopy
hub / github.com/zeromicro/go-zero / fromPostgreSqlDataSource

Function fromPostgreSqlDataSource

tools/goctl/model/sql/command/command.go:366–415  ·  view source on GitHub ↗
(arg pgDataSourceArg)

Source from the content-addressed store, hash-verified

364}
365
366func fromPostgreSqlDataSource(arg pgDataSourceArg) error {
367 log := console.NewConsole(arg.idea)
368 if len(arg.url) == 0 {
369 log.Error("%v", "expected data source of postgresql, but nothing found")
370 return nil
371 }
372
373 if len(arg.tablePat) == 0 {
374 log.Error("%v", "expected table or table globbing patterns, but nothing found")
375 return nil
376 }
377 db := postgres.New(arg.url)
378 im := model.NewPostgreSqlModel(db)
379
380 tables, err := im.GetAllTables(arg.schema)
381 if err != nil {
382 return err
383 }
384
385 matchTables := make(map[string]*model.Table)
386 for _, item := range tables {
387 if !arg.tablePat.Match(item) {
388 continue
389 }
390
391 columnData, err := im.FindColumns(arg.schema, item)
392 if err != nil {
393 return err
394 }
395
396 table, err := columnData.Convert()
397 if err != nil {
398 return err
399 }
400
401 matchTables[item] = table
402 }
403
404 if len(matchTables) == 0 {
405 return errors.New("no tables matched")
406 }
407
408 generator, err := gen.NewDefaultGenerator(arg.prefix, arg.dir, arg.cfg, gen.WithConsoleOption(log),
409 gen.WithPostgreSql(), gen.WithIgnoreColumns(arg.ignoreColumns))
410 if err != nil {
411 return err
412 }
413
414 return generator.StartFromInformationSchema(matchTables, arg.cache, arg.strict)
415}

Callers 1

PostgreSqlDataSourceFunction · 0.85

Calls 13

ErrorMethod · 0.95
GetAllTablesMethod · 0.95
FindColumnsMethod · 0.95
NewConsoleFunction · 0.92
NewFunction · 0.92
NewPostgreSqlModelFunction · 0.92
NewDefaultGeneratorFunction · 0.92
WithConsoleOptionFunction · 0.92
WithPostgreSqlFunction · 0.92
WithIgnoreColumnsFunction · 0.92
MatchMethod · 0.80
ConvertMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…