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¶
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¶
Adds a new column to the table by appending it to the Columns
slice.
Parameters:¶
- column (Column): The column to add.
GetPrimaryColumns¶
Returns a slice of Column
objects that are marked as primary keys.
Returns:¶
- ([]Column): A list of primary key columns.
GetTableNameInCase¶
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¶
Retrieves primary key columns that are not of "Date" or "Timestamp" type.
Returns:¶
- ([]Column): A list of non-date primary key columns.
GetPrimaryColumnJavaTypesAndVariables¶
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¶
Returns a comma-separated string of camel case names for all primary key columns.
Returns:¶
- (string): Comma-separated names of primary key columns.
GetFirstPrimaryColumn¶
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¶
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¶
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¶
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¶
```go 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 }