| 45 | } |
| 46 | |
| 47 | func (a *Args) checkValid() error { |
| 48 | if a.SQL == "" && a.DDLFile == "" && (a.DBDsn == "" && a.DBTable == "") { |
| 49 | return errors.New("you must specify sql or ddl file") |
| 50 | } |
| 51 | if a.DBTable != "" { |
| 52 | tables := strings.Split(a.DBTable, ",") |
| 53 | for _, name := range tables { |
| 54 | if strings.HasSuffix(name, "_test") { |
| 55 | return fmt.Errorf(`the table name (%s) suffix "_test" is not supported for code generation, please delete suffix "_test" or change it to another name. `, name) |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if a.DBDriver == "" { |
| 61 | a.DBDriver = parser.DBDriverMysql |
| 62 | } else if a.DBDriver == parser.DBDriverSqlite { |
| 63 | if !gofile.IsExists(a.DBDsn) { |
| 64 | return fmt.Errorf("sqlite db file %s not found in local host", a.DBDsn) |
| 65 | } |
| 66 | } |
| 67 | if a.fieldTypes == nil { |
| 68 | a.fieldTypes = make(map[string]string) |
| 69 | } |
| 70 | return nil |
| 71 | } |
| 72 | |
| 73 | func getSQL(args *Args) (string, map[string]string, error) { |
| 74 | if args.SQL != "" { |