remodel

package module
v0.0.0-...-98c721a Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: MIT Imports: 15 Imported by: 0

README

remodel

generate domain codes from create table ddl

requirement

  • Go 1.13+
  • MySQL
  • Memcached

Usage

install remodel command

go get -u github.com/yuki-eto/remodel/cmd/remodel

write create table ddl

make table schema to (root_dir)/schema/sql

CREATE TABLE IF NOT EXISTS `user_friends` (
  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `user_id` BIGINT(20) UNSIGNED NOT NULL,
  `other_user_id` BIGINT(20) UNSIGNED NOT NULL,
  `created_at` DATETIME,
  `updated_at` DATETIME,
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_relation` (`user_id`, `other_user_id`),
  KEY `other_user_relation` (`other_user_id`)
);

to Yaml

run cli and write to (root_dir)/schema/yaml

remodel -root ./ yaml

to Golang codes

remodel -root ./ -module module_sample entity
remodel -root ./ -module module_sample dao
remodel -root ./ -module module_sample model

Documentation

Index

Constants

View Source
const (
	// MySQL table column types
	BigInt     ColumnType = "bigint"
	MediumInt  ColumnType = "mediumint"
	SmallInt   ColumnType = "smallint"
	TinyInt    ColumnType = "tinyint"
	Int        ColumnType = "int"
	Float      ColumnType = "float"
	Double     ColumnType = "double"
	Decimal    ColumnType = "decimal"
	Numeric    ColumnType = "numeric"
	Bit        ColumnType = "bit"
	Date       ColumnType = "date"
	Datetime   ColumnType = "datetime"
	Timestamp  ColumnType = "timestamp"
	Time       ColumnType = "time"
	Year       ColumnType = "year"
	Binary     ColumnType = "binary"
	VarBinary  ColumnType = "varbinary"
	LongBlob   ColumnType = "longblob"
	MediumBlob ColumnType = "mediumblob"
	TinyBlob   ColumnType = "tinyblob"
	Blob       ColumnType = "blob"
	Set        ColumnType = "set"
	Char       ColumnType = "char"
	VarChar    ColumnType = "varchar"
	LongText   ColumnType = "longtext"
	MediumText ColumnType = "mediumtext"
	TinyText   ColumnType = "tinytext"
	Text       ColumnType = "text"
	Enum       ColumnType = "enum"

	// Golang types
	Uint64      EntityType = "uint64"
	Uint32      EntityType = "uint32"
	Uint16      EntityType = "uint16"
	Uint8       EntityType = "uint8"
	Int64       EntityType = "int64"
	Int32       EntityType = "int32"
	Int16       EntityType = "int16"
	Int8        EntityType = "int8"
	Bool        EntityType = "bool"
	Float64     EntityType = "float64"
	Float32     EntityType = "float32"
	TimePtr     EntityType = "*time.Time"
	String      EntityType = "string"
	ByteSlice   EntityType = "[]byte"
	StringSlice EntityType = "[]string"

	// outside library for generate code
	ErrorsLib   = "github.com/juju/errors"
	LogLib      = "github.com/labstack/gommon/log"
	RapidashLib = "go.knocknote.io/rapidash"

	EntityPackageName = "entity"
	DaoPackageName    = "dao"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name            string     `yaml:"name"`
	ColumnType      ColumnType `yaml:"column_type"`
	EntityType      EntityType `yaml:"entity_type"`
	Size            uint64     `yaml:"size"`
	IsAutoIncrement bool       `yaml:"is_auto_increment"`
	IsUnsigned      bool       `yaml:"is_unsigned"`
	IsNotNull       bool       `yaml:"is_not_null"`
	DefaultValue    string     `yaml:"default_value"`
	IsPrimaryKey    bool       `yaml:"is_primary_key"`
	UniqueIndexKeys []string   `yaml:"unique_index_keys"`
	IndexKeys       []string   `yaml:"index_keys"`
}

type ColumnType

type ColumnType string

type Dao

type Dao struct {
	Name       string
	TableName  string
	SliceName  string
	Indexes    []*DaoIndex
	Fields     []*DaoField
	IsReadOnly bool
	HasTime    bool
}

type DaoField

type DaoField struct {
	Name       string
	ColumnName string
}

type DaoFindMethod

type DaoFindMethod struct {
	Name        string
	Args        []code
	IsSliceArg  bool
	IsSlice     bool
	ReturnType  code
	FindColumns []string
}

type DaoIndex

type DaoIndex struct {
	*Index
	Columns []*Column
}

type Daos

type Daos []*Dao

func (*Daos) Output

func (s *Daos) Output(rootPath, moduleName string) error

type Entities

type Entities []*Entity

func (*Entities) Output

func (s *Entities) Output(rootPath string, isProtoc, isJSON bool) error

type Entity

type Entity struct {
	Name          string
	SliceName     string
	TableName     string
	Fields        []*Field
	IsReadOnly    bool
	EntityPackage string
}

type EntityType

type EntityType string

type Field

type Field struct {
	Name       string
	ColumnName string
	FieldType  EntityType
}

type Index

type Index struct {
	Name         string   `yaml:"name"`
	IsPrimaryKey bool     `yaml:"is_primary_key"`
	IsUnique     bool     `yaml:"is_unique"`
	Columns      []string `yaml:"columns"`
}

type Model

type Model struct {
	Name       string
	SliceName  string
	DaoName    string
	Columns    []*ModelColumn
	IsReadOnly bool
	IDType     string
	HasTime    bool
	HasBytes   bool
	HasStrings bool
}

type ModelColumn

type ModelColumn struct {
	*Column
	CamelName       string
	CamelPluralName string
}

type Models

type Models []*Model

func (*Models) Output

func (s *Models) Output(rootPath, moduleName string) error

type Table

type Table struct {
	Name       string    `yaml:"name"`
	Columns    []*Column `yaml:"columns"`
	Indexes    []*Index  `yaml:"indexes"`
	IsReadOnly bool      `yaml:"is_read_only"`
}

type Tables

type Tables []*Table

func (*Tables) Daos

func (s *Tables) Daos() *Daos

func (*Tables) Entities

func (s *Tables) Entities() *Entities

func (*Tables) Load

func (s *Tables) Load(rootPath string) error

func (*Tables) Models

func (s *Tables) Models() *Models

func (*Tables) Output

func (s *Tables) Output(rootDir string) error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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