Documentation ¶
Overview ¶
Copyright (C) 2021 Pau Sanchez
Copyright (C) 2021 Pau Sanchez ¶
Copyright (C) 2021 Pau Sanchez ¶
Copyright (C) 2021 Pau Sanchez ¶
Copyright (C) 2021 Pau Sanchez ¶
Copyright (C) 2021 Pau Sanchez ¶
Copyright (C) 2021 Pau Sanchez ¶
Copyright (C) 2021 Pau Sanchez ¶
Copyright (C) 2021 Pau Sanchez
Index ¶
- Constants
- func IdentityEscape(text string) string
- func MarkdownEscape(text string) string
- type DbConnection
- type DbFieldLayout
- type DbLayout
- func (dbLayout *DbLayout) AddField(schema string, table string, field DbFieldLayout) error
- func (dbLayout *DbLayout) GetField(schema string, table string, field string) *DbFieldLayout
- func (dbLayout *DbLayout) GetOrCreateSchema(schema string) *DbSchemaLayout
- func (dbLayout *DbLayout) GetTable(schema string, table string) *DbTableLayout
- func (dbLayout *DbLayout) MergeFrom(otherLayout *DbLayout, preserveComments bool, preserveMissing bool)
- func (dbLayout *DbLayout) PrintDbml(out io.Writer, addNotes bool)
- func (dbLayout *DbLayout) PrintMarkdown(out io.Writer, lineLength int)
- func (dbLayout *DbLayout) PrintText(out io.Writer, lineLength int)
- func (dbLayout *DbLayout) RebuildLookups()
- func (dbLayout *DbLayout) Sort()
- type DbLayoutTextParser
- type DbSchemaLayout
- func (dbSchemaLayout *DbSchemaLayout) GetOrCreateTable(table string) *DbTableLayout
- func (dbSchemaLayout *DbSchemaLayout) MergeFrom(otherSchemaLayout *DbSchemaLayout, preserveComments bool, preserveMissing bool, ...)
- func (dbSchemaLayout *DbSchemaLayout) RebuildLookups()
- func (dbSchemaLayout *DbSchemaLayout) Sort()
- type DbTableLayout
- type EscapeFunc
- type ItemIdentifier
- type WordWrap
Constants ¶
const ( DriverPostgres = "pgx" DriverMysql = "mysql" DriverMssql = "sqlserver" DriverSqlite = "sqlite3" )
const ( ITEM_ID_UNKNOWN = 0 ITEM_ID_LAYOUT = 1 ITEM_ID_SCHEMA = 2 ITEM_ID_TABLE = 3 ITEM_ID_FIELD = 4 )
const ( DbTypePostgres = "PostgreSQL" DbTypeMysql = "MySQL" DbTypeMssql = "MSSQL" DbTypeSqlite = "SQLite" )
const DeletedPrefix = "__DELETED__"
const NoDbSchemaLayoutName = ""
Variables ¶
This section is empty.
Functions ¶
func IdentityEscape ¶
----------------------------------------------------------------------------- IdentityEscape
It does nothing, it just returns what it gets -----------------------------------------------------------------------------
func MarkdownEscape ¶
----------------------------------------------------------------------------- MarkdownEscape
Escape markdown characters -----------------------------------------------------------------------------
Types ¶
type DbConnection ¶
type DbConnection struct {
// contains filtered or unexported fields
}
func DbConnect ¶
func DbConnect( dbtype string, dbhost string, dbport uint, dbuser string, dbpass string, dbname string, ) ( *DbConnection, error, )
----------------------------------------------------------------------------- DbConnect
Helper method to connect to database. -----------------------------------------------------------------------------
func NewDbConnection ¶
func NewDbConnection() *DbConnection
----------------------------------------------------------------------------- NewDbConnection -----------------------------------------------------------------------------
func (*DbConnection) Close ¶
func (conn *DbConnection) Close()
----------------------------------------------------------------------------- Close -----------------------------------------------------------------------------
func (*DbConnection) GetConnectionString ¶
func (conn *DbConnection) GetConnectionString() string
----------------------------------------------------------------------------- GetConnectionString -----------------------------------------------------------------------------
func (*DbConnection) GetDb ¶
func (conn *DbConnection) GetDb() *sql.DB
----------------------------------------------------------------------------- GetDb -----------------------------------------------------------------------------
func (*DbConnection) GetDriverType ¶
func (conn *DbConnection) GetDriverType() string
----------------------------------------------------------------------------- GetDriverType -----------------------------------------------------------------------------
func (*DbConnection) GetLayout ¶
func (conn *DbConnection) GetLayout() (*DbLayout, error)
----------------------------------------------------------------------------- GetLayout -----------------------------------------------------------------------------
type DbFieldLayout ¶
type DbFieldLayout struct { Name string Type string IsPrimaryKey bool IsUnique bool IsNullable bool Length uint32 Default string Comment string }
func NewDbFieldLayout ¶
func NewDbFieldLayout(name string) DbFieldLayout
----------------------------------------------------------------------------- NewDbFieldLayout -----------------------------------------------------------------------------
type DbLayout ¶
type DbLayout struct { Name string Type string // DbTypeXXX Comment string Schemas []*DbSchemaLayout SchemaLookup map[string]*DbSchemaLayout }
func NewDbLayout ¶
----------------------------------------------------------------------------- NewDbLayout -----------------------------------------------------------------------------
func NewDbLayoutFromParsedFile ¶
----------------------------------------------------------------------------- NewDbLayoutFromParsedFile -----------------------------------------------------------------------------
func NewDbLayoutFromParsedString ¶
----------------------------------------------------------------------------- NewDbLayoutFromParsedString
It will try to parse things with a simple algorithm, if the lines are really malformed, then it won't be able to do anything -----------------------------------------------------------------------------
func (*DbLayout) AddField ¶
func (dbLayout *DbLayout) AddField(schema string, table string, field DbFieldLayout) error
----------------------------------------------------------------------------- AddField -----------------------------------------------------------------------------
func (*DbLayout) GetField ¶
func (dbLayout *DbLayout) GetField(schema string, table string, field string) *DbFieldLayout
----------------------------------------------------------------------------- GetField -----------------------------------------------------------------------------
func (*DbLayout) GetOrCreateSchema ¶
func (dbLayout *DbLayout) GetOrCreateSchema(schema string) *DbSchemaLayout
----------------------------------------------------------------------------- GetOrCreateSchema -----------------------------------------------------------------------------
func (*DbLayout) GetTable ¶
func (dbLayout *DbLayout) GetTable(schema string, table string) *DbTableLayout
----------------------------------------------------------------------------- GetTable -----------------------------------------------------------------------------
func (*DbLayout) MergeFrom ¶
func (dbLayout *DbLayout) MergeFrom( otherLayout *DbLayout, preserveComments bool, preserveMissing bool, )
----------------------------------------------------------------------------- MergeFrom
Merges schemas, tables and fields that exist on provided layout by preserving the order from the current layout. -----------------------------------------------------------------------------
func (*DbLayout) PrintDbml ¶
----------------------------------------------------------------------------- PrintDbml
Print DBML document with table schemas ¶
More info:
-----------------------------------------------------------------------------
func (*DbLayout) PrintMarkdown ¶
----------------------------------------------------------------------------- PrintMarkdown
Print markdown document with all the information -----------------------------------------------------------------------------
func (*DbLayout) PrintText ¶
----------------------------------------------------------------------------- PrintText
Print a text document, which will be similar to markdown but without escaping anything at all. -----------------------------------------------------------------------------
func (*DbLayout) RebuildLookups ¶
func (dbLayout *DbLayout) RebuildLookups()
----------------------------------------------------------------------------- RebuildLookups
Rebuild internal lookup schemas, tables and fields -----------------------------------------------------------------------------
type DbLayoutTextParser ¶
type DbLayoutTextParser struct { LayoutPtr *DbLayout SchemaPtr *DbSchemaLayout TablePtr *DbTableLayout FieldPtr *DbFieldLayout // previous comment lines LastItemParsed ItemIdentifier Comment []string }
----------------------------------------------------------------------------- DbLayoutTextParser
Each item points to the current field/table/schema/layout that we are parsing -----------------------------------------------------------------------------
func NewDbLayoutTextParser ¶
func NewDbLayoutTextParser(layoutPtr *DbLayout) DbLayoutTextParser
----------------------------------------------------------------------------- NewDbLayoutTextParser -----------------------------------------------------------------------------
func (*DbLayoutTextParser) AssignCommentsToLastItem ¶
func (layoutParser *DbLayoutTextParser) AssignCommentsToLastItem()
----------------------------------------------------------------------------- AssignCommentsToLastItem -----------------------------------------------------------------------------
func (*DbLayoutTextParser) ParseField ¶
func (layoutParser *DbLayoutTextParser) ParseField(line string)
----------------------------------------------------------------------------- ParseField
- field_name [type / ....]
-----------------------------------------------------------------------------
func (*DbLayoutTextParser) ParseHeader ¶
func (layoutParser *DbLayoutTextParser) ParseHeader(line string)
----------------------------------------------------------------------------- NewDbLayoutTextParser -----------------------------------------------------------------------------
func (*DbLayoutTextParser) ParseLine ¶
func (layoutParser *DbLayoutTextParser) ParseLine(line string)
----------------------------------------------------------------------------- ParseLine -----------------------------------------------------------------------------
type DbSchemaLayout ¶
type DbSchemaLayout struct { Name string Comment string Tables []*DbTableLayout TableLookup map[string]*DbTableLayout }
func NewDbSchemaLayout ¶
func NewDbSchemaLayout(name string) DbSchemaLayout
----------------------------------------------------------------------------- NewDbSchemaLayout -----------------------------------------------------------------------------
func (*DbSchemaLayout) GetOrCreateTable ¶
func (dbSchemaLayout *DbSchemaLayout) GetOrCreateTable(table string) *DbTableLayout
----------------------------------------------------------------------------- GetOrCreateTable -----------------------------------------------------------------------------
func (*DbSchemaLayout) MergeFrom ¶
func (dbSchemaLayout *DbSchemaLayout) MergeFrom( otherSchemaLayout *DbSchemaLayout, preserveComments bool, preserveMissing bool, rebuildLookups bool, )
----------------------------------------------------------------------------- MergeFrom
Merges tables and fields that exist on provided layout by preserving the order from the current layout. -----------------------------------------------------------------------------
func (*DbSchemaLayout) RebuildLookups ¶
func (dbSchemaLayout *DbSchemaLayout) RebuildLookups()
----------------------------------------------------------------------------- RebuildLookups
Rebuild internal lookup tables and fields -----------------------------------------------------------------------------
func (*DbSchemaLayout) Sort ¶
func (dbSchemaLayout *DbSchemaLayout) Sort()
----------------------------------------------------------------------------- Sort
Sort inner objects in lexicographical order -----------------------------------------------------------------------------
type DbTableLayout ¶
type DbTableLayout struct { Name string Comment string Fields []*DbFieldLayout FieldLookup map[string]*DbFieldLayout }
func NewDbTableLayout ¶
func NewDbTableLayout(name string) DbTableLayout
----------------------------------------------------------------------------- NewDbTableLayout -----------------------------------------------------------------------------
func (*DbTableLayout) AddField ¶
func (dbTableLayout *DbTableLayout) AddField(field DbFieldLayout) error
----------------------------------------------------------------------------- AddField -----------------------------------------------------------------------------
func (*DbTableLayout) MergeFrom ¶
func (dbTableLayout *DbTableLayout) MergeFrom( otherTableLayout *DbTableLayout, preserveComments bool, preserveMissing bool, rebuildLookups bool, )
----------------------------------------------------------------------------- MergeFrom -----------------------------------------------------------------------------
func (*DbTableLayout) RebuildLookups ¶
func (dbTableLayout *DbTableLayout) RebuildLookups()
----------------------------------------------------------------------------- RebuildLookups
Rebuild internal field lookups -----------------------------------------------------------------------------
func (*DbTableLayout) Sort ¶
func (dbTableLayout *DbTableLayout) Sort()
----------------------------------------------------------------------------- Sort
Sort inner objects in lexicographical order -----------------------------------------------------------------------------
type EscapeFunc ¶
----------------------------------------------------------------------------- EscapeFunc -----------------------------------------------------------------------------
type ItemIdentifier ¶
type ItemIdentifier int
type WordWrap ¶
type WordWrap struct { MaxLength int // controls max line length Indent int // controls number of spaces each line starts with }
----------------------------------------------------------------------------- WordWrap -----------------------------------------------------------------------------
func NewWordWrap ¶
----------------------------------------------------------------------------- PrintMarkdown -----------------------------------------------------------------------------