ddl

package module
v0.0.0-...-f8fad95 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 5 Imported by: 2

README

protoc-ddl

THIS PROJECT IS WORKING IN PROGRESS

protoc-ddl is a tool of define and generate the schema for RDB.

How to use

Command Line

$ go get go.f110.dev/protoc-ddl/cmd/protoc-gen-ddl

With Bazel

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "a8d6b1b354d371a646d2f7927319974e0f9e52f73a2452d2b3877118169eb6bb",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.23.3/rules_go-v0.23.3.tar.gz",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.23.3/rules_go-v0.23.3.tar.gz",
    ],
)

git_repository(
    name = "dev_f110_protoc_ddl",
    commit = "61319c2f91243da88d6d88a04d3e5b783b86f510",
    remote = "https://github.com/f110/protoc-ddl",
)

load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()

go_register_toolchains()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

BUILD.bazel

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
    name = "database_proto",
    srcs = ["schema.proto"],
    visibility = ["//visibility:public"],
    deps = [
        "@dev_f110_protoc_ddl//:ddl_proto",
        "@com_google_protobuf//:timestamp_proto",
    ],
)

go_proto_library(
    name = "database_go_proto",
    importpath = "go.f110.dev/mono/tools/build/pkg/database",
    proto = ":database_proto",
    visibility = ["//visibility:public"],
    deps = ["//:go_default_library"],
)

go_library(
    name = "go_default_library",
    embed = [":database_go_proto"],
    importpath = "go.f110.dev/mono/tools/build/pkg/database",
    visibility = ["//visibility:public"],
)

load("@dev_f110_protoc_ddl//rules:def.bzl", "sql_schema", "vendor_sql_schema")

sql_schema(
    name = "schema",
    proto = ":database_proto",
)

vendor_sql_schema(
    name = "vendor_schema",
    src = ":schema",
)

You can see the generated schema file by the following command.

$ bazel run //:vendor_sql_schema

You will see the generated schema file in the same directory at *.sql.

Migration

This tool also supports the migration.

$ migrate --schema ./schema.sql --driver mysql --dsn "root@tcp(localhost)/protoc_ddl" --execute

Currently, Only mysql is supported.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// optional dev.f110.ddl.TableOptions table = 60000;
	E_Table = &file_ddl_proto_extTypes[0]
	// optional dev.f110.ddl.DAOOptions dao = 60001;
	E_Dao = &file_ddl_proto_extTypes[1]
)

Extension fields to descriptorpb.MessageOptions.

View Source
var (
	// optional dev.f110.ddl.ColumnOptions column = 60000;
	E_Column = &file_ddl_proto_extTypes[2]
)

Extension fields to descriptorpb.FieldOptions.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name  string
	Value interface{}
}

type ColumnOptions

type ColumnOptions struct {
	Sequence bool   `protobuf:"varint,1,opt,name=sequence,proto3" json:"sequence,omitempty"`
	Null     bool   `protobuf:"varint,2,opt,name=null,proto3" json:"null,omitempty"`
	Default  string `protobuf:"bytes,3,opt,name=default,proto3" json:"default,omitempty"`
	Size     int32  `protobuf:"varint,4,opt,name=size,proto3" json:"size,omitempty"`
	Type     string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"`
	Unique   bool   `protobuf:"varint,6,opt,name=unique,proto3" json:"unique,omitempty"`
	// contains filtered or unexported fields
}

func (*ColumnOptions) Descriptor deprecated

func (*ColumnOptions) Descriptor() ([]byte, []int)

Deprecated: Use ColumnOptions.ProtoReflect.Descriptor instead.

func (*ColumnOptions) GetDefault

func (x *ColumnOptions) GetDefault() string

func (*ColumnOptions) GetNull

func (x *ColumnOptions) GetNull() bool

func (*ColumnOptions) GetSequence

func (x *ColumnOptions) GetSequence() bool

func (*ColumnOptions) GetSize

func (x *ColumnOptions) GetSize() int32

func (*ColumnOptions) GetType

func (x *ColumnOptions) GetType() string

func (*ColumnOptions) GetUnique

func (x *ColumnOptions) GetUnique() bool

func (*ColumnOptions) ProtoMessage

func (*ColumnOptions) ProtoMessage()

func (*ColumnOptions) ProtoReflect

func (x *ColumnOptions) ProtoReflect() protoreflect.Message

func (*ColumnOptions) Reset

func (x *ColumnOptions) Reset()

func (*ColumnOptions) String

func (x *ColumnOptions) String() string

type DAOOptions

type DAOOptions struct {
	Queries []*QueryOption `protobuf:"bytes,1,rep,name=queries,proto3" json:"queries,omitempty"`
	// contains filtered or unexported fields
}

