Skip to content

Instantly share code, notes, and snippets.

@fairjm
Created May 29, 2018 13:28
Show Gist options
  • Save fairjm/8ed8ef8896af70906f7d332f0c5eb421 to your computer and use it in GitHub Desktop.
Save fairjm/8ed8ef8896af70906f7d332f0c5eb421 to your computer and use it in GitHub Desktop.
create sql to java fields
import re
code = """
`name` varchar(10) DEFAULT NULL',
`age` int NOT NULL DEFAULT ''
"""
def parse_field_name(s):
return re.sub(r"_(.)", lambda x: x.group(1).upper(), s.replace("`",""))
def parse_field_type(t):
tl = t.lower()
if t.startswith("int"):
return "Long"
elif t.startswith("varchar"):
return "String"
elif t.startswith("timestamp"):
return "Timestamp"
return t
lines = [(parse_field_name(a.split()[0]), parse_field_type(a.split()[1])) for a in code.splitlines() if len(a.strip()) > 0]
for name,type in lines:
print("private {0} {1};".format(type, name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment