Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateStruct ¶
func CreateStruct(tt []TableDescriptor, tableName string, withJson bool) string
CreateStruct creates a new struct with the camelized name of the table from the table descriptor. If withJson is true, creates the struct tags for json
func GetDbConnection ¶
func GetDbConnection(c *ConnectionString) *sql.DB
GetDbConnection returns the connection to the database using ConnectionString
Types ¶
type ConnectionString ¶
type ConnectionString struct {
// Host specifies the hostname or IP address of the database server.
Host string
// Port is the port number on which the database server is listening.
Port uint16
// Timeout is the maximum amount of time (in seconds) to wait for the database connection to be established.
Timeout uint16
// User is the username used for authenticating to the database.
User string
// Password is the password associated with the User for database authentication.
Password string
// DatabaseName is the name of the specific database to connect to on the server.
DatabaseName string
}
ConnectionString defines the details required to establish a connection to a database.
type TableDescriptor ¶
type TableDescriptor struct {
// Field is the name of the column in the table.
Field string
// Type is the data type of the column, as defined in the database schema (e.g., INT, VARCHAR(255)).
Type string
// Null indicates whether the column can contain NULL values ("YES" or "NO").
Null string
// Key specifies if the column is part of a key (e.g., "PRI" for primary key, "UNI" for unique key).
Key string
// Default is the default value assigned to the column, if any. A nil value indicates no default.
Default *string
// Extra contains additional information about the column, such as auto-increment settings.
Extra string
}
TableDescriptor represents the schema details of a single column in a database table.
func GetTableDescriptor ¶ added in v1.0.0
func GetTableDescriptor(conn *sql.DB, tableName string) []TableDescriptor
GetTableDescriptor returns the information from sql "describe <tableName>" query in a TableDescriptor struct
Click to show internal directories.
Click to hide internal directories.