Documentation ¶
Index ¶
- Variables
- func GenerateCreateTableSQL(dbType adapters.DBInterface, allStructs ...interface{}) (string, error)
- func GenerateCreateTableSQLForSingleTable(tableName string, fieldMap map[string]string) (string, error)
- func GenerateDropTableSQL(dbType adapters.DBInterface, allStructs ...interface{}) (string, error)
- func GenerateDropTableSQLForSingleTable(tableName string) (string, error)
- func GenerateInsertIntoTableSQL(s interface{}) (string, error)
- func ParseTagsAndTypes(dbType adapters.DBInterface, field *structs.Field) (string, error)
Constants ¶
This section is empty.
Variables ¶
var ( CreateTableTemplate = `` /* 130-byte string literal not displayed */ DropTableTemplate = `DROP TABLE {{ .TableName }};` InsertIntoTableTemplate = `INSERT INTO {{ .TableName }}({{ .FieldList }}) VALUES({{ .ValueList }});` )
Functions ¶
func GenerateCreateTableSQL ¶
func GenerateCreateTableSQL(dbType adapters.DBInterface, allStructs ...interface{}) (string, error)
GenerateCreateTableSQL basically generates "CREATE TABLE" SQL statements with given structs (single or multiple). Mainly converts namings(table name and field names) into the snake case and handles tags to provide SQL specific options. Example:
type HelloWorld struct { Name string Surname string }
createSQL, err := GenerateCreateTableSQL(nil, HelloWorld{})
func GenerateCreateTableSQLForSingleTable ¶
func GenerateCreateTableSQLForSingleTable(tableName string, fieldMap map[string]string) (string, error)
GenerateCreateTableSQLForSingleTable is very similar function to main one; however, it does the main job to traverse on the fields and converts to the corresponding SQL statements.
func GenerateDropTableSQL ¶
func GenerateDropTableSQL(dbType adapters.DBInterface, allStructs ...interface{}) (string, error)
GenerateDropTableSQL is simply generates "DROP TABLE" SQL statements with given multiple structs.
func GenerateDropTableSQLForSingleTable ¶
GenerateDropTableSQLForSingleTable is very similar to the general function about drop table; however, it does the main job to generate "DROP TABLE" statement for the single table
func GenerateInsertIntoTableSQL ¶
GenerateInsertIntoTableSQL basically generates "INSERT INTO TABLE" SQL statements with given single struct.
func ParseTagsAndTypes ¶
ParseTagsAndTypes: in short, checks the field tags and types on the struct and converts into the right SQL statements.
Most of the basic Types are supported currently in the dbtypes section.
Current Supported Tags: length: 100 -> Only applicable to string type autoincrement -> Converts field data type to corresponding auto increment data type in supported database extra -> Feed your custom SQL Statements for related field
Types ¶
This section is empty.