Well I am using DB liberally so to be clear I am thinking there could be
several possible data store formats that I deal with out the gate.

1. sqlite
2. mysql
3. postgresql
4. mongo
5. text fixed width
6. cvs

I know it seems crazy but right now part of what I am dealing with is a
lot of formats I have to pull data together from and I kind of figure my
data module will allow me to save some conversion headaches.  Also I am
going to be playing with different DB's for benchmarking queries.  The
performance of a select query on an indexed field greatly impacts the
success and usefulness of what I am dealing with.

Basically I am trying to make the super swiss army of DB libraries
specifically for my data.  So I will know a lot about the nature of the
data but may not know a lot about the medium that data is coming from.

Probably an absurd plan, but for now I am still in the spit balling what
is possible.

Ken

On Fri, Nov 11, 2016 at 01:22:50PM -0500, David Storrs wrote:
> I think the first question is "what are you trying to achieve?"  What
> differences should the system demonstrate if it's hooked to MySQL vs
> PostgreSQL?
> 
> Personally, I just pass connection objects around.  As long as you stick
> with standard SQL this is all that's required to make your system work with
> any DB.  (Obviously, you need to avoid DB-specific extensions like
> Postgres's incredibly convenient 'INSERT ... RETURNING <columns>' clause.)
> 
> Here's an example:
> 
> (define (dbh)
>    (postgresql-connect #:user "postgres"
>                         #:database "dbname"
>                         #:password "pass"))
> 
> (define (placeholders-for lst [start-from 1])
>   (string-join
>       (for/list ((i (in-naturals start-from))
>                 (ignored lst))
>                 (~a "$" i))  ;; returns, e.g. "$1,$2,$3"
>   ","))
> 
> (define (add-user username [db (dbh)])
>     (query-exec
>       db
>       (format "INSERT INTO users (username) VALUES (~a)"
>           (placeholders-for (list username)))
>       username))
> 
> This is the bare bones for a completely engine-agnostic system.  You could
> add conditionals to dbh and placeholders-for so that they knew to generate
> a MySQL handle and the string "?,?,?" instead of a Pg handle and
> "$1,$2,$3"  Then you can use add-user without caring what engine you're
> attached to, just by passing in a connection object of the right type.
> 
> 
> 
> 
> 
> 
> 
> 
> On Fri, Nov 11, 2016 at 9:39 AM, Ken MacKenzie <[email protected]> wrote:
> 
> > I am trying to figure out the best way to do this and granted I am not
> > sure my architecture is the most sane or sensible way to handle it.  I am
> > trying to build my DB interface and I want to allow the system to deal with
> > numerous types of data stores.  So I have a config file that is read and
> > gets the information needed.  So to pseudo lay it out:
> >
> > (define (query-db where-clause))
> >
> > (define (db-type)
> >   (cond
> >     [(=? db-conf '(mysql)) (????)]) ;something to redefine how query-db
> > actually works.
> > )
> >
> > Maybe this is silly as in query-db I can just do a conditional for each
> > type.  But then I have to do a conditional for each DB action, connect,
> > drop, query, update, etc.  I was thinking loading the conditional and
> > redefining place holders would be a more elegant solution.  I don't know
> > just spit balling with a different design pattern here.
> >
> > Ken
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to [email protected].
> > For more options, visit https://groups.google.com/d/optout.
> >

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to