(ctx context.Context)
| 241 | } |
| 242 | |
| 243 | func run(ctx context.Context) error { |
| 244 | flag.Parse() |
| 245 | |
| 246 | dir := flag.Arg(0) |
| 247 | if dir == "" { |
| 248 | dir = filepath.Join("internal", "engine", "postgresql") |
| 249 | } |
| 250 | |
| 251 | tmpl, err := template.New("").Parse(catalogTmpl) |
| 252 | if err != nil { |
| 253 | return err |
| 254 | } |
| 255 | conn, err := pgx.Connect(ctx, databaseURL()) |
| 256 | if err != nil { |
| 257 | return err |
| 258 | } |
| 259 | defer conn.Close(ctx) |
| 260 | |
| 261 | schemas := []schemaToLoad{ |
| 262 | { |
| 263 | Name: "pg_catalog", |
| 264 | GenFnName: "genPGCatalog", |
| 265 | DestPath: filepath.Join(dir, "pg_catalog.go"), |
| 266 | }, |
| 267 | { |
| 268 | Name: "information_schema", |
| 269 | GenFnName: "genInformationSchema", |
| 270 | DestPath: filepath.Join(dir, "information_schema.go"), |
| 271 | }, |
| 272 | } |
| 273 | |
| 274 | for _, schema := range schemas { |
| 275 | procs, err := readProcs(ctx, conn, schema.Name) |
| 276 | if err != nil { |
| 277 | return err |
| 278 | } |
| 279 | |
| 280 | if schema.Name == "pg_catalog" { |
| 281 | procs = preserveLegacyCatalogBehavior(procs) |
| 282 | } |
| 283 | |
| 284 | relations, err := readRelations(ctx, conn, schema.Name) |
| 285 | if err != nil { |
| 286 | return err |
| 287 | } |
| 288 | |
| 289 | err = writeFormattedGo(tmpl, tmplCtx{ |
| 290 | Pkg: "postgresql", |
| 291 | SchemaName: schema.Name, |
| 292 | GenFnName: schema.GenFnName, |
| 293 | Procs: procs, |
| 294 | Relations: relations, |
| 295 | }, schema.DestPath) |
| 296 | |
| 297 | if err != nil { |
| 298 | return err |
| 299 | } |
| 300 | } |
no test coverage detected