func (*DAOOptions) Descriptor deprecated

func (*DAOOptions) Descriptor() ([]byte, []int)

Deprecated: Use DAOOptions.ProtoReflect.Descriptor instead.

func (*DAOOptions) GetQueries

func (x *DAOOptions) GetQueries() []*QueryOption

func (*DAOOptions) ProtoMessage

func (*DAOOptions) ProtoMessage()

func (*DAOOptions) ProtoReflect

func (x *DAOOptions) ProtoReflect() protoreflect.Message

func (*DAOOptions) Reset

func (x *DAOOptions) Reset()

func (*DAOOptions) String

func (x *DAOOptions) String() string

type IndexOption

type IndexOption struct {
	Name    string   `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Columns []string `protobuf:"bytes,2,rep,name=columns,proto3" json:"columns,omitempty"`
	Unique  bool     `protobuf:"varint,3,opt,name=unique,proto3" json:"unique,omitempty"`
	// contains filtered or unexported fields
}

func (*IndexOption) Descriptor deprecated

func (*IndexOption) Descriptor() ([]byte, []int)

Deprecated: Use IndexOption.ProtoReflect.Descriptor instead.

func (*IndexOption) GetColumns

func (x *IndexOption) GetColumns() []string

func (*IndexOption) GetName

func (x *IndexOption) GetName() string

func (*IndexOption) GetUnique

func (x *IndexOption) GetUnique() bool

func (*IndexOption) ProtoMessage

func (*IndexOption) ProtoMessage()

func (*IndexOption) ProtoReflect

func (x *IndexOption) ProtoReflect() protoreflect.Message

func (*IndexOption) Reset

func (x *IndexOption) Reset()

func (*IndexOption) String

func (x *IndexOption) String() string

type QueryOption

type QueryOption struct {
	Name  string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Query string `protobuf:"bytes,2,opt,name=query,proto3" json:"query,omitempty"`
	// contains filtered or unexported fields
}

func (*QueryOption) Descriptor deprecated

func (*QueryOption) Descriptor() ([]byte, []int)

Deprecated: Use QueryOption.ProtoReflect.Descriptor instead.

func (*QueryOption) GetName

func (x *QueryOption) GetName() string

func (*QueryOption) GetQuery

func (x *QueryOption) GetQuery() string

func (*QueryOption) ProtoMessage

func (*QueryOption) ProtoMessage()

func (*QueryOption) ProtoReflect

func (x *QueryOption) ProtoReflect() protoreflect.Message

func (*QueryOption) Reset

func (x *QueryOption) Reset()

func (*QueryOption) String

func (x *QueryOption) String() string

type TableOptions

type TableOptions struct {
	TableName     string         `protobuf:"bytes,1,opt,name=table_name,json=tableName,proto3" json:"table_name,omitempty"`
	PrimaryKey    []string       `protobuf:"bytes,2,rep,name=primary_key,json=primaryKey,proto3" json:"primary_key,omitempty"`
	Indexes       []*IndexOption `protobuf:"bytes,3,rep,name=indexes,proto3" json:"indexes,omitempty"`
	Engine        string         `protobuf:"bytes,4,opt,name=engine,proto3" json:"engine,omitempty"`
	WithTimestamp bool           `protobuf:"varint,5,opt,name=with_timestamp,json=withTimestamp,proto3" json:"with_timestamp,omitempty"`
	// contains filtered or unexported fields
}

func (*TableOptions) Descriptor deprecated

func (*TableOptions) Descriptor() ([]byte, []int)

Deprecated: Use TableOptions.ProtoReflect.Descriptor instead.

func (*TableOptions) GetEngine

func (x *TableOptions) GetEngine() string

func (*TableOptions) GetIndexes

func (x *TableOptions) GetIndexes() []*IndexOption

func (*TableOptions) GetPrimaryKey

func (x *TableOptions) GetPrimaryKey() []string

func (*TableOptions) GetTableName

func (x *TableOptions) GetTableName() string

func (*TableOptions) GetWithTimestamp

func (x *TableOptions) GetWithTimestamp() bool

func (*TableOptions) ProtoMessage

func (*TableOptions) ProtoMessage()

func (*TableOptions) ProtoReflect

func (x *TableOptions) ProtoReflect() protoreflect.Message

func (*TableOptions) Reset

func (x *TableOptions) Reset()

func (*TableOptions) String

func (x *TableOptions) String() string

Directories

Path Synopsis
cmd
internal
rules
Generated by protoc-ddl.
Generated by protoc-ddl.
dao
Package dao contains the data access object.
Package dao contains the data access object.
dao/daotest
Generated by protoc-ddl.
Generated by protoc-ddl.

Jump to

Keyboard shortcuts

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