/sqlgen2

Go tool for generating sql scanners, sql statements and other helper functions

Primary LanguageGoBSD 2-Clause "Simplified" LicenseBSD-2-Clause

sqlgen2

GoDoc Build Status Issues

sqlgen generates SQL statements from your Go structs, used along with sqlapi database helper functions. It takes the place of a simple ORM or hand-written SQL.

See the demo directory for examples. Look in the generated files *_sql.go and the hand-crafted files (hook.go, issue.go, user.go).

Features

  • Auto-generates DAO-style table-support code for SQL databases.
  • Sophisticated parsing of a Go struct that describes records in the table.
  • Allows nesting of structs, fields that are structs or pointers to structs etc.
  • Struct tags give fine control over the semantics of each field.
  • Supports indexes and constraints.
  • Supports foreign key relationships between tables.
  • Helps you develop code for joins and views.
  • Supports JSON-encoded columns, allowing a more no-SQL model when needed.
  • Provides a builder-style API for constructing where-clauses and query constraints.
  • Allows declarative requirements on the expected result of each query, enhancing error checking.
  • Very flexible configuration.
  • Fast and easy to use.

Currently, support is included for MySQL, PostgreSQL and SQLite. Other database/sql dialects can be added relatively easy - send a Pull Request!

There is also direct support for pgx, which differs somewhat from the database/sql but is noteworthy and worth supporting here.

Install

-- this is being revised --

Usage

See the command line usage.

Tutorial

See the tutorial.

Credits

This tool was derived from sqlgen by drone.io, which was itself inspired by scaneo.