You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ssql-postgresql/ssql-postgresql.scm

49 lines
1.4 KiB
Scheme

(module ssql-postgresql
(*postgresql-translator*)
(cond-expand
(chicken-4
(import chicken scheme)
(use ssql postgresql foops data-structures))
(chicken-5
(import scheme ssql postgresql foops (chicken format) (chicken string))))
(define *postgresql-translator*
(let ((type->sql-converters
`((,boolean? . boolean->sql)
,@(*ansi-translator* 'type->sql-converters)))
(clauses-order (append (*ansi-translator* 'clauses-order)
'(returning))))
(derive-object (*ansi-translator* self)
((escape-string string)
(escape-string (ssql-connection) string))
((boolean->sql boolean)
(if boolean "'t'" "'f'"))
((clauses-order) clauses-order)
((type->sql-converters) type->sql-converters)
((array (elements ...))
(sprintf "ARRAY[~A]"
(string-intersperse
(map (lambda (el)
(self 'ssql->sql el))
elements)
", "))))))
(define-operators *postgresql-translator*
(limit prefix)
(offset prefix)
(returning prefix "RETURNING" ", ")
(random function)
(@> infix)
(<@ infix))
(register-sql-engine! connection? *postgresql-translator*)
)