sql-enum-generator

command module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 9 Imported by: 0

README

sql-enum-generator

sql-enum-generator is a tool that converts SQL INSERT statements for master data into OpenAPI schemas. This application enables developers to easily generate enum representations of database master data using OpenAPI specifications, streamlining the development process and ensuring consistency between the database and application code.

Currently only postgresql is supported.

Features

  • Parses SQL INSERT statements and generates corresponding OpenAPI schemas
  • Generated OpenAPI schemas can be utilized with other tools for type generation

Quick Start

  1. Create a configuration file named sqlenumgen.yml with the following content:
version: "1"
tables:
  - name: products
    key: name
    value: id
  1. Run the application using the following command:
$ go run github.com/flum1025/sql-enum-generator generate --source-path ./example/master.sql --output-path ./example/openapi.generated.json --config ./example/sqlenumgen.yml
  1. Utilize language-specific generation tools to create enums from the generated OpenAPI schema.

For actual generation examples, please refer to the example directory in the repository.

Language-Specific Usage Examples

Go

For Go, you can use oapi-codegen to generate code from the OpenAPI schema. Create a configuration file named oapi-codegen.yml with the following content:

package: main
output: ./openapi.generated.go
generate:
  models: true
compatibility:
  always-prefix-enum-values: true
output-options:
  skip-prune: true

Then, run the following command to generate the Go code:

$ go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config ./example/oapi-codegen.yml ./example/openapi.generated.json
TypeScript

For TypeScript, you can use openapi-typescript to generate TypeScript definitions. Run the following command:

$ npx openapi-typescript ./example/openapi.generated.json -o ./example/openapi.generated.d.ts --enum

Future Plans

  • Add support for additional SQL dialects

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package main provides primitives to interact with the openapi HTTP API.
Package main provides primitives to interact with the openapi HTTP API.
app

Jump to

Keyboard shortcuts

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