schema_store

package
v0.9.71 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 License: Apache-2.0 Imports: 9 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCreateSchemaStatement

func GetCreateSchemaStatement(db *sql.DB, schemaName string) (error, string)

func GetTablesFromDB

func GetTablesFromDB(db *sql.DB, schema string) ([]string, error)

Types

type Column

type Column struct {
	//Idx          int               `json:"idx"`
	Name         string            `json:"name"`
	Type         ColumnType        `json:"type"`
	RawType      string            `json:"raw_type"`
	DefaultVal   ColumnValueString `json:"default_value_string"`
	IsNullable   bool              `json:"is_nullable"`
	IsUnsigned   bool              `json:"is_unsigned"`
	IsPrimaryKey bool              `json:"is_primary_key"`
	IsGenerated  bool              `json:"is_generated"`
}

Column

func (Column) EqualsDefault

func (col Column) EqualsDefault(value interface{}) bool

type ColumnType added in v0.9.59

type ColumnType = int
const (
	TypeNumber    ColumnType = iota + 1 // tinyint, smallint, int, bigint, year
	TypeMediumInt                       // medium int
	TypeFloat                           // float, double
	TypeEnum                            // enum
	TypeSet                             // set
	TypeString                          // other
	TypeDatetime                        // datetime
	TypeTimestamp                       // timestamp
	TypeDate                            // date
	TypeTime                            // time
	TypeBit                             // bit
	TypeJson                            // json
	TypeDecimal                         // decimal
)

type ColumnValueString

type ColumnValueString struct {
	ValueString string `json:"value"`
	IsNull      bool   `json:"is_null"`
}

ColumnValueString is the same as sql.NullString We define it here in case we want to extend it.

func (*ColumnValueString) Equals

func (v1 *ColumnValueString) Equals(v2 *ColumnValueString) bool

type Schema

type Schema map[string]*Table

func GetSchemaFromDB

func GetSchemaFromDB(db *sql.DB, dbName string) (Schema, error)

type SchemaStore

type SchemaStore interface {
	GetSchema(database string) (Schema, error)
	InvalidateSchemaCache(schema string)
	InvalidateCache()
	IsInCache(dbName string) bool
	Close()
}

func NewSimpleSchemaStoreFromDBConn

func NewSimpleSchemaStoreFromDBConn(db *sql.DB) (SchemaStore, error)

type SimpleSchemaStore

type SimpleSchemaStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSimpleSchemaStore

func NewSimpleSchemaStore(dbCfg *config.DBConfig) (*SimpleSchemaStore, error)

func (*SimpleSchemaStore) Close

func (store *SimpleSchemaStore) Close()

func (*SimpleSchemaStore) GetSchema

func (store *SimpleSchemaStore) GetSchema(dbName string) (Schema, error)

func (*SimpleSchemaStore) InvalidateCache

func (store *SimpleSchemaStore) InvalidateCache()

func (*SimpleSchemaStore) InvalidateSchemaCache

func (store *SimpleSchemaStore) InvalidateSchemaCache(schema string)

func (*SimpleSchemaStore) IsInCache

func (store *SimpleSchemaStore) IsInCache(dbName string) bool

type Table

type Table struct {
	Version string `json:"version"`
	Schema  string `json:"db_name"`
	Name    string `json:"table_name"`

	Columns            []Column            `json:"columns"`
	PrimaryKeyColumns  []Column            `json:"primary_key_columns"`
	UniqueKeyColumnMap map[string][]string `json:"unique_key_columns"`
	// contains filtered or unexported fields
}

Table

func GetTableDefFromDB

func GetTableDefFromDB(db *sql.DB, dbName string, tableName string) (*Table, error)

func (*Table) Column

func (t *Table) Column(col string) (c *Column, ok bool)

func (*Table) ColumnNames

func (t *Table) ColumnNames() []string

func (*Table) MustColumn

func (t *Table) MustColumn(col string) *Column

func (*Table) RenameColumn

func (t *Table) RenameColumn(origin, target string)

func (*Table) ReplaceSqlPrefix added in v0.9.59

func (t *Table) ReplaceSqlPrefix() string

Jump to

Keyboard shortcuts

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