dbmap

package
v0.0.0-...-4021e5a Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidArguments = errors.New("invalid argument")

Functions

func GenerateCode

func GenerateCode(cfg Config, database *Database) error

func GenerateProto

func GenerateProto(cfg Config, database *Database) error

func ReadFile

func ReadFile(cfg *Config, configFile string)

Types

type Column

type Column struct {
	TableName       string
	TableSchema     string
	ColumnName      string
	OrdinalPosition int
	DataType        string
	UdtName         string
	ColumnDefault   string
	IsNullable      bool
	IsSequence      bool
	IsPrimaryKey    bool
}

Column The structure of a column

type Config

type Config struct {
	Database struct {
		Provider string `yaml:"provider"`
		Host     string `yaml:"host"`
		Port     string `yaml:"port"`
		Database string `yaml:"database"`
		Username string `yaml:"user"`
		Password string `yaml:"password"`
	} `yaml:"database"`
	Output struct {
		Path   string `yaml:"path"`
		Suffix string `yaml:"suffix"`
		Lang   string `yaml:"lang"`
	} `yaml:"output"`
	EmbedRelationships bool `yaml:"embed_relationships"`
	Proto              struct {
		Path        string `yaml:"path"`
		JavaPackage string `yaml:"java_package"`
		ObjCPrefix  string `yaml:"objc_prefix"`
		Version     string `yaml:"version"`
	} `yaml:"proto"`
	Generator struct {
		Schemas         []string `yaml:"schemas"`
		ExcludedTables  []string `yaml:"excluded_tables"`
		IndexedLookups  bool     `yaml:"indexed_lookups"`
		ExcludedColumns []struct {
			Tablename string   `yaml:"table"`
			Columns   []string `yaml:"columns"`
		} `yaml:"excluded_columns"`
		Mapping []struct {
			Tablename string `yaml:"table"`
			Queries   []struct {
				Name  string `yaml:"name"`
				Query string `yaml:"query"`
			} `yaml:"queries"`
		} `yaml:"mapping"`
		Transforms []struct {
			Tablename string `yaml:"table"`
			Xforms    struct {
				Select []struct {
					Columnname string `yaml:"column"`
					Datatype   string `yaml:"data_type"`
					Xform      string `yaml:"xform"`
				} `yaml:"select"`
				Insert []struct {
					Columnname string `yaml:"column"`
					Datatype   string `yaml:"data_type"`
					Xform      string `yaml:"xform"`
				}
				Update []struct {
					Columnname string `yaml:"column"`
					Datatype   string `yaml:"data_type"`
					Xform      string `yaml:"xform"`
				}
			} `yaml:"xforms"`
		} `yaml:"transforms"`
	} `yaml:"generator"`
}

Config The expected YAML configuration for generating code based on a database schema

type Database

type Database struct {
	DB      *sql.DB
	Schemas []Schema
}

The current database and the schema's we will generate code against

type ForeignColumns

type ForeignColumns struct {
	ForeignColumn   string
	LocalColumn     string
	OrdinalPosition int32
}

type ForeignRelation

type ForeignRelation struct {
	ForeignSchema string
	ForeignTable  string
	MapName       string
	Columns       []ForeignColumns
	RelationType  RelationType
}

type Index

type Index struct {
	TableSchema string
	TableName   string
	IndexName   string
	IndexType   IndexType
	Columns     []string
}

type IndexType

type IndexType int
const (
	PrimaryKey IndexType = 0
	Unique     IndexType = 1
	NonUnique  IndexType = 2
)

type Provider

type Provider interface {
	ReadDatabase() *Database
}

type RelationType

type RelationType int
const (
	ZeroOneOrMore RelationType = 0
	ManyToMany    RelationType = 1 // These are not supported because of the implicit cycles
)

type Schema

type Schema struct {
	SchemaName string
	Tables     []Table
}

The structure of a schema

type Table

type Table struct {
	TableName   string
	TableSchema string
	Columns     []Column
	Indexes     []Index
	Relations   []ForeignRelation
}

The structure of a table

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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