Posts tagged racket

exploring typecheking sql query in typed/racket

This post will describe a POC on how to typecheck sql query in typed/racket.


The goal is to make this typecheck:

(: some-query : (Listof (Vector String String)))
(define some-query
  (query
   movies
   #:from     ([actor a] [movie m])
   #:where    (= a.name "Jhon Wayne")
   #:select   (a.name m.name)))

With the schema defined as:

(define-schema movies
  (actor    [id Integer]
            [name String])
  (movie    [id Integer]
            [name String]
            [director_id Integer])
  (director [id Integer]
            [name String]))

Mapping data from sql result to struct

This post describe the implementation of a descriptive macro to fill structures from sql result.


The goal

At end of this post we will archive this:

;; assume the table actor exist and have at least id, name, age

(struct actor ([id #:auto] [name #:auto] [age #:auto]) 
  #:transparent #:mutable #:auto-value #f)

(select
    (["id" actor id]
     ["name" actor name]
     ["age" actor age])
  "SELECT a.* FROM actor AS a where a.id = $1"
  12)
;; => '(((actor 12 "some name" 80)))

basic fastcgi with racket

The objective is to implement the most basic working fastcgi protocol in pure racket.


How it works

The minimal fastcgi implementation will look like:

  1. wait on a tcp connection
  2. read all input data
  3. write output hello world like data
  4. close connection