[DB-SIG] need some database API design advice

Chris Clark Chris.Clark at actian.com
Wed Apr 11 21:48:22 CEST 2012


On Wednesday 2012-04-11 12:44 (-0700), Peter Eisentraut 
<peter_e at gmx.net> wrote:
> ....
> So, in terms of code, which one of these is "better"?
>
> 1a.
>
> rv = plpy.execute("some SQL command")
> try:
>      output(rv.colnames())
> except SomeException:
>      output("it's a utility command")
>
> 1b.
>
> rv = plpy.execute("some SQL command")
> if rv.has_rows():  # some currently nonexisting function to be added
>      output(rv.colnames())
> else:
>      output("it's a utility command")
>
> 2.
>
> rv = plpy.execute("some SQL command")
> if rv.colnames() is not None:
>      output(rv.colnames())
> else:
>      output("it's a utility command")

My 2 cents, I don't like any of them :-p

I prefer the last one modified slightly:

    rv = plpy.execute("some SQL command")
    if rv.colnames():
         output(rv.colnames())
    else:
         output("it's a utility command")

I.e. loose the None check. I'm not sure I like making an explicit 
function call for the colnames. I.e. I think sticking with the pep249 
description attribute is a better solution, the API already exist so 
clone that (when possible) in your new api.

....Of course a lot of this is is down to style preferences.

Chris



More information about the DB-SIG mailing list