sqlproto

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2025 License: MIT Imports: 8 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 WriteDataPackageCode added in v0.0.4

func WriteDataPackageCode(
	outputPath string,
	orm string,
	projectName string,
	serviceName string,
	name string,
	moduleName, moduleVersion string,
	protoFields ProtoFieldArray,
)

func WriteInitWireCode added in v0.0.4

func WriteInitWireCode(
	outputPath string,
)

func WriteMainCode added in v0.0.4

func WriteMainCode(
	outputPath string,

	projectName string,
	serviceName string,

	enableREST bool,
	enableGRPC bool,
	enableAsynq bool,
	enableSSE bool,
	enableKafka bool,
	enableMQTT bool,
)

func WriteServerPackageCode added in v0.0.4

func WriteServerPackageCode(
	outputPath string,
	projectName string,
	serviceType string,
	serviceName string,
	services map[string]string,
)

func WriteServicePackageCode added in v0.0.4

func WriteServicePackageCode(
	outputPath string,
	projectName string,
	serviceName string,
	name string,
	targetModuleName, sourceModuleName, moduleVersion string,
	userRepo, isGrpcService bool,
)

func WriteServiceProto added in v0.0.4

func WriteServiceProto(
	outputPath string,
	serviceType string,
	name string,
	comment string,
	targetModuleName, sourceModuleName, moduleVersion string,
	protoFields ProtoFieldArray,
)

func WriteWireCode added in v0.0.4

func WriteWireCode(
	outputPath string,

	projectName string,
	serviceName string,
)

Types

type ProtoField added in v0.0.4

type ProtoField render.ProtoField

type ProtoFieldArray added in v0.0.4

type ProtoFieldArray render.ProtoFieldArray

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,
) (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