Skip to content

Instantly share code, notes, and snippets.

@tg123
Created April 25, 2014 07:27
Show Gist options
  • Save tg123/11280667 to your computer and use it in GitHub Desktop.
Save tg123/11280667 to your computer and use it in GitHub Desktop.
mysql create table to java pojo field
#!/usr/bin/env python
import sys
import re
# http://stackoverflow.com/questions/4303492/how-can-i-simplify-this-conversion-from-underscore-to-camelcase-in-python
def underscore_to_camelcase(value):
def camelcase():
yield str.lower
while True:
yield str.capitalize
c = camelcase()
return "".join(c.next()(x) if x else '_' for x in value.split("_"))
M = {
'int': 'long',
'varchar' : 'String',
'datetime' : 'Date',
}
ACC = 'private'
for f, t in re.findall('`(.*?)` (.*?)\(?\d*\)? ', sys.stdin.read()):
f = underscore_to_camelcase(f)
print ACC, M[t], f + ';'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment