(c *cli.Context)
| 114 | } |
| 115 | |
| 116 | func importTables(c *cli.Context) { |
| 117 | ttt := template.Must(template.New("st").Funcs(funcMap).Parse(structTemplate)) |
| 118 | cxn, err := sql.Open(driver(c), conn(c)) |
| 119 | if err != nil { |
| 120 | cxdie(c, err) |
| 121 | } |
| 122 | // Many drivers defer connections until the first statement. We test |
| 123 | // that here. |
| 124 | if err := cxn.Ping(); err != nil { |
| 125 | cxdie(c, err) |
| 126 | } |
| 127 | defer cxn.Close() |
| 128 | |
| 129 | // Set up Squirrel |
| 130 | stmts := squirrel.NewStmtCacher(cxn) |
| 131 | bldr := squirrel.StatementBuilder.RunWith(stmts) |
| 132 | if driver(c) == "postgres" { |
| 133 | bldr = bldr.PlaceholderFormat(squirrel.Dollar) |
| 134 | } |
| 135 | |
| 136 | // Set up destination |
| 137 | out := dest(c) |
| 138 | fmt.Fprintln(out, fileHeader) |
| 139 | |
| 140 | tables := tableList(c) |
| 141 | |
| 142 | if len(tables) == 0 { |
| 143 | tables, err = publicTables(bldr) |
| 144 | if err != nil { |
| 145 | fmt.Fprintf(os.Stderr, "Cannot fetch list of tables: %s\n", err) |
| 146 | os.Exit(2) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | for _, t := range tables { |
| 151 | f, err := importTable(t, bldr) |
| 152 | if err != nil { |
| 153 | fmt.Fprintf(os.Stderr, "Failed to import table %s: %s", t, err) |
| 154 | } |
| 155 | |
| 156 | //fmt.Fprintf(out, "%s %s %s\n", f.StructName, f.TableName, f.Fields) |
| 157 | ttt.Execute(out, f) |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | type column struct { |
| 162 | Name, DataType string |
nothing calls this directly
no test coverage detected