An open API service indexing awesome lists of open source software.

https://github.com/optiopay/sqlgen

A sql.Scanner and sql.Valuer generator for Go
https://github.com/optiopay/sqlgen

library open-source sql

Last synced: 5 months ago
JSON representation

A sql.Scanner and sql.Valuer generator for Go

Awesome Lists containing this project

README

          

# sqlgen

This tool generates `sql.Scanner` and `sql.Valuer` interfaces for your own structs and type aliases. It is tested with Postgres and `lib/pq` library, others might work. The command is quite self explanatory, use the `--help` option to understand the parameters.

## Trying it out

The `example` folder provides you with tests and structs to understand how this tool works. Run `go generate` in the example folder to generate the interfaces. Then you can run `go test` to see if all works. It tries to connect to a local postgres instance and needs a database named ⁠⁠⁠⁠`custom`.

The `-array`⁠⁠⁠⁠ param generates array types as well, the `-sql`⁠⁠⁠⁠ param adds a Init function that can be used to create the composite type in postgres.

## Aliases
There is support for type aliases. To generate scanner and valuer for type aliases you can pass them through the `alias` param.