::xotcl::Object
::xo::db::sql
::xotcl::Object create ::xo::db::sql
Methods
proc datatype_constraint
::60140 proc datatype_constraint {type table att} {
# for postgres, we do not need type specific constraints
return ""
}
proc date_trunc
::60140 proc date_trunc {field date} {
return "date_trunc('$field',$date)"
}
proc date_trunc_expression
::60140 proc date_trunc_expression {field date date_string} {
return "date_trunc('$field',$date) = '$date_string'"
}
proc map_datatype
::60140 proc map_datatype type {
switch -- $type {
string { set type text }
long_text { set type text }
date { set type "timestamp with time zone" }
ltree { set type [expr {[::xo::db::has_ltree] ? "ltree" : "text" }] }
}
return $type
}
proc map_function_name
::60140 proc map_function_name sql {
return $sql
}
proc select
::60140 proc select {-vars:required -from:required {-where ""} {-groupby ""} {-limit ""} {-offset ""} {-start ""} {-orderby ""} {-map_function_names false}} {
set where_clause [expr {$where ne "" ? "WHERE $where" : ""}]
set offset_clause [expr {$offset ne "" ? "OFFSET $offset" : ""}]
set limit_clause [expr {$limit ne "" ? "LIMIT $limit" : ""}]
set order_clause [expr {$orderby ne "" ? "ORDER BY $orderby" : ""}]
set group_clause [expr {$groupby ne "" ? "GROUP BY $groupby" : ""}]
return "SELECT $vars FROM $from $where_clause $group_clause $order_clause $limit_clause $offset_clause"
}
proc since_interval_condition
::60140 proc since_interval_condition {var interval} {
set since [clock format [clock scan "-$interval"] -format "%Y-%m-%d %T"]
return "$var > TO_TIMESTAMP('$since','YYYY-MM-DD HH24:MI:SS')"
}