Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the best practices for functional programming and database interaction?

I know that in pure object-oriented languages like Java it usually makes sense to use ORMs like Hibernate. But what would I do when writing a CRUD-type functionality in Clojure or Common LISP?

Passing around SQL as the first-order functions? But isn't having SQL in HTML-generating code very ugly?

Thanks,

Olek

like image 457
mannicken Avatar asked Feb 19 '09 07:02

mannicken


2 Answers

Common Lisp is not a self-consciously FP language. Clojure can just use Hibernate.

For Common Lisp: databases. Here's a persistent object one. And here is the first part of a tutorial that uses it with Hunchentoot, a CL webserver and dynamic webpage toolkit. SQL in CL can look like this (which looks longer than it really is, because the SQL is horizontally formatted and the CL isn't). And if you like, this guy is working on a web framework (using CLSQL and Elephant, already linked-to) that aims at tersity, with an eye on the arc challenge.

EDIT: a recent answer expands on this.

like image 101
ayrnieu Avatar answered Nov 19 '22 00:11

ayrnieu


Ur/Web may be interesting, although it's not lisp based: http://plv.csail.mit.edu/ur/

As quoted from their site:

Ur/Web supports construction of dynamic web applications backed by SQL databases. The signature of the standard library is such that well-typed Ur/Web programs "don't go wrong" in a very broad sense. Not only do they not crash during particular page generations, but they also may not:

  • Suffer from any kinds of code-injection attacks
  • Return invalid HTML
  • Contain dead intra-application links
  • Have mismatches between HTML forms and the fields expected by their handlers
  • Include client-side code that makes incorrect assumptions about the "AJAX"-style services that the remote web server provides
  • Attempt invalid SQL queries
  • Use improper marshaling or unmarshaling in communication with SQL databases or between browsers and web servers
like image 31
Attila Lendvai Avatar answered Nov 18 '22 22:11

Attila Lendvai