use super::{CastEntry, CastStrategy};
use crate::stdlib::PylonType::{
BigInt, Bool, Datetime, Decimal, Duration, Float32, Float64, Int16, Int32, Int64, Json, LocalDate, LocalDatetime,
LocalTime, Str, Uuid,
};
use CastStrategy::{Function as Fn, Implicit, Sql};
fn c(
source: impl Into<crate::stdlib::PylonType>,
target: impl Into<crate::stdlib::PylonType>,
strategy: CastStrategy,
) -> CastEntry {
CastEntry {
source: source.into(),
target: target.into(),
strategy,
}
}
pub(super) fn build() -> Vec<CastEntry> {
vec![
c(Int16, Int32, Implicit),
c(Int16, Int64, Implicit),
c(Int16, Float32, Implicit),
c(Int16, Float64, Implicit),
c(Int16, Decimal, Implicit),
c(Int16, BigInt, Implicit),
c(Int32, Int64, Implicit),
c(Int32, Float64, Implicit),
c(Int32, Decimal, Implicit),
c(Int32, BigInt, Implicit),
c(Int64, Decimal, Implicit),
c(Int64, BigInt, Implicit),
c(Float32, Float64, Implicit),
c(Int64, Int32, Sql("int4")),
c(Int64, Int16, Sql("int2")),
c(Int32, Int16, Sql("int2")),
c(Float64, Float32, Sql("float4")),
c(Float64, Int64, Sql("int8")),
c(Float64, Decimal, Sql("numeric")),
c(Decimal, Float64, Sql("float8")),
c(Decimal, Int64, Sql("int8")),
c(Decimal, BigInt, Sql("numeric")),
c(BigInt, Int64, Sql("int8")),
c(BigInt, Decimal, Sql("numeric")),
c(Bool, Int16, Sql("int2")),
c(Bool, Int32, Sql("int4")),
c(Bool, Int64, Sql("int8")),
c(Str, Uuid, Sql("uuid")),
c(LocalDatetime, LocalDate, Sql("date")),
c(LocalDatetime, LocalTime, Sql("time")),
c(Str, Int16, Fn("to_int16")),
c(Str, Int32, Fn("to_int32")),
c(Str, Int64, Fn("to_int64")),
c(Str, Float32, Fn("to_float32")),
c(Str, Float64, Fn("to_float64")),
c(Str, Decimal, Fn("to_decimal")),
c(Str, BigInt, Fn("to_bigint")),
c(Str, Bool, Fn("to_bool")),
c(Str, Datetime, Fn("to_datetime")),
c(Str, Json, Fn("to_json")),
c(Int16, Str, Fn("to_str")),
c(Int32, Str, Fn("to_str")),
c(Int64, Str, Fn("to_str")),
c(Float32, Str, Fn("to_str")),
c(Float64, Str, Fn("to_str")),
c(Decimal, Str, Fn("to_str")),
c(BigInt, Str, Fn("to_str")),
c(Bool, Str, Fn("to_str")),
c(Uuid, Str, Fn("to_str")),
c(Datetime, Str, Fn("to_str")),
c(Duration, Str, Fn("to_str")),
c(Json, Str, Fn("to_str")),
c(Int16, Bool, Fn("to_bool")),
c(Int32, Bool, Fn("to_bool")),
c(Int64, Bool, Fn("to_bool")),
]
}