Hi,

I'm using underscored_separator_convention in a database, but
camelCase in python code.

I created small wrapper across a table column so I don't need to
define columns using a key property:

from sqlalchemy import Column as SqlColumn

def underscored(s):
  result = u""
  for i in xrange(0, len(s)):
    c = s[i]
    if (c.isupper()):
      if i > 0: result += u"_"
      result += c.lower()
    elif c.isdigit():
      if len(result) and result[-1].isdigit():
        result += c
      else:
        result += u"_" + c
    else:
      result += c

  return result

def Column(*args, **kw):
  k = args[0]
  m = list(args)
  m[0] = underscored(k)
  return SqlColumn(key=k, *m, **kw)

Usage:
  Column("productId", BigInteger, Sequence("ux_address_id_seq"),
primary_key=True),
This will create a table column "product_id", but I access it as
productId in python and sqlalchemy expression code.

My question: Is this code good or there is a better way directly built
into the sqlalchemy?

Thanks!
Petr

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to