fukamachi / integral

[OBSOLETE] Use Mito instead.
https://github.com/fukamachi/mito
BSD 3-Clause "New" or "Revised" License
54 stars 3 forks source link

Issue/6 handle read replica #9

Closed rudolph-miller closed 9 years ago

rudolph-miller commented 9 years ago

How about this?

(defvar *read-db* (make-connection :mysql :database-name "sample" :username "root" :host "read-replica-host"))
(defvar *master-db* (make-connection :mysql :database-name "sample" :username "root" :host "master-host"))

(setf *get-connection-fn*
      (lambda (&key query)
        (if (and query
                   (>= (length query) 6)
                   (string-equal query "SELECT" :end1 6))
            (connection-established-handle *read-db*)
            (Connection-established-handle *master-db*))))
rudolph-miller commented 9 years ago

It's just the idea.