sqlproto

package module
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: MIT Imports: 11 Imported by: 1

README

SQL → Protobuf

This tool imports the SQL database schemas and generates Protobuf code for use in Kratos microservices.

HOW TO INSTALL

go install github.com/tx7do/kratos-cli/sql-proto/cmd/sql2proto@latest

HOW TO USE

sql2proto is a tool to import SQL database schema and generate Protobuf code.

Usage:
  sql2proto [flags]

Flags:
  -n, --dsn string          Data source name (connection information), for example:
                            "mysql://user:pass@tcp(localhost:3306)/dbname"
                            "postgres://user:pass@host:port/dbname"
  -e, --excludes strings    comma-separated list of tables to exclude
  -h, --help                help for sql2proto
  -i, --includes strings    comma-separated list of tables to inspect (all if empty)
  -m, --module string       module name for the generated code, e.g., 'admin' (default "admin")
  -o, --output string       output path for protobuf schema files (default "./api/protos/")
  -s, --src-module string   Source module name, for REST service generate, e.g., "admin" (default "user")
  -t, --type string         generate RPC service type, "rest" for REST service, "grpc" for gRPC service (default "grpc")
  -v, --version string      Version of the module, e.g., 'v1' (default "v1")

EXAMPLES

generate gRPC service from PostgreSQL database schema:

sql2proto \
  -n "postgres://postgres:pass@localhost:5432/test?sslmode=disable" \
  -o "./api/protos" \
  -t "grpc" \
  -m "user"

generate REST service from MySQL database schema:

sql2proto \
  -n "mysql://root:pass@localhost:3306/test" \
  -o "./api/protos" \
  -t "rest" \
  -m "admin" \
  -s "user"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveTableCommentSuffix added in v0.0.15

func RemoveTableCommentSuffix(input string) string

func WriteServiceProto added in v0.0.4

func WriteServiceProto(
	outputPath string,
	serviceType string,
	targetModuleName, sourceModuleName, moduleVersion string,
	tableName string,
	tableComment string,
	protoFields ProtoFieldArray,
) error

func WriteServicesProto added in v0.0.8

func WriteServicesProto(
	outputPath string,
	serviceType string,
	targetModuleName, sourceModuleName, moduleVersion string,
	tables TableDataArray,
) error

Types

type ProtoField added in v0.0.4

type ProtoField generators.ProtoField

type ProtoFieldArray added in v0.0.4

type ProtoFieldArray []generators.ProtoField

type TableDataArray added in v0.0.3

type TableDataArray []*internal.TableData

func Convert

func Convert(
	ctx context.Context,
	dsn, outputPath *string,
	moduleName, sourceModuleName, moduleVersion *string,
	serviceType *string,
	includeTables, excludeTables []string,
	exportProto bool,
) (TableDataArray, error)

Convert converts the database schema into a protocol buffer definition.

Directories

Path Synopsis
cmd
sql2proto command
mux

Jump to

Keyboard shortcuts

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