Last active
August 29, 2015 14:11
-
-
Save akovalenko/0721e6c5d0b660b893f8 to your computer and use it in GitHub Desktop.
Minimal parse / execute / row-reader demo for cl-postgres-async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(in-package :cl-postgres-async) | |
;;(defparameter *test-connection* '("test" "test" "" "localhost")) | |
(defvar *test-connection* '("test" "test" "" "localhost")) | |
(defun prompt-connection (&optional (list *test-connection*)) | |
(flet ((ask (name pos) | |
(format *query-io* "~a (enter to keep '~a'): " name (nth pos list)) | |
(finish-output *query-io*) | |
(let ((answer (read-line *query-io*))) | |
(unless (string= answer "") (setf (nth pos list) answer))))) | |
(format *query-io* "~%To run this test, you must configure a database connection.~%") | |
(ask "Database name" 0) | |
(ask "User" 1) | |
(ask "Password" 2) | |
(ask "Hostname" 3))) | |
(defun min-async-test (&optional (sql "SELECT 1 AS RESULT") | |
(parameters nil)) | |
(as:with-event-loop () | |
(bb:finally | |
(bb:catcher | |
(bb:alet* | |
((conn (apply #'async-open-database *test-connection*)) | |
(nil (async-send-parse conn "s1" sql)) | |
(aff (async-send-execute | |
conn "s1" parameters | |
(row-handler-by-reader #'pprint | |
#'vector-row-reader))) | |
(nil (format t "~&Rows affected: ~A~&" aff)))) | |
(condition (c) (format t "Error: ~&~a~&" c))) | |
(as:exit-event-loop)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment