Some checks failed
CI / Lint (push) Successful in -27m59s
CI / Test (1.25) (push) Successful in -27m46s
CI / Test (1.24) (push) Failing after 59s
CI / Build (push) Successful in -28m14s
Integration Tests / Integration Tests (push) Failing after -28m16s
Release / Build and Release (push) Successful in 1m1s
feat(templ): ✨ added templ to command line that reads go template and outputs code Reviewed-on: #1 Co-authored-by: Hein <hein.puth@gmail.com> Co-committed-by: Hein <hein.puth@gmail.com>
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
package commontypes
|
|
|
|
// PHPTypeMap maps PostgreSQL types to PHP types
|
|
var PHPTypeMap = map[string]string{
|
|
// Integer types
|
|
"integer": "int",
|
|
"int": "int",
|
|
"int4": "int",
|
|
"smallint": "int",
|
|
"int2": "int",
|
|
"bigint": "int",
|
|
"int8": "int",
|
|
"serial": "int",
|
|
"bigserial": "int",
|
|
"smallserial": "int",
|
|
|
|
// String types
|
|
"text": "string",
|
|
"varchar": "string",
|
|
"char": "string",
|
|
"character": "string",
|
|
"citext": "string",
|
|
"bpchar": "string",
|
|
"uuid": "string",
|
|
|
|
// Boolean
|
|
"boolean": "bool",
|
|
"bool": "bool",
|
|
|
|
// Float types
|
|
"real": "float",
|
|
"float4": "float",
|
|
"double precision": "float",
|
|
"float8": "float",
|
|
"numeric": "float",
|
|
"decimal": "float",
|
|
|
|
// Date/Time types
|
|
"timestamp": "\\DateTime",
|
|
"timestamp without time zone": "\\DateTime",
|
|
"timestamp with time zone": "\\DateTime",
|
|
"timestamptz": "\\DateTime",
|
|
"date": "\\DateTime",
|
|
"time": "\\DateTime",
|
|
"time without time zone": "\\DateTime",
|
|
"time with time zone": "\\DateTime",
|
|
"timetz": "\\DateTime",
|
|
|
|
// Binary
|
|
"bytea": "string",
|
|
|
|
// JSON
|
|
"json": "array",
|
|
"jsonb": "array",
|
|
}
|
|
|
|
// SQLToPhp converts SQL types to PHP types
|
|
func SQLToPhp(sqlType string, nullable bool) string {
|
|
baseType := ExtractBaseType(sqlType)
|
|
|
|
phpType, ok := PHPTypeMap[baseType]
|
|
if !ok {
|
|
phpType = "mixed"
|
|
}
|
|
|
|
// PHP 7.1+ supports nullable types with ?Type syntax
|
|
if !nullable && phpType != "mixed" {
|
|
return "?" + phpType
|
|
}
|
|
|
|
return phpType
|
|
}
|