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

Function fromMysqlDataSource

tools/goctl/model/sql/command/command.go:296–353  ·  view source on GitHub ↗
(arg dataSourceArg)

Source from the content-addressed store, hash-verified

294}
295
296func fromMysqlDataSource(arg dataSourceArg) error {
297 log := console.NewConsole(arg.idea)
298 if len(arg.url) == 0 {
299 log.Error("%v", "expected data source of mysql, but nothing found")
300 return nil
301 }
302
303 if len(arg.tablePat) == 0 {
304 log.Error("%v", "expected table or table globbing patterns, but nothing found")
305 return nil
306 }
307
308 dsn, err := mysql.ParseDSN(arg.url)
309 if err != nil {
310 return err
311 }
312
313 logx.Disable()
314 databaseSource := strings.TrimSuffix(arg.url, "/"+dsn.DBName) + "/information_schema"
315 db := sqlx.NewMysql(databaseSource)
316 im := model.NewInformationSchemaModel(db)
317
318 tables, err := im.GetAllTables(dsn.DBName)
319 if err != nil {
320 return err
321 }
322
323 matchTables := make(map[string]*model.Table)
324 for _, item := range tables {
325 if !arg.tablePat.Match(item) {
326 continue
327 }
328
329 columnData, err := im.FindColumns(dsn.DBName, item)
330 if err != nil {
331 return err
332 }
333
334 table, err := columnData.Convert()
335 if err != nil {
336 return err
337 }
338
339 matchTables[item] = table
340 }
341
342 if len(matchTables) == 0 {
343 return errors.New("no tables matched")
344 }
345
346 generator, err := gen.NewDefaultGenerator(arg.prefix, arg.dir, arg.cfg,
347 gen.WithConsoleOption(log), gen.WithIgnoreColumns(arg.ignoreColumns))
348 if err != nil {
349 return err
350 }
351
352 return generator.StartFromInformationSchema(matchTables, arg.cache, arg.strict)
353}

Callers 1

MySqlDataSourceFunction · 0.85

Calls 13

ErrorMethod · 0.95
GetAllTablesMethod · 0.95
FindColumnsMethod · 0.95
NewConsoleFunction · 0.92
DisableFunction · 0.92
NewMysqlFunction · 0.92
NewDefaultGeneratorFunction · 0.92
WithConsoleOptionFunction · 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…