pg_gen

command module
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2025 License: MIT Imports: 16 Imported by: 0

README

pg_gen

A golang code generator to introspect and generate database/sql code from Postgres databases

Example usage of the generated code can be found here.

Usage

  1. Create a configuration file in your project root, YAML and JSON formats are supported. Example:
# The PostgreSQL database connection string
dsn: "postgresql://myuser:mypassword@localhost:5432/mydb?sslmode=disable"

# The database schemas that will be introspected for code generation
schemas:
  public:
    # If views should be included in code generation (Optional, default=false)
    include_views: true
    # Tables or views that should be ignored in code generation (Optional, default=null)
    ignore:
      - "locked_table"
      - "super_secret_view"
    # Golang code generation specific stuff
    go:
      # The destination folder
      dest: "./gen"
      # The generated code package name
      package: "gen"
      # If the generated entities must include JSON tags (Optional, default=false)
      emit_json_tags: true
  1. Execute the generator
go run github.com/gustapinto/pg_gen@latest -config=./example_config.yaml
  1. All done! Your generated code is ready to be used

You can also use the generator as a go:generate clause. Example:

//go:generate go run github.com/gustapinto/pg_gen@latest -config=./example_config.yaml
package main

func main() {
    // Your code
}

API status

The generated code API uses a DAO/Active Record like struct and method organization, example usage of this can be found here.

Currently the generated code API is not set on stone yet, so we highly recommend you to use explicit versions of pg_gen when generating code (ex: go run github.com/gustapinto/pg_gen@X.Y.Z instead of go run github.com/gustapinto/pg_gen@latest).

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL