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.7 KiB
Go
73 lines
1.7 KiB
Go
package commontypes
|
|
|
|
// RustTypeMap maps PostgreSQL types to Rust types
|
|
var RustTypeMap = map[string]string{
|
|
// Integer types
|
|
"integer": "i32",
|
|
"int": "i32",
|
|
"int4": "i32",
|
|
"smallint": "i16",
|
|
"int2": "i16",
|
|
"bigint": "i64",
|
|
"int8": "i64",
|
|
"serial": "i32",
|
|
"bigserial": "i64",
|
|
"smallserial": "i16",
|
|
|
|
// String types
|
|
"text": "String",
|
|
"varchar": "String",
|
|
"char": "String",
|
|
"character": "String",
|
|
"citext": "String",
|
|
"bpchar": "String",
|
|
"uuid": "String",
|
|
|
|
// Boolean
|
|
"boolean": "bool",
|
|
"bool": "bool",
|
|
|
|
// Float types
|
|
"real": "f32",
|
|
"float4": "f32",
|
|
"double precision": "f64",
|
|
"float8": "f64",
|
|
"numeric": "f64",
|
|
"decimal": "f64",
|
|
|
|
// Date/Time types (using chrono crate)
|
|
"timestamp": "NaiveDateTime",
|
|
"timestamp without time zone": "NaiveDateTime",
|
|
"timestamp with time zone": "DateTime<Utc>",
|
|
"timestamptz": "DateTime<Utc>",
|
|
"date": "NaiveDate",
|
|
"time": "NaiveTime",
|
|
"time without time zone": "NaiveTime",
|
|
"time with time zone": "DateTime<Utc>",
|
|
"timetz": "DateTime<Utc>",
|
|
|
|
// Binary
|
|
"bytea": "Vec<u8>",
|
|
|
|
// JSON
|
|
"json": "serde_json::Value",
|
|
"jsonb": "serde_json::Value",
|
|
}
|
|
|
|
// SQLToRust converts SQL types to Rust types
|
|
func SQLToRust(sqlType string, nullable bool) string {
|
|
baseType := ExtractBaseType(sqlType)
|
|
|
|
rustType, ok := RustTypeMap[baseType]
|
|
if !ok {
|
|
rustType = "String"
|
|
}
|
|
|
|
// Handle nullable types with Option<T>
|
|
if nullable {
|
|
return rustType
|
|
}
|
|
|
|
return "Option<" + rustType + ">"
|
|
}
|