MCPcopy
hub / github.com/sqlc-dev/sqlc / run

Function run

internal/tools/sqlc-pg-gen/main.go:243–368  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

241}
242
243func 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 }

Callers 1

mainFunction · 0.70

Calls 12

databaseURLFunction · 0.85
readProcsFunction · 0.85
readRelationsFunction · 0.85
writeFormattedGoFunction · 0.85
scanProcsFunction · 0.85
ParseMethod · 0.65
CloseMethod · 0.65
ExecMethod · 0.65
QueryMethod · 0.65
JoinMethod · 0.45
ReplaceMethod · 0.45

Tested by

no test coverage detected