Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gustapinto/pg_gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/[email protected] instead of go run github.com/gustapinto/pg_gen@latest).

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published