Table

Monstarillo table

Structs

None

Table

Represents the structure of a database table, including its name, type, columns, and foreign key relationships.

Fields:

  • TableName (string): The name of the table.
  • DatabaseType (string): The type of database (e.g., SQL, NoSQL).
  • Columns ([]Column): A collection of columns present in the table.
  • ForeignKeys ([]ForeignKey): The foreign key relationships defined in the table.
  • ReferencedForeignKeys ([]ForeignKey): The foreign key relationships referencing this table.
  • GuiListTable (GuiListTable): Represents GUI list table-related properties.

Functions

NewTable

func NewTable(tableName, databaseType string) Table

Creates and returns a new Table instance with the specified table name and database type.

Parameters:

  • tableName (string): The name of the table to create.
  • databaseType (string): The database type (e.g., “SQL”).

Returns:

  • (Table): A newly initialized Table instance.

AddColumn

func (t *Table) AddColumn(column Column)

Adds a new column to the table by appending it to the Columns slice.

Parameters:

  • column (Column): The column to add.

GetPrimaryColumns

func (t *Table) GetPrimaryColumns() []Column

Returns a slice of Column objects that are marked as primary keys.

Returns:

  • ([]Column): A list of primary key columns.

GetTableNameInCase

func (t *Table) GetTableNameInCase(caseToReturn string) string

Formats the table name into the specified case style (e.g., camel, pascal, snake, kebab).

Parameters:

  • caseToReturn (string): The desired case style.

Returns:

  • (string): The table name in the specified case.

GetPrimaryNonDateColumns

func (t *Table) GetPrimaryNonDateColumns() []Column

Retrieves primary key columns that are not of “Date” or “Timestamp” type.

Returns:

  • ([]Column): A list of non-date primary key columns.

GetPrimaryColumnJavaTypesAndVariables

func (t *Table) GetPrimaryColumnJavaTypesAndVariables() string

Returns a string containing Java types and variables for primary key columns, formatted as "Type1 var1, Type2 var2".

Returns:

  • (string): Formatted string of types and variable names.

GetPrimaryColumnVariables

func (t *Table) GetPrimaryColumnVariables() string

Returns a comma-separated string of camel case names for all primary key columns.

Returns:

  • (string): Comma-separated names of primary key columns.

GetFirstPrimaryColumn

func (t *Table) GetFirstPrimaryColumn() Column

Returns the first column marked as a primary key. Returns an empty Column if no primary key is found.

Returns:

  • (Column): The first primary key column or an empty column.

GetFirstPrimaryColumnJavaDataType

func (t *Table) GetFirstPrimaryColumnJavaDataType() string

Returns the Java data type of the first primary key column. Returns an empty string if none exists.

Returns:

  • (string): Java data type of the first primary key column.

GetFirstPrimaryColumnJavaFirstUnitTestValue

func (t *Table) GetFirstPrimaryColumnJavaFirstUnitTestValue() string

Returns the Java first unit test value of the first primary key column.

Returns:

  • (string): Unit test value of the first primary key column.

GetFirstPrimaryColumnSetString

func (t *Table) GetFirstPrimaryColumnSetString() string

Retrieves the set string of the first primary key column, if one exists.

Returns:

  • (string): The set string of the first primary key column.

Example Usage

package main

import (
 "fmt"
)

type Column struct {
 Name          string
 IsPrimaryKey  bool
 JavaDataType  string
 CamelCaseName string
}

func (c *Column) GetJavaDataType() string {
 return c.JavaDataType
}

func (c *Column) GetCamelCaseColumnName() string {
 return c.CamelCaseName
}