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>
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package commontypes
|
|
|
|
import "strings"
|
|
|
|
// CSharpTypeMap maps PostgreSQL types to C# types
|
|
var CSharpTypeMap = map[string]string{
|
|
// Integer types
|
|
"integer": "int",
|
|
"int": "int",
|
|
"int4": "int",
|
|
"smallint": "short",
|
|
"int2": "short",
|
|
"bigint": "long",
|
|
"int8": "long",
|
|
"serial": "int",
|
|
"bigserial": "long",
|
|
"smallserial": "short",
|
|
|
|
// String types
|
|
"text": "string",
|
|
"varchar": "string",
|
|
"char": "string",
|
|
"character": "string",
|
|
"citext": "string",
|
|
"bpchar": "string",
|
|
"uuid": "Guid",
|
|
|
|
// Boolean
|
|
"boolean": "bool",
|
|
"bool": "bool",
|
|
|
|
// Float types
|
|
"real": "float",
|
|
"float4": "float",
|
|
"double precision": "double",
|
|
"float8": "double",
|
|
"numeric": "decimal",
|
|
"decimal": "decimal",
|
|
|
|
// Date/Time types
|
|
"timestamp": "DateTime",
|
|
"timestamp without time zone": "DateTime",
|
|
"timestamp with time zone": "DateTimeOffset",
|
|
"timestamptz": "DateTimeOffset",
|
|
"date": "DateTime",
|
|
"time": "TimeSpan",
|
|
"time without time zone": "TimeSpan",
|
|
"time with time zone": "DateTimeOffset",
|
|
"timetz": "DateTimeOffset",
|
|
|
|
// Binary
|
|
"bytea": "byte[]",
|
|
|
|
// JSON
|
|
"json": "string",
|
|
"jsonb": "string",
|
|
}
|
|
|
|
// SQLToCSharp converts SQL types to C# types
|
|
func SQLToCSharp(sqlType string, nullable bool) string {
|
|
baseType := ExtractBaseType(sqlType)
|
|
|
|
csType, ok := CSharpTypeMap[baseType]
|
|
if !ok {
|
|
csType = "object"
|
|
}
|
|
|
|
// Handle nullable value types (reference types are already nullable)
|
|
if !nullable && csType != "string" && !strings.HasSuffix(csType, "[]") && csType != "object" {
|
|
return csType + "?"
|
|
}
|
|
|
|
return csType
|
|
}
|